Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def describe_policy(ctx, path):
    """
    Displays the stack policy used.

    """
    stack, _ = get_stack_or_env(ctx, path)
    response = stack.get_policy()
    write(response.get('StackPolicyBody', {}))
Exemplo n.º 4
0
def generate_command(ctx, path):
    """
    Prints the template.

    Prints the template used for stack in PATH.
    """
    stack, _ = get_stack_or_env(ctx, path)
    write(stack.template.body)
Exemplo n.º 5
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"])
Exemplo n.º 6
0
def list_change_sets(ctx, path):
    """
    List change sets for stack.

    """
    stack, _ = get_stack_or_env(ctx, path)
    response = stack.list_change_sets()
    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
    write(response, ctx.obj["output_format"])
Exemplo n.º 7
0
 def test_get_stack_or_env_with_env(self):
     ctx = MagicMock(
         obj={
             "sceptre_dir": sentinel.sceptre_dir,
             "user_variables": sentinel.user_variables
         })
     stack, env = get_stack_or_env(ctx, "environment/dir")
     self.mock_ConfigReader.assert_called_once_with(sentinel.sceptre_dir,
                                                    sentinel.user_variables)
     assert isinstance(env, Environment)
     assert stack is None
Exemplo n.º 8
0
 def test_get_stack_or_env_with_stack(self):
     ctx = MagicMock(
         obj={
             "sceptre_dir": sentinel.sceptre_dir,
             "user_variables": sentinel.user_variables
         })
     stack, env = get_stack_or_env(ctx, "stack.yaml")
     self.mock_ConfigReader.assert_called_once_with(sentinel.sceptre_dir,
                                                    sentinel.user_variables)
     assert isinstance(stack, Stack)
     assert env is None
Exemplo n.º 9
0
def validate_command(ctx, path):
    """
    Validates the template.

    Validates the template used for stack in PATH.
    """
    stack, _ = get_stack_or_env(ctx, path)
    response = stack.template.validate()
    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
        click.echo("Template is valid. Template details:\n")
    write(response, ctx.obj["output_format"])
Exemplo n.º 10
0
def list_resources(ctx, path):
    """
    List resources for stack or environment.

    """
    stack, env = get_stack_or_env(ctx, path)
    output_format = ctx.obj["output_format"]

    if stack:
        write(stack.describe_resources(), output_format)
    elif env:
        write(env.describe_resources(), output_format)
Exemplo n.º 11
0
def set_policy_command(ctx, path, policy_file, built_in):
    """
    Sets stack policy.

    Sets a specific stack policy for either a file or using a built-in policy.
    """
    stack, _ = get_stack_or_env(ctx, path)

    if built_in == 'deny-all':
        stack.lock()
    elif built_in == 'allow-all':
        stack.unlock()
    else:
        stack.set_policy(policy_file)
Exemplo n.º 12
0
def list_outputs(ctx, path, export):
    """
    List outputs for stack.

    """
    stack, _ = get_stack_or_env(ctx, path)
    response = stack.describe_outputs()

    if export == "envvar":
        write("\n".join([
            "export awsscripter_{0}={1}".format(output["OutputKey"],
                                                output["OutputValue"])
            for output in response
        ]))
    else:
        write(response, ctx.obj["output_format"])
Exemplo n.º 13
0
def status_command(ctx, path):
    """
    Print status of stack or environment.

    Prints the stack status or the status of the stacks within a environment
    for a given config PATH.
    """
    output_format = ctx.obj["output_format"]
    no_colour = ctx.obj["no_colour"]

    stack, env = get_stack_or_env(ctx, path)

    if stack:
        write(stack.get_status(), no_colour=no_colour)
    elif env:
        write(env.describe(), output_format=output_format, no_colour=no_colour)
Exemplo n.º 14
0
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_env(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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
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)