Exemple #1
0
    def action(self, req, identity, body={}):
        """
        Performs a specified action on a stack, the body is expecting to
        contain exactly one item whose key specifies the action
        """

        if len(body) < 1:
            raise exc.HTTPBadRequest(_("No action specified"))

        if len(body) > 1:
            raise exc.HTTPBadRequest(_("Multiple actions specified"))

        ac = body.keys()[0]
        if ac not in self.ACTIONS:
            raise exc.HTTPBadRequest(_("Invalid action %s specified") % ac)

        if ac == self.SUSPEND:
            try:
                res = self.engine.stack_suspend(req.context, identity)
            except rpc_common.RemoteError as ex:
                return util.remote_error(ex)
        elif ac == self.RESUME:
            try:
                res = self.engine.stack_resume(req.context, identity)
            except rpc_common.RemoteError as ex:
                return util.remote_error(ex)
        else:
            raise exc.HTTPInternalServerError(_("Unexpected action %s") % ac)
Exemple #2
0
    def detail(self, req):
        """
        Lists detailed information for all stacks
        """
        try:
            stacks = self.engine.list_stacks(req.context)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {"stacks": [format_stack(req, s) for s in stacks]}
Exemple #3
0
    def _event_list(self, req, identity,
                    filter_func=lambda e: True, detail=False):
        try:
            events = self.engine.list_events(req.context,
                                             identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        keys = None if detail else summary_keys

        return [format_event(req, e, keys) for e in events if filter_func(e)]
Exemple #4
0
    def index(self, req, identity):
        """
        Lists summary information for all resources
        """

        try:
            res_list = self.engine.list_stack_resources(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {'resources': [format_resource(req, res) for res in res_list]}
Exemple #5
0
    def show(self, req, identity, resource_name):
        """
        Gets detailed information for a stack
        """

        try:
            res = self.engine.describe_stack_resource(req.context, identity,
                                                      resource_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {'resource': format_resource(req, res)}
Exemple #6
0
    def metadata(self, req, identity, resource_name):
        """
        Gets detailed information for a stack
        """

        try:
            res = self.engine.describe_stack_resource(req.context, identity,
                                                      resource_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {engine_api.RES_METADATA: res[engine_api.RES_METADATA]}
Exemple #7
0
    def index(self, req, identity):
        """
        Lists summary information for all resources
        """

        try:
            res_list = self.engine.list_stack_resources(req.context,
                                                        identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {'resources': [format_resource(req, res) for res in res_list]}
Exemple #8
0
    def _event_list(self,
                    req,
                    identity,
                    filter_func=lambda e: True,
                    detail=False):
        try:
            events = self.engine.list_events(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        keys = None if detail else summary_keys

        return [format_event(req, e, keys) for e in events if filter_func(e)]
Exemple #9
0
    def show(self, req, identity, resource_name):
        """
        Gets detailed information for a stack
        """

        try:
            res = self.engine.describe_stack_resource(req.context,
                                                      identity,
                                                      resource_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {'resource': format_resource(req, res)}
Exemple #10
0
    def metadata(self, req, identity, resource_name):
        """
        Gets detailed information for a stack
        """

        try:
            res = self.engine.describe_stack_resource(req.context,
                                                      identity,
                                                      resource_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {engine_api.RES_METADATA: res[engine_api.RES_METADATA]}
Exemple #11
0
    def update(self, req, identity, body):
        """
        Update an existing stack with a new template and/or parameters
        """
        data = InstantiationData(body)

        try:
            res = self.engine.update_stack(req.context, identity,
                                           data.template(), data.user_params(),
                                           data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        raise exc.HTTPAccepted()
Exemple #12
0
    def update(self, req, identity, body):
        """
        Update an existing stack with a new template and/or parameters
        """
        data = InstantiationData(body)

        try:
            res = self.engine.update_stack(
                req.context, identity, data.template(), data.environment(), data.files(), data.args()
            )
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        raise exc.HTTPAccepted()
Exemple #13
0
    def delete(self, req, identity):
        """
        Delete the specified stack
        """

        try:
            res = self.engine.delete_stack(req.context, identity, cast=False)

        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if res is not None:
            raise exc.HTTPBadRequest(res['Error'])

        raise exc.HTTPNoContent()
Exemple #14
0
    def template(self, req, identity):
        """
        Get the template body for an existing stack
        """

        try:
            templ = self.engine_rpcapi.get_template(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if templ is None:
            raise exc.HTTPNotFound()

        # TODO(zaneb): always set Content-type to application/json
        return templ
Exemple #15
0
    def create(self, req, body):
        """
        Create a new stack
        """

        data = InstantiationData(body)

        try:
            result = self.engine.create_stack(
                req.context, data.stack_name(), data.template(), data.environment(), data.files(), data.args()
            )
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        return {"stack": format_stack(req, {engine_api.STACK_ID: result})}
Exemple #16
0
    def create(self, req, body):
        """
        Create a new stack
        """

        data = InstantiationData(body)

        try:
            result = self.engine.create_stack(req.context, data.stack_name(),
                                              data.template(),
                                              data.user_params(), data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        raise exc.HTTPCreated(location=util.make_url(req, result))
Exemple #17
0
    def delete(self, req, identity):
        """
        Delete the specified stack
        """

        try:
            res = self.engine.delete_stack(req.context, identity, cast=False)

        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if res is not None:
            raise exc.HTTPBadRequest(res["Error"])

        raise exc.HTTPNoContent()
Exemple #18
0
    def _event_list(self, req, identity,
                    filter_func=lambda e: True, detail=False):
        try:
            result = self.engine.list_events(req.context,
                                             identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if 'events' not in result:
            raise exc.HTTPInternalServerError()
        ev_list = result['events']

        keys = None if detail else summary_keys

        return [format_event(req, e, keys) for e in ev_list if filter_func(e)]
Exemple #19
0
    def template(self, req, identity):
        """
        Get the template body for an existing stack
        """

        try:
            templ = self.engine.get_template(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if templ is None:
            raise exc.HTTPNotFound()

        # TODO(zaneb): always set Content-type to application/json
        return templ
Exemple #20
0
    def show(self, req, identity):
        """
        Gets detailed information for a stack
        """

        try:
            stack_list = self.engine_rpcapi.show_stack(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if not stack_list['stacks']:
            raise exc.HTTPInternalServerError()

        stack = stack_list['stacks'][0]

        return {'stack': format_stack(req, stack)}
Exemple #21
0
    def show(self, req, identity):
        """
        Gets detailed information for a stack
        """

        try:
            stack_list = self.engine.show_stack(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if not stack_list:
            raise exc.HTTPInternalServerError()

        stack = stack_list[0]

        return {"stack": format_stack(req, stack)}
Exemple #22
0
    def lookup(self, req, stack_name, path='', body=None):
        """
        Redirect to the canonical URL for a stack
        """

        try:
            identity = self.engine.identify_stack(req.context,
                                                  stack_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        location = util.make_url(req, identity)
        if path:
            location = '/'.join([location, path])

        raise exc.HTTPFound(location=location)
Exemple #23
0
    def lookup(self, req, stack_name, path='', body=None):
        """
        Redirect to the canonical URL for a stack
        """

        try:
            identity = self.engine_rpcapi.identify_stack(
                req.context, stack_name)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        location = util.make_url(req, identity)
        if path:
            location = '/'.join([location, path])

        raise exc.HTTPFound(location=location)
Exemple #24
0
    def _event_list(self,
                    req,
                    identity,
                    filter_func=lambda e: True,
                    detail=False):
        try:
            result = self.engine.list_events(req.context, identity)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if 'events' not in result:
            raise exc.HTTPInternalServerError()
        ev_list = result['events']

        keys = None if detail else summary_keys

        return [format_event(req, e, keys) for e in ev_list if filter_func(e)]
Exemple #25
0
    def validate_template(self, req, body):
        """
        Implements the ValidateTemplate API action
        Validates the specified template
        """

        data = InstantiationData(body)

        try:
            result = self.engine.validate_template(req.context, data.template())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if "Error" in result:
            raise exc.HTTPBadRequest(result["Error"])

        return result
Exemple #26
0
    def create(self, req, body):
        """
        Create a new stack
        """

        data = InstantiationData(body)

        try:
            result = self.engine.create_stack(req.context,
                                              data.stack_name(),
                                              data.template(),
                                              data.user_params(),
                                              data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        raise exc.HTTPCreated(location=util.make_url(req, result))
Exemple #27
0
    def index(self, req):
        """
        Lists summary information for all stacks
        """

        try:
            stacks = self.engine.list_stacks(req.context)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        summary_keys = (engine_api.STACK_ID, engine_api.STACK_NAME,
                        engine_api.STACK_DESCRIPTION, engine_api.STACK_STATUS,
                        engine_api.STACK_STATUS_DATA,
                        engine_api.STACK_CREATION_TIME,
                        engine_api.STACK_DELETION_TIME,
                        engine_api.STACK_UPDATED_TIME)

        return {'stacks': [format_stack(req, s, summary_keys) for s in stacks]}
Exemple #28
0
    def validate_template(self, req, body):
        """
        Implements the ValidateTemplate API action
        Validates the specified template
        """

        data = InstantiationData(body)

        try:
            result = self.engine_rpcapi.validate_template(
                req.context, data.template())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex, True)

        if 'Error' in result:
            raise exc.HTTPBadRequest(explanation=result['Error'])

        return result
Exemple #29
0
    def update(self, req, identity, body):
        """
        Update an existing stack with a new template and/or parameters
        """
        data = InstantiationData(body)

        try:
            res = self.engine.update_stack(req.context,
                                           identity,
                                           data.template(),
                                           data.user_params(),
                                           data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        if 'Description' in res:
            raise exc.HTTPBadRequest(explanation=res['Description'])

        raise exc.HTTPAccepted()
Exemple #30
0
    def create(self, req, body):
        """
        Create a new stack
        """

        data = InstantiationData(body)

        try:
            result = self.engine_rpcapi.create_stack(req.context,
                                                     data.stack_name(),
                                                     data.template(),
                                                     data.user_params(),
                                                     data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex, True)

        if 'Description' in result:
            raise exc.HTTPBadRequest(explanation=result['Description'])

        raise exc.HTTPCreated(location=util.make_url(req, result))
Exemple #31
0
    def index(self, req):
        """
        Lists summary information for all stacks
        """

        try:
            stacks = self.engine.list_stacks(req.context)
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex)

        summary_keys = (engine_api.STACK_ID,
                        engine_api.STACK_NAME,
                        engine_api.STACK_DESCRIPTION,
                        engine_api.STACK_STATUS,
                        engine_api.STACK_STATUS_DATA,
                        engine_api.STACK_CREATION_TIME,
                        engine_api.STACK_DELETION_TIME,
                        engine_api.STACK_UPDATED_TIME)

        return {'stacks': [format_stack(req, s, summary_keys) for s in stacks]}
Exemple #32
0
    def create(self, req, body):
        """
        Create a new stack
        """

        data = InstantiationData(body)

        try:
            result = self.engine_rpcapi.create_stack(req.context,
                                                     data.stack_name(),
                                                     data.template(),
                                                     data.user_params(),
                                                     data.args())
        except rpc_common.RemoteError as ex:
            return util.remote_error(ex, True)

        if 'Description' in result:
            raise exc.HTTPBadRequest(explanation=result['Description'])

        raise exc.HTTPCreated(location=util.make_url(req, result))