def get_template_summary(req_params): stack_name = req_params.get('StackName') stack = None if stack_name: stack = find_stack(stack_name) if not stack: return stack_not_found_error(stack_name) cloudformation_listener.prepare_template_body(req_params) template = template_deployer.parse_template(req_params['TemplateBody']) req_params['StackName'] = 'tmp-stack' stack = Stack(req_params, template) result = stack.describe_details() id_summaries = {} for resource_id, resource in stack.template_resources.items(): res_type = resource['Type'] id_summaries[res_type] = id_summaries.get(res_type) or [] id_summaries[res_type].append(resource_id) result['ResourceTypes'] = list(id_summaries.keys()) result['ResourceIdentifierSummaries'] = [{ 'ResourceType': key, 'LogicalResourceIds': { 'member': values } } for key, values in id_summaries.items()] return result
def create_change_set(req_params): stack_name = req_params.get('StackName') cloudformation_listener.prepare_template_body(req_params) template = template_deployer.parse_template(req_params['TemplateBody']) template['StackName'] = stack_name template['ChangeSetName'] = req_params.get('ChangeSetName') stack = existing = find_stack(stack_name) if not existing: # automatically create (empty) stack if none exists yet state = RegionState.get() empty_stack_template = dict(template) empty_stack_template['Resources'] = {} stack = Stack(req_params, empty_stack_template) state.stacks[stack.stack_id] = stack change_set = StackChangeSet(req_params, template) stack.change_sets.append(change_set) return {'StackId': change_set.stack_id, 'Id': change_set.change_set_id}
def create_stack(req_params): state = RegionState.get() cloudformation_listener.prepare_template_body(req_params) template = template_deployer.parse_template(req_params['TemplateBody']) template['StackName'] = req_params.get('StackName') stack = Stack(req_params, template) state.stacks[stack.stack_id] = stack deployer = template_deployer.TemplateDeployer(stack) try: deployer.deploy_stack() except Exception as e: stack.set_stack_status('CREATE_FAILED') msg = 'Unable to create stack "%s": %s' % (stack.stack_name, e) LOG.debug('%s %s' % (msg, traceback.format_exc())) return error_response(msg, code=400, code_string='ValidationError') result = {'StackId': stack.stack_id} return result
def update_stack(req_params): stack_name = req_params.get('StackName') stack = find_stack(stack_name) if not stack: return error_response('Unable to update non-existing stack "%s"' % stack_name, code=404, code_string='ValidationError') cloudformation_listener.prepare_template_body(req_params) template = template_deployer.parse_template(req_params['TemplateBody']) new_stack = Stack(req_params, template) deployer = template_deployer.TemplateDeployer(stack) try: deployer.update_stack(new_stack) except Exception as e: stack.set_stack_status('UPDATE_FAILED') msg = 'Unable to update stack "%s": %s' % (stack_name, e) LOG.debug('%s %s' % (msg, traceback.format_exc())) return error_response(msg, code=400, code_string='ValidationError') result = {'StackId': stack.stack_id} return result