cook: add cook step, to run "sub-"recipes (#15797)

{
     "cook": {
       "filename": "secondary-recipe.json"
    }}
This commit is contained in:
Frédéric Péters 2017-06-28 22:34:12 +02:00
parent f9424f64d9
commit c25b14cf25
1 changed files with 14 additions and 5 deletions

View File

@ -56,12 +56,18 @@ class Command(BaseCommand):
)
def handle(self, recipe_json, *args, **kwargs):
recipe = json.load(open(recipe_json))
self.verbosity = kwargs.get('verbosity')
self.timeout = kwargs.get('timeout')
self.run_cook(recipe_json)
if self.verbosity:
print 'All steps executed successfully. Your environment should now be ready.'
def run_cook(self, filename):
recipe = json.load(open(filename))
variables = {}
if 'load-variables-from' in recipe:
variables.update(json.load(open(
os.path.join(os.path.dirname(recipe_json), recipe['load-variables-from']))))
os.path.join(os.path.dirname(filename), recipe['load-variables-from']))))
variables.update(recipe.get('variables', {}))
for step in recipe.get('steps', []):
action, action_args = step.items()[0]
@ -73,11 +79,9 @@ class Command(BaseCommand):
getattr(self, action.replace('-', '_'))(**action_args)
if self.must_notify:
notify_agents(None)
self.wait_operationals(timeout=kwargs['timeout'])
self.wait_operationals(timeout=self.timeout)
self.must_notify = False
notify_agents(None)
if self.verbosity:
print 'All steps executed successfully. Your environment should now be ready.'
def wait_operationals(self, timeout):
services = []
@ -270,3 +274,8 @@ class Command(BaseCommand):
attribute.order = AttributeDefinition.objects.all().aggregate(
Max('order')).get('order__max') + 1
attribute.save()
def cook(self, filename):
current_tenant = connection.get_tenant()
self.run_cook(filename)
connection.set_tenant(current_tenant)