def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: env.stacks[basename].lock() except ClientError as e: context.error = e
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: context.response = env.stacks[basename].validate_template() except ClientError as e: context.error = e
def step_impl(context, aws_stack_name, stack_name, template_name): full_aws_stack_name = get_cloudformation_stack_name( context, aws_stack_name) env = Environment(context.sceptre_dir, os.path.dirname(stack_name)) stack_base_name = os.path.basename(stack_name) context.response = env.import_stack(full_aws_stack_name, stack_base_name, template_name)
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: context.output = env.stacks[basename].template.body except Exception as e: context.error = e
def import_env(ctx, environment): """ Import a Sceptre environment from a set of AWS CloudFormation stacks. """ env = Environment(sceptre_dir=ctx.obj["sceptre_dir"], environment_path=environment, options=ctx.obj["options"]) migrator.import_env(env)
def test_initialise_environment_with_non_leaf_directory( self, mock_validate_path, mock_is_leaf, mock_load_environments): mock_is_leaf.return_value = False mock_load_environments.return_value = sentinel.environments environment = Environment(sceptre_dir="sceptre_dir", environment_path="environment_path", options=sentinel.options) assert environment.environments == sentinel.environments
def setup_method(self, test_method, mock_check_env_path_valid, mock_is_leaf, mock_load_stacks): mock_is_leaf.return_value = True mock_load_stacks.return_value = sentinel.stacks self.environment = Environment(sceptre_dir="sceptre_dir", environment_path="environment_path", options=sentinel.options) # Run the rest of the tests against a leaf environment self.environment._is_leaf = True
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: env.stacks[basename].delete() except ClientError as e: if e.response['Error']['Code'] == 'ValidationError' \ and e.response['Error']['Message'].endswith("does not exist"): return else: raise e
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: env.stacks[basename].create() except ClientError as e: if e.response['Error']['Code'] == 'AlreadyExistsException' \ and e.response['Error']['Message'].endswith("already exists"): return else: raise e
def import_stack(ctx, environment, stack, aws_stack_name, template_path): """ Import a Sceptre stack from AWS Cloudformation. """ if not template_path: template_path = os.path.join("templates", aws_stack_name + ".yaml") migrator.import_stack( Environment(sceptre_dir=ctx.obj["sceptre_dir"], environment_path=environment, options=ctx.obj["options"]), aws_stack_name, stack, template_path)
def step_impl(context, change_set_name, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) stack = env.stacks[basename] allowed_errors = {'ValidationError', 'ChangeSetNotFound'} try: stack.execute_change_set(change_set_name) except ClientError as e: if e.response['Error']['Code'] in allowed_errors: context.error = e return else: raise e
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) try: env.stacks[basename].update() except ClientError as e: message = e.response['Error']['Message'] if e.response['Error']['Code'] == 'ValidationError' \ and (message.endswith("does not exist") or message.endswith("No updates are to be performed.")): return else: raise e
def generate_import_list(ctx, environment, list_path): """ Generate import a list of Sceptre stack from AWS Cloudformation. """ env = Environment(sceptre_dir=ctx.obj["sceptre_dir"], environment_path=environment, options=ctx.obj["options"]) if list_path: with open(list_path, 'w') as list_file_obj: migrator.generate_import_list(env, list_file_obj) else: migrator.generate_import_list(env)
def import_list(sceptre_dir, options, list_fobj): logger = logging.getLogger(__name__) logger.info("Importing from list") global import_stack_list import_stack_list = MigrationEnvironment.read_import_stack_list(list_fobj) for item in import_stack_list: import_stack( Environment(sceptre_dir=sceptre_dir, environment_path=item[MigrationEnvironment.PART_ENV], options=options), item[MigrationEnvironment.PART_AWS_STACK_NAME], item[MigrationEnvironment.PART_SCEPTRE_STACK_NAME], item[MigrationEnvironment.PART_TEMPLATE_PATH])
def run(self): argument = (self.argument if self.argument else '').lower() assert argument in self.ALLOWED_ARG_VALUES, \ "As the argument for !set_stack_termination_protection, please choose one of {0}".format(self.ALLOWED_ARG_VALUES) environment = Environment(self.environment_config.sceptre_dir, self.environment_config.environment_path) stack = environment.stacks[self.stack_config.name] cf_stack_name = stack.external_name enable = argument == 'enabled' self.logger.info( "Setting termination protection of stack '%s' to '%s'", cf_stack_name, argument) self.connection_manager.call('cloudformation', 'update_termination_protection', kwargs={ 'StackName': cf_stack_name, 'EnableTerminationProtection': enable })
def resolve(self): if self.argument: source_stack_path = self.dependency_stack_name source_env_path, source_stack_name = source_stack_path.rsplit( '/', 1) environment = Environment(self.environment_config.sceptre_dir, source_env_path) source_stack = environment.stacks[source_stack_name] region = source_stack.region source_stack_full_name = "-".join([ self.environment_config["project_code"], self.dependency_stack_name.replace("/", "-") ]) output_key = self.argument.split("::")[1] cloudformation = boto3.client('cloudformation', region_name=region) response = cloudformation.describe_stacks( StackName=source_stack_full_name) for output in response["Stacks"][0]["Outputs"]: if (output["OutputKey"] == output_key): return output["OutputValue"] raise Exception( "could not retrieve '{}' output value from '{}' stack").format( output_key, source_stack_path)
def step_impl(context, environment_name): env = Environment(context.sceptre_dir, environment_name) env.launch()
def setup_method(self, test_method): self.environment = Environment(path="path", options=sentinel.options) # Run the rest of the tests against a leaf environment self.environment._is_leaf = True
def test_initialise_environment_with_no_options(self): environment = Environment(path="path") assert environment.path == "path" assert environment._options == {} assert environment.stacks == [] assert environment.sub_environments == []
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) context.output = env.stacks[basename].describe_resources()
def step_impl(context, environment_name): env = Environment(context.sceptre_dir, environment_name) context.response = env.describe_resources()
def step_impl(context, environment_name): env = Environment(context.sceptre_dir, environment_name) env.delete()
def step_impl(context, stack_name): environment_name, basename = os.path.split(stack_name) env = Environment(context.sceptre_dir, environment_name) env.stacks[basename].launch()