Commit 9d58ea60 authored by Antoine Catton's avatar Antoine Catton

Rename rootfs recipe to downloader recipe.

This recipe was written in order to create a service which download a
file after the buildout run.

rootfs recipe is replaced by downloader recipe which is more generic.
parent 4e2aee94
...@@ -56,6 +56,7 @@ setup(name=name, ...@@ -56,6 +56,7 @@ setup(name=name,
'dropbear = slapos.recipe.dropbear:Recipe', 'dropbear = slapos.recipe.dropbear:Recipe',
'dropbear.add_authorized_key = slapos.recipe.dropbear:AddAuthorizedKey', 'dropbear.add_authorized_key = slapos.recipe.dropbear:AddAuthorizedKey',
'dropbear.client = slapos.recipe.dropbear:Client', 'dropbear.client = slapos.recipe.dropbear:Client',
'downloader = slapos.recipe.downloader:Recipe',
'duplicity = slapos.recipe.duplicity:Recipe', 'duplicity = slapos.recipe.duplicity:Recipe',
'erp5scalabilitytestbed = slapos.recipe.erp5scalabilitytestbed:Recipe', 'erp5scalabilitytestbed = slapos.recipe.erp5scalabilitytestbed:Recipe',
'equeue = slapos.recipe.equeue:Recipe', 'equeue = slapos.recipe.equeue:Recipe',
...@@ -100,7 +101,6 @@ setup(name=name, ...@@ -100,7 +101,6 @@ setup(name=name,
'pwgen = slapos.recipe.pwgen:Recipe', 'pwgen = slapos.recipe.pwgen:Recipe',
'proactive = slapos.recipe.proactive:Recipe', 'proactive = slapos.recipe.proactive:Recipe',
'request = slapos.recipe.request:Recipe', 'request = slapos.recipe.request:Recipe',
'rootfs = slapos.recipe.rootfs:Recipe',
'seleniumrunner = slapos.recipe.seleniumrunner:Recipe', 'seleniumrunner = slapos.recipe.seleniumrunner:Recipe',
'sheepdogtestbed = slapos.recipe.sheepdogtestbed:SheepDogTestBed', 'sheepdogtestbed = slapos.recipe.sheepdogtestbed:SheepDogTestBed',
'shell = slapos.recipe.shell:Recipe', 'shell = slapos.recipe.shell:Recipe',
......
...@@ -26,16 +26,34 @@ ...@@ -26,16 +26,34 @@
############################################################################## ##############################################################################
import os import os
import subprocess import urllib
import hashlib
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
BUFFER_SIZE = 1024
def service(args): def service(args):
if not os.path.exists(args['confirm']): if not os.path.exists(args['confirm']):
subprocess.check_call([args['wget'], args['image'], urllib.urlretrieve(args['url'], args['output'])
'-O', args['output']])
if args['md5'] is not None:
# XXX: Find a better way to do a md5sum
md5sum = hashlib.md5()
with open(args['output'], 'r') as output:
file_buffer = output.read(BUFFER_SIZE)
while len(file_buffer) > 0:
md5sum.update(file_buffer)
file_buffer = output.read(BUFFER_SIZE)
if args['md5'] != md5sum.hexdigest():
return 127 # Not-null return code
# Just a touch on args['confirm'] file
open(args['confirm'], 'w').close() open(args['confirm'], 'w').close()
return 0
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
...@@ -43,15 +61,19 @@ class Recipe(GenericBaseRecipe): ...@@ -43,15 +61,19 @@ class Recipe(GenericBaseRecipe):
def install(self): def install(self):
path_list = [] path_list = []
md5sum = self.options.get('md5sum', '')
if len(md5sum) == 0:
md5sum = None
path_list.append( path_list.append(
self.createPythonScript( self.createPythonScript(
self.options['binary'], self.options['binary'],
'slapos.recipe.rootfs.service', 'slapos.recipe.downloader.service',
{ {
'wget': self.options['wget-binary'], 'url': self.options['url'],
'image': self.options['image-url'], 'md5': md5sum,
'output': self.options['downloaded-image'], 'output': self.options['downloaded-file'],
'confirm': self.options['downloaded-image-complete'] 'confirm': self.options['downloaded-file-complete']
} }
) )
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment