def show(self, req, id): try: # NOTE(dprince): the extensions alias is used as the 'id' for show ext = self.extension_manager.extensions[id] except KeyError: raise exception.NotFound() return dict(extension=self._translate(ext))
def _process_stack(self, request, action, action_args, content_type, body, accept): """Implement the processing stack.""" # Get the implementing method try: meth, extensions = self.get_method(request, action, content_type, body) except (AttributeError, TypeError): ex = exception.ConvertedException(exception.NotFound()) return Fault(ex) except KeyError as ex: ex = exception.ConvertedException( exception.NoSuchAction(ex.args[0])) return Fault(ex) except exception.MalformedRequestBody as ex: ex = exception.ConvertedException(ex) return Fault(ex) try: method_name = meth.__qualname__ except AttributeError: method_name = 'Controller: %s Method: %s' % (six.text_type( self.controller), meth.__name__) if body: decoded_body = encodeutils.safe_decode(body, errors='ignore') msg = ("Action: '%(action)s', calling method: %(meth)s, body: " "%(body)s") % { 'action': action, 'body': decoded_body, 'meth': method_name } LOG.debug(strutils.mask_password(msg)) else: LOG.debug("Calling method '%(meth)s'", {'meth': method_name}) # Now, deserialize the request body... try: if content_type: contents = self.deserialize(meth, content_type, body) else: contents = {} except exception.InvalidContentType as ex: ex = exception.ConvertedException(ex) return Fault(ex) except exception.MalformedRequestBody as ex: ex = exception.ConvertedException(ex) return Fault(ex) # Update the action args action_args.update(contents) project_id = action_args.pop("project_id", None) context = request.environ.get('delfin.context') if (context and project_id and (project_id != context.project_id)): ex = exception.ConvertedException(exception.MalformedRequestUrl()) return Fault(ex) # Run pre-processing extensions response, post = self.pre_process_extensions(extensions, request, action_args) if not response: try: with ResourceExceptionHandler(): action_result = self.dispatch(meth, request, action_args) except Fault as ex: response = ex if not response: # No exceptions; convert action_result into a # ResponseObject resp_obj = None if type(action_result) is dict or action_result is None: resp_obj = ResponseObject(action_result) elif isinstance(action_result, ResponseObject): resp_obj = action_result else: response = action_result # Run post-processing extensions if resp_obj: _set_request_id_header(request, resp_obj) # Do a preserialize to set up the response object serializers = getattr(meth, 'wsgi_serializers', {}) resp_obj._bind_method_serializers(serializers) if hasattr(meth, 'wsgi_code'): resp_obj._default_code = meth.wsgi_code resp_obj.preserialize(accept, self.default_serializers) # Process post-processing extensions response = self.post_process_extensions( post, resp_obj, request, action_args) if resp_obj and not response: response = resp_obj.serialize(request, accept, self.default_serializers) try: msg_dict = dict(url=request.url, status=response.status_int) msg = _("%(url)s returned with HTTP %(status)s") % msg_dict except AttributeError as e: msg_dict = dict(url=request.url, e=e) msg = _("%(url)s returned a fault: %(e)s") % msg_dict LOG.info(msg) return response
def create(self, req): raise exception.NotFound()
def delete(self, req, id): raise exception.NotFound()