def _build_properties(csar, csar_parameters): result = { 'generatedHeatStackName': { 'Contract': YAQL('$.string()'), 'Usage': 'Out' }, 'hotEnvironment': { 'Contract': YAQL('$.string()'), 'Usage': 'In' } } if csar_parameters: params_dict = {} for key, value in (csar.get('parameters') or {}).items(): param_contract = \ CSARPackage._translate_param_to_contract(value) params_dict[key] = param_contract result['templateParameters'] = { 'Contract': params_dict, 'Default': {}, 'Usage': 'In' } else: result['templateParameters'] = { 'Contract': {}, 'Default': {}, 'Usage': 'In' } return result
def _translate_outputs(csar): result = {} for key in (csar.get('outputs') or {}).keys(): result[key] = { "Contract": YAQL("$.string()"), "Usage": "Out" } return result
def _generate_workflow(csar, files): hot_files_map = {} for f in files: file_path = "$resources.string('{0}{1}')".format( CSAR_FILES_DIR_NAME, f) hot_files_map['../{0}'.format(f)] = YAQL(file_path) hot_env = YAQL("$.hotEnvironment") copy_outputs = [] for key in (csar.get('outputs') or {}).keys(): copy_outputs.append({YAQL('$.' + key): YAQL('$outputs.' + key)}) deploy = [ { YAQL('$environment'): YAQL("$.find('io.murano.Environment').require()") }, { YAQL('$reporter'): YAQL("new('io.murano.system.StatusReporter', " "environment => $environment)") }, { 'If': YAQL('$.getAttr(generatedHeatStackName) = null'), 'Then': [ YAQL("$.setAttr(generatedHeatStackName, " "'{0}_{1}'.format(randomName(), id($environment)))") ] }, { YAQL('$stack'): YAQL("new('io.murano.system.HeatStack', $environment, " "name => $.getAttr(generatedHeatStackName))") }, YAQL("$reporter.report($this, " "'Application deployment has started')"), { YAQL('$resources'): YAQL("new('io.murano.system.Resources')") }, { YAQL('$template'): YAQL("$resources.yaml('template.yaml')") }, YAQL('$stack.setTemplate($template)'), { YAQL('$parameters'): YAQL("$.templateParameters") }, YAQL('$stack.setParameters($parameters)'), { YAQL('$files'): hot_files_map }, YAQL('$stack.setFiles($files)'), { YAQL('$hotEnv'): hot_env }, { 'If': YAQL("bool($hotEnv)"), 'Then': [{ YAQL('$envRelPath'): YAQL("'{0}' + $hotEnv".format(CSAR_ENV_DIR_NAME)) }, { YAQL('$hotEnvContent'): YAQL("$resources.string(" "$envRelPath)") }, YAQL('$stack.setHotEnvironment($hotEnvContent)')] }, YAQL("$reporter.report($this, 'Stack creation has started')"), { 'Try': [YAQL('$stack.push()')], 'Catch': [{ 'As': 'e', 'Do': [ YAQL("$reporter.report_error($this, $e.message)"), { 'Rethrow': None } ] }], 'Else': [ { YAQL('$outputs'): YAQL('$stack.output()') }, { 'Do': copy_outputs }, YAQL("$reporter.report($this, " "'Stack was successfully created')"), YAQL("$reporter.report($this, " "'Application deployment has finished')"), ] } ] destroy = [{ YAQL('$environment'): YAQL("$.find('io.murano.Environment').require()") }, { YAQL('$stack'): YAQL("new('io.murano.system.HeatStack', $environment, " "name => $.getAttr(generatedHeatStackName))") }, YAQL('$stack.delete()')] return { 'Workflow': { 'deploy': { 'Body': deploy }, 'destroy': { 'Body': destroy } } }
def _generate_workflow(csar, files): hot_files_map = {} for f in files: file_path = "$resources.string('{0}{1}')".format( CSAR_FILES_DIR_NAME, f) hot_files_map['../{0}'.format(f)] = YAQL(file_path) hot_env = YAQL("$.hotEnvironment") copy_outputs = [] for key in (csar.get('outputs') or {}).keys(): copy_outputs.append({YAQL('$.' + key): YAQL('$outputs.' + key)}) deploy = [ {YAQL('$environment'): YAQL( "$.find('io.murano.Environment').require()" )}, {YAQL('$reporter'): YAQL( "new('io.murano.system.StatusReporter', " "environment => $environment)")}, { 'If': YAQL('$.getAttr(generatedHeatStackName) = null'), 'Then': [ YAQL("$.setAttr(generatedHeatStackName, " "'{0}_{1}'.format(randomName(), id($environment)))") ] }, {YAQL('$stack'): YAQL( "new('io.murano.system.HeatStack', $environment, " "name => $.getAttr(generatedHeatStackName))")}, YAQL("$reporter.report($this, " "'Application deployment has started')"), {YAQL('$resources'): YAQL("new('io.murano.system.Resources')")}, {YAQL('$template'): YAQL("$resources.yaml('template.yaml')")}, YAQL('$stack.setTemplate($template)'), {YAQL('$parameters'): YAQL("$.templateParameters")}, YAQL('$stack.setParameters($parameters)'), {YAQL('$files'): hot_files_map}, YAQL('$stack.setFiles($files)'), {YAQL('$hotEnv'): hot_env}, { 'If': YAQL("bool($hotEnv)"), 'Then': [ {YAQL('$envRelPath'): YAQL("'{0}' + $hotEnv".format( CSAR_ENV_DIR_NAME))}, {YAQL('$hotEnvContent'): YAQL("$resources.string(" "$envRelPath)")}, YAQL('$stack.setHotEnvironment($hotEnvContent)') ] }, YAQL("$reporter.report($this, 'Stack creation has started')"), { 'Try': [YAQL('$stack.push()')], 'Catch': [ { 'As': 'e', 'Do': [ YAQL("$reporter.report_error($this, $e.message)"), {'Rethrow': None} ] } ], 'Else': [ {YAQL('$outputs'): YAQL('$stack.output()')}, {'Do': copy_outputs}, YAQL("$reporter.report($this, " "'Stack was successfully created')"), YAQL("$reporter.report($this, " "'Application deployment has finished')"), ] } ] destroy = [ {YAQL('$environment'): YAQL( "$.find('io.murano.Environment').require()" )}, {YAQL('$stack'): YAQL( "new('io.murano.system.HeatStack', $environment, " "name => $.getAttr(generatedHeatStackName))")}, YAQL('$stack.delete()') ] return { 'Workflow': { 'deploy': { 'Body': deploy }, 'destroy': { 'Body': destroy } } }