def execute_command(ctx, path, change_set_name, yes): """ Executes a Change Set. \f :param path: Path to execute the command on. :type path: str :param change_set_name: Change Set to use. :type change_set_name: str :param yes: A flag to answer 'yes' too all CLI questions. :type yes: bool """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), config_directory=ctx.obj.get("config_directory"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options"), ignore_dependencies=ctx.obj.get("ignore_dependencies") ) plan = SceptrePlan(context) confirmation( plan.execute_change_set.__name__, yes, change_set=change_set_name, command_path=path ) plan.execute_change_set(change_set_name)
def create_command(ctx, path, change_set_name, yes): """ Creates a stack or a change set. Creates a stack for a given config PATH. Or if CHANGE_SET_NAME is specified creates a change set for stack in PATH. """ context = SceptreContext(command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options")) action = "create" stack, _ = get_stack_or_stack_group(context) if change_set_name: confirmation(action, yes, change_set=change_set_name, stack=path) command = 'create_change_set' plan = SceptrePlan(context, command, stack) plan.execute(change_set_name) else: confirmation(action, yes, stack=path) plan = SceptrePlan(context, action, stack) response = plan.execute() if response != StackStatus.COMPLETE: exit(1)
def launch_command(ctx, path, yes): """ Launch a stack or stack_group. Launch a stack or stack_group for a given config PATH. """ context = SceptreContext(command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options")) action = "launch" stack, stack_group = get_stack_or_stack_group(context) if stack: confirmation(action, yes, stack=path) plan = SceptrePlan(context, action, stack) response = plan.execute() if response != StackStatus.COMPLETE: exit(1) elif stack_group: confirmation(action, yes, stack_group=path) plan = SceptrePlan(context, action, stack_group) response = plan.execute() if not all(status == StackStatus.COMPLETE for status in response.values()): exit(1)
def create_command(ctx, path, change_set_name, yes): """ Creates a stack or a change set. Creates a stack for a given config PATH. Or if CHANGE_SET_NAME is specified creates a change set for stack in PATH. :param path: Path to a Stack or StackGroup :type path: str :param change_set_name: A name of the Change Set - optional :type change_set_name: str :param yes: A flag to assume yes to all questions. :type yes: bool """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options"), ignore_dependencies=ctx.obj.get("ignore_dependencies")) action = "create" plan = SceptrePlan(context) if change_set_name: confirmation(action, yes, change_set=change_set_name, command_path=path) plan.create_change_set(change_set_name) else: confirmation(action, yes, command_path=path) responses = plan.create() exit(stack_status_exit_code(responses.values()))
def execute_command(ctx, path, change_set_name, yes): """ Executes a change set. """ stack, _ = get_stack_or_env(ctx, path) confirmation("execute", yes, change_set=change_set_name, stack=path) stack.execute_change_set(change_set_name)
def update_command(ctx, path, change_set, verbose, yes): """ Updates a stack for a given config PATH. Or perform an update via change-set when the change-set flag is set. \f :param path: Path to execute the command on. :type path: str :param change_set: Whether a change set should be created. :type change_set: bool :param verbose: A flag to print a verbose output. :type verbose: bool :param yes: A flag to answer 'yes' to all CLI questions. :type yes: bool """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), config_directory=ctx.obj.get("config_directory"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options"), output_format=ctx.obj.get("output_format"), ignore_dependencies=ctx.obj.get("ignore_dependencies")) plan = SceptrePlan(context) if change_set: change_set_name = "-".join(["change-set", uuid1().hex]) plan.create_change_set(change_set_name) try: # Wait for change set to be created statuses = plan.wait_for_cs_completion(change_set_name) # Exit if change set fails to create for status in list(statuses.values()): if status != StackChangeSetStatus.READY: exit(1) # Describe changes descriptions = plan.describe_change_set(change_set_name) for description in list(descriptions.values()): if not verbose: description = simplify_change_set_description(description) write(description, context.output_format) # Execute change set if happy with changes if yes or click.confirm("Proceed with stack update?"): plan.execute_change_set(change_set_name) except Exception as e: raise e finally: # Clean up by deleting change set plan.delete_change_set(change_set_name) else: confirmation("update", yes, command_path=path) responses = plan.update() exit(stack_status_exit_code(responses.values()))
def execute_command(ctx, path, change_set_name, yes): """ Executes a change set. """ stack, _ = get_stack_or_stack_group(ctx, path) confirmation("execute", yes, change_set=change_set_name, stack=path) action = 'execute_change_set' plan = SceptrePlan(path, action, stack) plan.execute(change_set_name)
def update_command(ctx, path, change_set, verbose, yes): """ Update a stack. Updates a stack for a given config PATH. Or perform an update via change-set when the change-set flag is set. """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options"), output_format=ctx.obj.get("output_format") ) stack, _ = get_stack_or_stack_group(context) if change_set: action = 'create_change_set' change_set_name = "-".join(["change-set", uuid1().hex]) plan = SceptrePlan(context, action, stack) plan.execute(change_set_name) try: # Wait for change set to be created plan.action = 'wait_for_cs_completion' status = plan.execute(change_set_name) # Exit if change set fails to create if status != StackChangeSetStatus.READY: exit(1) # Describe changes plan.action = 'describe_change_set' description = plan.execute(change_set_name) if not verbose: description = simplify_change_set_description(description) write(description, context.output_format) # Execute change set if happy with changes if yes or click.confirm("Proceed with stack update?"): plan.action = 'execute_change_set' plan.execute(change_set_name) finally: # Clean up by deleting change set plan.action = 'delete_change_set' plan.execute(change_set_name) else: confirmation("update", yes, stack=path) action = 'update' plan = SceptrePlan(context, action, stack) response = plan.execute() if response != StackStatus.COMPLETE: exit(1)
def delete_command(ctx, path, change_set_name, yes): """ Deletes a stack for a given config PATH. Or if CHANGE_SET_NAME is specified deletes a change set for stack in PATH. \f :param path: Path to execute command on. :type path: str :param change_set_name: The name of the change set to use - optional :type change_set_name: str :param yes: Flag to answer yes to all CLI questions. :type yes: bool """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options"), ignore_dependencies=ctx.obj.get("ignore_dependencies"), full_scan=True, ) plan = SceptrePlan(context) plan.resolve(command='delete', reverse=True) if change_set_name: delete_msg = "The Change Set will be delete on the following stacks, if applicable:\n" else: delete_msg = "The following stacks, in the following order, will be deleted:\n" dependencies = '' for stacks in plan.launch_order: for stack in stacks: dependencies += "{}{}{}\n".format(Fore.YELLOW, stack.name, Style.RESET_ALL) print(delete_msg + "{}".format(dependencies)) confirmation(plan.delete.__name__, yes, change_set=change_set_name, command_path=path) if change_set_name: plan.delete_change_set(change_set_name) else: responses = plan.delete() exit(stack_status_exit_code(responses.values()))
def execute_command(ctx, path, change_set_name, yes): """ Executes a change set. """ context = SceptreContext( command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options") ) stack, _ = get_stack_or_stack_group(context) confirmation("execute", yes, change_set=change_set_name, stack=path) action = 'execute_change_set' plan = SceptrePlan(context, action, stack) plan.execute(change_set_name)
def create_command(ctx, path, change_set_name, yes): """ Creates a stack or a change set. Creates a stack for a given config PATH. Or if CHANGE_SET_NAME is specified creates a change set for stack in PATH. """ action = "create" stack, _ = get_stack_or_stack_group(ctx, path) if change_set_name: confirmation(action, yes, change_set=change_set_name, stack=path) stack.create_change_set(change_set_name) else: confirmation(action, yes, stack=path) response = stack.create() if response != StackStatus.COMPLETE: exit(1)
def launch_command(ctx, path, yes): """ Launch a Stack or StackGroup. Launch a Stack or StackGroup for a given config PATH. :param path: The path to launch. Can be a Stack or StackGroup. :type path: str :param yes: A flag to answer 'yes' to all CLI questions. :type yes: bool """ context = SceptreContext(command_path=path, project_path=ctx.obj.get("project_path"), user_variables=ctx.obj.get("user_variables"), options=ctx.obj.get("options")) plan = SceptrePlan(context) confirmation(plan.launch.__name__, yes, command_path=path) responses = plan.launch() exit(stack_status_exit_code(responses.values()))
def launch_command(ctx, path, yes): """ Launch a stack or environment. Launch a stack or environment for a given config PATH. """ action = "launch" stack, env = get_stack_or_env(ctx, path) if stack: confirmation(action, yes, stack=path) response = stack.launch() if response != StackStatus.COMPLETE: exit(1) elif env: confirmation(action, yes, environment=path) response = env.launch() if not all(status == StackStatus.COMPLETE for status in response.values()): exit(1)
def delete_command(ctx, path, change_set_name, yes): """ Deletes a stack or a change set. Deletes a stack for a given config PATH. Or if CHANGE_SET_NAME is specified deletes a change set for stack in PATH. """ action = "delete" stack, env = get_stack_or_env(ctx, path) if stack: if change_set_name: confirmation(action, yes, change_set=change_set_name, stack=path) stack.delete_change_set(change_set_name) else: confirmation(action, yes, stack=path) response = stack.delete() if response != StackStatus.COMPLETE: exit(1) elif env: confirmation(action, yes, environment=path) response = env.delete() if not all(status == StackStatus.COMPLETE for status in response.values()): exit(1)
def delete_command(ctx, path, change_set_name, yes): """ Deletes a stack or a change set. Deletes a stack for a given config PATH. Or if CHANGE_SET_NAME is specified deletes a change set for stack in PATH. """ action = "delete" stack, stack_group = get_stack_or_stack_group(ctx, path) if stack: if change_set_name: confirmation(action, yes, change_set=change_set_name, stack=path) command = 'delete_change_set' plan = SceptrePlan(path, command, stack) plan.execute(change_set_name) else: confirmation(action, yes, stack=path) plan = SceptrePlan(path, action, stack) response = plan.execute() if response != StackStatus.COMPLETE: exit(1) elif stack_group: confirmation(action, yes, stack_group=path) plan = SceptrePlan(path, action, stack_group) response = plan.execute() if not all(status == StackStatus.COMPLETE for status in response.values()): exit(1)
def launch_command(ctx, path, yes): """ Launch a stack or stack_group. Launch a stack or stack_group for a given config PATH. """ action = "launch" stack, stack_group = get_stack_or_stack_group(ctx, path) if stack: confirmation(action, yes, stack=path) response = stack.launch() if response != StackStatus.COMPLETE: exit(1) elif stack_group: confirmation(action, yes, stack_group=path) response = stack_group.launch() if not all( status == StackStatus.COMPLETE for status in response.values() ): exit(1)
def update_command(ctx, path, change_set, verbose, yes): """ Update a stack. Updates a stack for a given config PATH. Or perform an update via change-set when the change-set flag is set. """ stack, _ = get_stack_or_env(ctx, path) if change_set: change_set_name = "-".join(["change-set", uuid1().hex]) stack.create_change_set(change_set_name) try: # Wait for change set to be created status = stack.wait_for_cs_completion(change_set_name) # Exit if change set fails to create if status != StackChangeSetStatus.READY: exit(1) # Describe changes description = stack.describe_change_set(change_set_name) if not verbose: description = simplify_change_set_description(description) write(description, ctx.obj["output_format"]) # Execute change set if happy with changes if yes or click.confirm("Proceed with stack update?"): stack.execute_change_set(change_set_name) finally: # Clean up by deleting change set stack.delete_change_set(change_set_name) else: confirmation("update", yes, stack=path) response = stack.update() if response != StackStatus.COMPLETE: exit(1)
def create_command(ctx, path, change_set_name, yes): """ Creates a stack or a change set. Creates a stack for a given config PATH. Or if CHANGE_SET_NAME is specified creates a change set for stack in PATH. """ action = "create" # <<<<<<< HEAD # stack, _ = get_stack_or_env(ctx, path) # print(stack) # ======= # stack, _ = get_stack_or_stack_group(ctx, path) # >>>>>>> cfb45a0c7c9e4567f765d4ee4c7dbfe05ebfa0b9 stack, _ = get_stack_or_stack_group(ctx, path) if change_set_name: confirmation(action, yes, change_set=change_set_name, stack=path) stack.create_change_set(change_set_name) else: confirmation(action, yes, stack=path) response = stack.create() if response != StackStatus.COMPLETE: exit(1)