Exemplo n.º 1
0
    def update_stack(
            self, name_or_id,
            template_file=None, template_url=None,
            template_object=None, files=None,
            rollback=True, tags=None,
            wait=False, timeout=3600,
            environment_files=None,
            **parameters):
        """Update a stack.

        :param string name_or_id: Name or ID of the stack to update.
        :param string template_file: Path to the template.
        :param string template_url: URL of template.
        :param string template_object: URL to retrieve template object.
        :param dict files: dict of additional file content to include.
        :param boolean rollback: Enable rollback on update failure.
        :param boolean wait: Whether to wait for the delete to finish.
        :param int timeout: Stack update timeout in seconds.
        :param environment_files: Paths to environment files to apply.

        Other arguments will be passed as stack parameters which will take
        precedence over any parameters specified in the environments.

        Only one of template_file, template_url, template_object should be
        specified.

        :returns: a dict containing the stack description

        :raises: ``OpenStackCloudException`` if something goes wrong during
            the OpenStack API calls
        """
        params = dict(
            tags=tags,
            is_rollback_disabled=not rollback,
            timeout_mins=timeout // 60,
            parameters=parameters
        )
        params.update(self.orchestration.read_env_and_templates(
            template_file=template_file, template_url=template_url,
            template_object=template_object, files=files,
            environment_files=environment_files
        ))
        if wait:
            # find the last event to use as the marker
            events = event_utils.get_events(
                self, name_or_id, event_args={'sort_dir': 'desc', 'limit': 1})
            marker = events[0].id if events else None

        # Not to cause update of ID field pass stack as dict
        self.orchestration.update_stack(stack={'id': name_or_id}, **params)

        if wait:
            event_utils.poll_for_events(self,
                                        name_or_id,
                                        action='UPDATE',
                                        marker=marker)
        return self.get_stack(name_or_id)
Exemplo n.º 2
0
    def create_stack(self,
                     name,
                     tags=None,
                     template_file=None,
                     template_url=None,
                     template_object=None,
                     files=None,
                     rollback=True,
                     wait=False,
                     timeout=3600,
                     environment_files=None,
                     **parameters):
        """Create a stack.

        :param string name: Name of the stack.
        :param tags: List of tag(s) of the stack. (optional)
        :param string template_file: Path to the template.
        :param string template_url: URL of template.
        :param string template_object: URL to retrieve template object.
        :param dict files: dict of additional file content to include.
        :param boolean rollback: Enable rollback on create failure.
        :param boolean wait: Whether to wait for the delete to finish.
        :param int timeout: Stack create timeout in seconds.
        :param environment_files: Paths to environment files to apply.

        Other arguments will be passed as stack parameters which will take
        precedence over any parameters specified in the environments.

        Only one of template_file, template_url, template_object should be
        specified.

        :returns: a dict containing the stack description

        :raises: ``OpenStackCloudException`` if something goes wrong during
            the OpenStack API call
        """
        params = dict(tags=tags,
                      is_rollback_disabled=not rollback,
                      timeout_mins=timeout // 60,
                      parameters=parameters)
        params.update(
            self.orchestration.read_env_and_templates(
                template_file=template_file,
                template_url=template_url,
                template_object=template_object,
                files=files,
                environment_files=environment_files))
        self.orchestration.create_stack(name=name, **params)
        if wait:
            event_utils.poll_for_events(self, stack_name=name, action='CREATE')
        return self.get_stack(name)
Exemplo n.º 3
0
    def create_stack(
            self, name, tags=None,
            template_file=None, template_url=None,
            template_object=None, files=None,
            rollback=True,
            wait=False, timeout=3600,
            environment_files=None,
            **parameters):
        """Create a stack.

        :param string name: Name of the stack.
        :param tags: List of tag(s) of the stack. (optional)
        :param string template_file: Path to the template.
        :param string template_url: URL of template.
        :param string template_object: URL to retrieve template object.
        :param dict files: dict of additional file content to include.
        :param boolean rollback: Enable rollback on create failure.
        :param boolean wait: Whether to wait for the delete to finish.
        :param int timeout: Stack create timeout in seconds.
        :param environment_files: Paths to environment files to apply.

        Other arguments will be passed as stack parameters which will take
        precedence over any parameters specified in the environments.

        Only one of template_file, template_url, template_object should be
        specified.

        :returns: a dict containing the stack description

        :raises: ``OpenStackCloudException`` if something goes wrong during
            the OpenStack API call
        """
        params = dict(
            tags=tags,
            is_rollback_disabled=not rollback,
            timeout_mins=timeout // 60,
            parameters=parameters
        )
        params.update(self.orchestration.read_env_and_templates(
            template_file=template_file, template_url=template_url,
            template_object=template_object, files=files,
            environment_files=environment_files
        ))
        self.orchestration.create_stack(name=name, **params)
        if wait:
            event_utils.poll_for_events(self, stack_name=name,
                                        action='CREATE')
        return self.get_stack(name)
Exemplo n.º 4
0
    def delete_stack(self, name_or_id, wait=False):
        """Delete a stack

        :param string name_or_id: Stack name or ID.
        :param boolean wait: Whether to wait for the delete to finish

        :returns: True if delete succeeded, False if the stack was not found.

        :raises: ``OpenStackCloudException`` if something goes wrong during
            the OpenStack API call
        """
        stack = self.get_stack(name_or_id, resolve_outputs=False)
        if stack is None:
            self.log.debug("Stack %s not found for deleting", name_or_id)
            return False

        if wait:
            # find the last event to use as the marker
            events = event_utils.get_events(self,
                                            name_or_id,
                                            event_args={
                                                'sort_dir': 'desc',
                                                'limit': 1
                                            })
            marker = events[0].id if events else None

        self.orchestration.delete_stack(stack)

        if wait:
            try:
                event_utils.poll_for_events(self,
                                            stack_name=name_or_id,
                                            action='DELETE',
                                            marker=marker)
            except exc.OpenStackCloudHTTPError:
                pass
            stack = self.get_stack(name_or_id, resolve_outputs=False)
            if stack and stack['stack_status'] == 'DELETE_FAILED':
                raise exc.OpenStackCloudException(
                    "Failed to delete stack {id}: {reason}".format(
                        id=name_or_id, reason=stack['stack_status_reason']))

        return True
Exemplo n.º 5
0
    def delete_stack(self, name_or_id, wait=False):
        """Delete a stack

        :param string name_or_id: Stack name or ID.
        :param boolean wait: Whether to wait for the delete to finish

        :returns: True if delete succeeded, False if the stack was not found.

        :raises: ``OpenStackCloudException`` if something goes wrong during
            the OpenStack API call
        """
        stack = self.get_stack(name_or_id, resolve_outputs=False)
        if stack is None:
            self.log.debug("Stack %s not found for deleting", name_or_id)
            return False

        if wait:
            # find the last event to use as the marker
            events = event_utils.get_events(
                self, name_or_id, event_args={'sort_dir': 'desc', 'limit': 1})
            marker = events[0].id if events else None

        self.orchestration.delete_stack(stack)

        if wait:
            try:
                event_utils.poll_for_events(self,
                                            stack_name=name_or_id,
                                            action='DELETE',
                                            marker=marker)
            except exc.OpenStackCloudHTTPError:
                pass
            stack = self.get_stack(name_or_id, resolve_outputs=False)
            if stack and stack['stack_status'] == 'DELETE_FAILED':
                raise exc.OpenStackCloudException(
                    "Failed to delete stack {id}: {reason}".format(
                        id=name_or_id, reason=stack['stack_status_reason']))

        return True