예제 #1
0
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)
예제 #2
0
def status_command(ctx, path):
    """
    Print status of stack or stack_group.

    Prints the stack status or the status of the stacks within a
    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"),
                no_colour=ctx.obj.get("no_colour"),
                output_format=ctx.obj.get("output_format")
            )

    stack, stack_group = get_stack_or_stack_group(context)

    if stack:
        command = 'get_status'
        plan = SceptrePlan(context, command, stack)
        write(plan.execute(), no_colour=context.no_colour)
    elif stack_group:
        command = 'describe'
        plan = SceptrePlan(context, command, stack_group)
        write(plan.execute(), output_format=context.output_format,
              no_colour=context.no_colour)
예제 #3
0
파일: delete.py 프로젝트: rgitzel/sceptre
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)
예제 #4
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.
    """
    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 = "delete"

    stack, stack_group = get_stack_or_stack_group(context)

    if stack:
        if change_set_name:
            confirmation(action, yes, change_set=change_set_name, stack=path)
            command = 'delete_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)
    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)
예제 #5
0
    def test_planner_executes_with_params(self):
        plan = SceptrePlan('test/path', 'test-command', self.stack_group)
        plan.execute = Mock(name='execute')
        plan.execute.return_value = sentinel.success

        result = plan.execute('test-attribute')
        plan.execute.assert_called_once_with('test-attribute')
        assert result == sentinel.success
예제 #6
0
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)
예제 #7
0
파일: list.py 프로젝트: rgitzel/sceptre
def list_resources(ctx, path):
    """
    List resources for stack or stack_group.

    """
    stack, stack_group = get_stack_or_stack_group(ctx, path)
    output_format = ctx.obj["output_format"]
    action = 'describe_resources'

    if stack:
        plan = SceptrePlan(path, action, stack)
        write(plan.execute(), output_format)
    elif stack_group:
        plan = SceptrePlan(path, action, stack_group)
        write(plan.execute(), output_format)
예제 #8
0
def estimate_cost_command(ctx, path):
    """
    Estimates the cost of the template.
    Prints a URI to STOUT that provides an estimated cost based on the
    resources in the stack. This command will also attempt to open a web
    browser with the returned URI.
    """
    action = 'estimate_cost'
    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)
    plan = SceptrePlan(context, action, stack.template)
    response = plan.execute()

    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
        click.echo("View the estimated cost at:")
        response = response["Url"]
        webbrowser.open(response, new=2)
    write(response + "\n", 'str')
예제 #9
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)
예제 #10
0
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)
예제 #11
0
파일: describe.py 프로젝트: rgitzel/sceptre
def describe_policy(ctx, path):
    """
    Displays the stack policy used.

    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'get_policy'
    plan = SceptrePlan(path, action, stack)
    response = plan.execute()
    write(response.get('StackPolicyBody', {}))
예제 #12
0
def generate_command(ctx, path):
    """
    Prints the template.

    Prints the template used for stack in PATH.
    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'generate'
    plan = SceptrePlan(path, action, stack.template)
    write(plan.execute())
예제 #13
0
def status_command(ctx, path):
    """
    Print status of stack or stack_group.

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

    stack, stack_group = get_stack_or_stack_group(ctx, path)

    if stack:
        command = 'get_status'
        plan = SceptrePlan(path, command, stack)
        write(plan.execute(), no_colour=no_colour)
    elif stack_group:
        command = 'describe'
        plan = SceptrePlan(path, command, stack_group)
        write(plan.execute(), output_format=output_format, no_colour=no_colour)
예제 #14
0
def list_resources(ctx, path):
    """
    List resources for stack or stack_group.

    """
    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, stack_group = get_stack_or_stack_group(context)
    action = 'describe_resources'

    if stack:
        plan = SceptrePlan(context, action, stack)
        write(plan.execute(), context.output_format)
    elif stack_group:
        plan = SceptrePlan(context, action, stack_group)
        write(plan.execute(), context.output_format)
예제 #15
0
파일: describe.py 프로젝트: rgitzel/sceptre
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"])
예제 #16
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_stack_group(ctx, path)
    if change_set_name:
        confirmation(action, yes, change_set=change_set_name, stack=path)
        command = 'create_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)
예제 #17
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.
    """
    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)

    if built_in == 'deny-all':
        action = 'lock'
        plan = SceptrePlan(context, action, stack)
        plan.execute()
    elif built_in == 'allow-all':
        action = 'unlock'
        plan = SceptrePlan(context, action, stack)
        plan.execute()
    else:
        action = 'set_policy'
        plan = SceptrePlan(context, action, stack)
        plan.execute(policy_file)
예제 #18
0
파일: list.py 프로젝트: rgitzel/sceptre
def list_change_sets(ctx, path):
    """
    List change sets for stack.

    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'list_change_sets'
    plan = SceptrePlan(path, action, stack)
    response = plan.execute()

    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
    write(response, ctx.obj["output_format"])
예제 #19
0
def validate_command(ctx, path):
    """
    Validates the template.

    Validates the template used for stack in PATH.
    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'validate'
    plan = SceptrePlan(path, action, stack.template)
    response = plan.execute()
    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
        click.echo("Template is valid. Template details:\n")
    write(response, ctx.obj["output_format"])
예제 #20
0
def describe_policy(ctx, path):
    """
    Displays the stack policy used.

    """
    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 = 'get_policy'
    plan = SceptrePlan(context, action, stack)
    response = plan.execute()
    write(response.get('StackPolicyBody', {}))
예제 #21
0
def generate_command(ctx, path):
    """
    Prints the template.

    Prints the template used 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")
            )

    stack, _ = get_stack_or_stack_group(context)
    action = 'generate'
    plan = SceptrePlan(context, action, stack.template)
    write(plan.execute())
예제 #22
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)
예제 #23
0
def estimate_cost_command(ctx, path):
    """
    Estimates the cost of the template.
    Prints a URI to STOUT that provides an estimated cost based on the
    resources in the stack. This command will also attempt to open a web
    browser with the returned URI.
    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'estimate_cost'
    plan = SceptrePlan(path, action, stack.template)
    response = plan.execute()

    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
        click.echo("View the estimated cost at:")
        response = response["Url"]
        webbrowser.open(response, new=2)
    write(response + "\n", 'str')
예제 #24
0
def list_change_sets(ctx, path):
    """
    List change sets for stack.

    """
    context = SceptreContext(command_path=path,
                             project_path=ctx.obj.get("project_path"),
                             user_variables=ctx.obj.get("user_variables"),
                             output_format=ctx.obj.get("output_format"),
                             options=ctx.obj.get("options"))

    stack, _ = get_stack_or_stack_group(context)
    action = 'list_change_sets'
    plan = SceptrePlan(context, action, stack)
    response = plan.execute()

    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
    write(response, context.output_format)
예제 #25
0
파일: list.py 프로젝트: rgitzel/sceptre
def list_outputs(ctx, path, export):
    """
    List outputs for stack.

    """
    stack, _ = get_stack_or_stack_group(ctx, path)
    action = 'describe_outputs'
    plan = SceptrePlan(path, action, stack)
    response = plan.execute()

    if export == "envvar":
        write("\n".join(
            [
                "export SCEPTRE_{0}={1}".format(
                    output["OutputKey"], output["OutputValue"]
                )
                for output in response
            ]
        ))
    else:
        write(response, ctx.obj["output_format"])
예제 #26
0
def list_outputs(ctx, path, export):
    """
    List outputs for stack.

    """
    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_outputs'
    plan = SceptrePlan(context, action, stack)
    response = plan.execute()

    if export == "envvar":
        write("\n".join([
            "export SCEPTRE_{0}={1}".format(output["OutputKey"],
                                            output["OutputValue"])
            for output in response
        ]))
    else:
        write(response, context.output_format)
예제 #27
0
def validate_command(ctx, path):
    """
    Validates the template.

    Validates the template used 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"),
                output_format=ctx.obj.get("output_format")
            )

    stack, _ = get_stack_or_stack_group(context)
    action = 'validate'
    plan = SceptrePlan(context, action, stack.template)
    response = plan.execute()

    if response['ResponseMetadata']['HTTPStatusCode'] == 200:
        del response['ResponseMetadata']
        click.echo("Template is valid. Template details:\n")
    write(response, context.output_format)
예제 #28
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_stack_group(ctx, path)

    if built_in == 'deny-all':
        action = 'lock'
        plan = SceptrePlan(path, action, stack)
        plan.execute()
    elif built_in == 'allow-all':
        action = 'unlock'
        plan = SceptrePlan(path, action, stack)
        plan.execute()
    else:
        action = 'set_policy'
        plan = SceptrePlan(path, action, stack)
        plan.execute(policy_file)
예제 #29
0
 def test_command_not_found_error_raised(self):
     with pytest.raises(AttributeError):
         plan = SceptrePlan('test/path', 'test-command', self.stack)
         plan.execute()
예제 #30
0
 def test_command_not_callable_error_raised(self):
     with pytest.raises(TypeError):
         plan = SceptrePlan('test/path', 'name', self.stack)
         plan.execute()