Beispiel #1
0
    def update_stack(self, stack):
        self.logger.debug("Updating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:

            try:
                self._update_stack(stack)
            except ClientError as e:

                if self.is_boto_no_update_required_exception(e):
                    self.logger.info("Stack {0} does not need an update".format(stack.name))
                    return
                else:
                    self.logger.info(
                        "Updating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                                stack.template.name,
                                                                                get_pretty_parameters_string(
                                                                                    stack)))
                    raise

            self.logger.info(
                "Updating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                        stack.template.name,
                                                                        get_pretty_parameters_string(stack)))

            self.wait_for_stack_action_to_complete(stack.name, "update", stack.timeout)
            self.logger.info("Update completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException("Could not update {0}: {1}".format(stack.name, e))
Beispiel #2
0
    def update_stack(self, stack):
        try:

            try:
                self._update_stack(stack)
            except BotoServerError as e:

                if self.is_boto_no_update_required_exception(e):
                    self.logger.info(
                        "Stack {0} does not need an update".format(stack.name))
                    return
                else:
                    self.logger.info(
                        "Updating stack {0} ({1}) with parameters:\n{2}".
                        format(stack.name, stack.template.name,
                               get_pretty_parameters_string(stack.parameters)))
                    raise

            self.logger.info(
                "Updating stack {0} ({1}) with parameters:\n{2}".format(
                    stack.name, stack.template.name,
                    get_pretty_parameters_string(stack.parameters)))

            self.wait_for_stack_action_to_complete(stack.name, "update",
                                                   stack.timeout)
            self.logger.info("Update completed for {0}".format(stack.name))

        except BotoServerError as e:
            raise CfnStackActionFailedException(
                "Could not update {0}: {1}".format(stack.name, e.message))
Beispiel #3
0
    def update_stack(self, stack):
        try:

            try:
                self._update_stack(stack)
            except BotoServerError as e:

                if self.is_boto_no_update_required_exception(e):
                    self.logger.info("Stack {0} does not need an update".format(stack.name))
                    return
                else:
                    self.logger.info(
                        "Updating stack {0} ({1}) with parameters:\n{2}".format(
                            stack.name, stack.template.name, get_pretty_parameters_string(stack)
                        )
                    )
                    raise

            self.logger.info(
                "Updating stack {0} ({1}) with parameters:\n{2}".format(
                    stack.name, stack.template.name, get_pretty_parameters_string(stack)
                )
            )

            self.wait_for_stack_action_to_complete(stack.name, "update", stack.timeout)
            self.logger.info("Update completed for {0}".format(stack.name))

        except BotoServerError as e:
            raise CfnStackActionFailedException("Could not update {0}: {1}".format(stack.name, e.message))
Beispiel #4
0
    def create_stack(self, stack):
        self.logger.debug("Creating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            stack_parameters_string = get_pretty_parameters_string(stack)

            self.logger.info(
                "Creating stack {0} ({1}) with parameters:\n{2}".format(
                    stack.name, stack.template.name, stack_parameters_string))
            self._create_stack(stack)

            self.wait_for_stack_action_to_complete(stack.name, "create",
                                                   stack.timeout)

            stack_outputs = get_pretty_stack_outputs(
                self.get_stack_outputs(stack))
            if stack_outputs:
                self.logger.info(
                    "Create completed for {0} with outputs: \n{1}".format(
                        stack.name, stack_outputs))
            else:
                self.logger.info("Create completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException(
                "Could not create {0}: {1}".format(stack.name, e))
Beispiel #5
0
    def create_stack(self, stack):
        assert isinstance(stack, CloudFormationStack)
        try:
            self.logger.info(
                "Creating stack {0} from template {1} with parameters:\n{2}".format(stack.name, stack.template.name,
                                                                                    get_pretty_parameters_string(
                                                                                        stack)))
            self._create_stack(stack)

            self.wait_for_stack_action_to_complete(stack.name, "create", stack.timeout)
            self.logger.info("Create completed for {0}".format(stack.name))
        except BotoServerError as e:
            raise CfnStackActionFailedException("Could not create {0}: {1}".format(stack.name, e.message))
Beispiel #6
0
    def test_get_pretty_parameters_string(self):
        template_body = {
            'Parameters': {
                'myParameter1': {
                    'Type': 'String',
                    'NoEcho': True
                },
                'myParameter2': {
                    'Type': 'String'
                },
                'myParameter3': {
                    'Type': 'Number',
                    'NoEcho': 'true'
                },
                'myParameter4': {
                    'Type': 'Number',
                    'NoEcho': 'false'
                },
                'myParameter5': {
                    'Type': 'Number',
                    'NoEcho': False
                }
            }
        }

        parameters = {
            'myParameter1': 'super-secret',
            'myParameter2': 'not-that-secret',
            'myParameter3': 'also-super-secret',
            'myParameter4': 'could-be-public',
            'myParameter5': 'also-ok'
        }

        template = CloudFormationTemplate(template_body,
                                          'just-another-template')
        stack = CloudFormationStack(template, parameters, 'just-another-stack',
                                    'eu-west-1')

        expected_string = """+--------------+-----------------+
|  Parameter   |      Value      |
+--------------+-----------------+
| myParameter1 |       ***       |
| myParameter2 | not-that-secret |
| myParameter3 |       ***       |
| myParameter4 | could-be-public |
| myParameter5 |     also-ok     |
+--------------+-----------------+"""

        self.assertEqual(expected_string,
                         util.get_pretty_parameters_string(stack))
Beispiel #7
0
    def create_stack(self, stack):
        assert isinstance(stack, CloudFormationStack)
        try:
            self.logger.info(
                "Creating stack {0} from template {1} with parameters:\n{2}".
                format(stack.name, stack.template.name,
                       get_pretty_parameters_string(stack.parameters)))
            self._create_stack(stack)

            self.wait_for_stack_action_to_complete(stack.name, "create",
                                                   stack.timeout)
            self.logger.info("Create completed for {0}".format(stack.name))
        except BotoServerError as e:
            raise CfnStackActionFailedException(
                "Could not create {0}: {1}".format(stack.name, e.message))
Beispiel #8
0
    def create_stack(self, stack):
        self.logger.debug("Creating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            self.logger.info(
                "Creating stack {0} ({1}) with parameters:\n{2}".format(stack.name,
                                                                        stack.template.name,
                                                                        get_pretty_parameters_string(
                                                                            stack)))
            self._create_stack(stack)

            self.wait_for_stack_action_to_complete(stack.name, "create", stack.timeout)
            self.logger.info("Create completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException("Could not create {0}: {1}".format(stack.name, e))
Beispiel #9
0
    def test_get_pretty_parameters_string(self):
        template_body = {
            'Parameters': {
                'myParameter1': {
                    'Type': 'String',
                    'NoEcho': True
                },
                'myParameter2': {
                    'Type': 'String'
                },
                'myParameter3': {
                    'Type': 'Number',
                    'NoEcho': 'true'
                },
                'myParameter4': {
                    'Type': 'Number',
                    'NoEcho': 'false'
                },
                'myParameter5': {
                    'Type': 'Number',
                    'NoEcho': False
                }
            }
        }

        parameters = {
            'myParameter1': 'super-secret',
            'myParameter2': 'not-that-secret',
            'myParameter3': 'also-super-secret',
            'myParameter4': 'could-be-public',
            'myParameter5': 'also-ok'
        }

        template = CloudFormationTemplate(template_body, 'just-another-template')
        stack = CloudFormationStack(template, parameters, 'just-another-stack', 'eu-west-1')

        expected_string = """+--------------+-----------------+
|  Parameter   |      Value      |
+--------------+-----------------+
| myParameter1 |       ***       |
| myParameter2 | not-that-secret |
| myParameter3 |       ***       |
| myParameter4 | could-be-public |
| myParameter5 |     also-ok     |
+--------------+-----------------+"""

        self.assertEqual(expected_string, util.get_pretty_parameters_string(stack))
Beispiel #10
0
    def create_stack(self, stack):
        assert isinstance(stack, CloudFormationStack)
        try:
            self.logger.info(
                "Creating stack {0} from template {1} with parameters:\n{2}".format(stack.name, stack.template.name,
                                                                                    get_pretty_parameters_string(
                                                                                        stack.parameters)))
            self.conn.create_stack(stack.name,
                                   template_body=stack.template.get_template_json(),
                                   parameters=stack.get_parameters_list(),
                                   capabilities=['CAPABILITY_IAM'])

            self.wait_for_stack_action_to_complete(stack.name, "create", stack.timeout)
            self.logger.info("Create completed for {0}".format(stack.name))
        except BotoServerError as e:
            message = get_message_from_boto_server_error(e)
            raise CfnStackActionFailedException(
                "Could not create stack {0}. Cfn API responded with: {1}".format(stack.name, message))
Beispiel #11
0
    def update_stack(self, stack):
        self.logger.debug("Updating stack: {0}".format(stack))
        assert isinstance(stack, CloudFormationStack)

        try:
            stack_parameters_string = get_pretty_parameters_string(stack)

            try:
                self._update_stack(stack)
            except ClientError as e:

                if self.is_boto_no_update_required_exception(e):
                    self.logger.info(
                        "Stack {0} does not need an update".format(stack.name))
                    return
                else:
                    self.logger.info(
                        "Updating stack {0} ({1}) with parameters:\n{2}".
                        format(stack.name, stack.template.name,
                               stack_parameters_string))
                    raise

            self.logger.info(
                "Updating stack {0} ({1}) with parameters:\n{2}".format(
                    stack.name, stack.template.name, stack_parameters_string))

            self.wait_for_stack_action_to_complete(stack.name, "update",
                                                   stack.timeout)

            stack_outputs = get_pretty_stack_outputs(
                self.get_stack_outputs(stack))
            if stack_outputs:
                self.logger.info(
                    "Update completed for {0} with outputs: \n{1}".format(
                        stack.name, stack_outputs))
            else:
                self.logger.info("Update completed for {0}".format(stack.name))
        except (BotoCoreError, ClientError, CfnSphereBotoError) as e:
            raise CfnStackActionFailedException(
                "Could not update {0}: {1}".format(stack.name, e))
Beispiel #12
0
    def update_stack(self, stack):
        assert isinstance(stack, CloudFormationStack)
        try:
            self.logger.info(
                "Updating stack {0} from template {1} with parameters:\n{2}".format(stack.name, stack.template.name,
                                                                                    get_pretty_parameters_string(
                                                                                        stack.parameters)))

            self.conn.update_stack(stack.name,
                                   template_body=stack.template.get_template_json(),
                                   parameters=stack.get_parameters_list(),
                                   capabilities=['CAPABILITY_IAM'])

            self.wait_for_stack_action_to_complete(stack.name, "update", stack.timeout)
            self.logger.info("Update completed for {0}".format(stack.name))
        except BotoServerError as e:
            message = get_message_from_boto_server_error(e)

            if message == "No updates are to be performed.":
                self.logger.info("Nothing to do: {0}.".format(message))
            else:
                raise CfnStackActionFailedException("{0}.".format(message))