Esempio n. 1
0
def describe_change_set(ctx, path, change_set_name, verbose):
    """
    Describes the change set.

    :param path: Path to execute the command on.
    :type path: str
    :param change_set_name: Name of the Change Set to use.
    :type change_set_name: str
    :param verbose: A flag to display verbose output.
    :type verbose: 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"),
        output_format=ctx.obj.get("output_format"),
        no_colour=ctx.obj.get("no_colour"),
        ignore_dependencies=ctx.obj.get("ignore_dependencies")
    )

    plan = SceptrePlan(context)

    responses = plan.describe_change_set(change_set_name)
    for response in responses.values():
        description = response
        if not verbose:
            description = simplify_change_set_description(description)
        write(description, context.output_format, context.no_colour)
Esempio n. 2
0
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()))
Esempio n. 3
0
def describe_change_set(ctx, path, change_set_name, verbose):
    """
    Describes the change set.

    """
    stack, _ = get_stack_or_env(ctx, path)
    description = stack.describe_change_set(change_set_name)
    if not verbose:
        description = simplify_change_set_description(description)
    write(description, ctx.obj["output_format"])
Esempio n. 4
0
def describe_change_set(ctx, path, change_set_name, verbose):
    """
    Describes the change set.

    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'describe_change_set'
    plan = SceptrePlan(path, action, stack)
    description = plan.execute(change_set_name)
    if not verbose:
        description = simplify_change_set_description(description)
    write(description, ctx.obj["output_format"])
Esempio n. 5
0
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)
Esempio n. 6
0
def describe_change_set(ctx, path, change_set_name, verbose):
    """
    Describes the 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)
    action = 'describe_change_set'
    plan = SceptrePlan(context, action, stack)
    description = plan.execute(change_set_name)
    if not verbose:
        description = simplify_change_set_description(description)
    write(description, context.output_format)
Esempio n. 7
0
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)