def _create_resource_instance(self, resource_name, plural_name):
        """Factory function for quota Resource.

        This routine returns a resource instance of the appropriate type
        according to system configuration.

        If QUOTAS.track_quota_usage is True, and there is a model mapping for
        the current resource, this function will return an instance of
        AccountedResource; otherwise an instance of CountableResource.
        """

        if (not cfg.CONF.QUOTAS.track_quota_usage
                or resource_name not in self._tracked_resource_mappings):
            LOG.info(
                _LI("Creating instance of CountableResource for "
                    "resource:%s"), resource_name)
            return resource.CountableResource(resource_name,
                                              resource._count_resource,
                                              'quota_%s' % resource_name)
        else:
            LOG.info(
                _LI("Creating instance of TrackedResource for "
                    "resource:%s"), resource_name)
            return resource.TrackedResource(
                resource_name, self._tracked_resource_mappings[resource_name],
                'quota_%s' % resource_name)
 def _plugins_support(self, extension):
     alias = extension.get_alias()
     supports_extension = alias in self.get_supported_extension_aliases()
     if not supports_extension:
         LOG.info(
             _LI("Extension %s not supported by any of loaded "
                 "plugins"), alias)
     return supports_extension
Beispiel #3
0
    def __call__(self, request):
        """WSGI method that controls (de)serialization and method dispatch."""

        LOG.info(_LI("%(method)s %(url)s"), {
            "method": request.method,
            "url": request.url
        })

        try:
            action, args, accept = self.deserializer.deserialize(request)
        except exception.InvalidContentType:
            msg = _("Unsupported Content-Type")
            LOG.exception(_LE("InvalidContentType: %s"), msg)
            return Fault(webob.exc.HTTPBadRequest(explanation=msg))
        except n_exc.MalformedRequestBody:
            msg = _("Malformed request body")
            LOG.exception(_LE("MalformedRequestBody: %s"), msg)
            return Fault(webob.exc.HTTPBadRequest(explanation=msg))

        try:
            action_result = self.dispatch(request, action, args)
        except webob.exc.HTTPException as ex:
            LOG.info(_LI("HTTP exception thrown: %s"), ex)
            action_result = Fault(ex, self._fault_body_function)
        except Exception:
            LOG.exception(_LE("Internal error"))
            # Do not include the traceback to avoid returning it to clients.
            action_result = Fault(webob.exc.HTTPServerError(),
                                  self._fault_body_function)

        if isinstance(action_result, dict) or action_result is None:
            response = self.serializer.serialize(action_result,
                                                 accept,
                                                 action=action)
        else:
            response = action_result

        try:
            LOG.info(_LI("%(url)s returned with HTTP %(status)d"),
                     dict(url=request.url, status=response.status_int))
        except AttributeError as e:
            LOG.info(_LI("%(url)s returned a fault: %(exception)s"),
                     dict(url=request.url, exception=e))

        return response
    def add_extension(self, ext):
        # Do nothing if the extension doesn't check out
        if not self._check_extension(ext):
            return

        alias = ext.get_alias()
        LOG.info(_LI('Loaded extension: %s'), alias)

        if alias in self.extensions:
            raise exceptions.DuplicatedExtension(alias=alias)
        self.extensions[alias] = ext
Beispiel #5
0
 def __init__(self,
              plugin,
              collection,
              resource,
              attr_info,
              allow_bulk=False,
              member_actions=None,
              parent=None,
              allow_pagination=False,
              allow_sorting=False):
     if member_actions is None:
         member_actions = []
     self._plugin = plugin
     self._collection = collection.replace('-', '_')
     self._resource = resource.replace('-', '_')
     self._attr_info = attr_info
     self._allow_bulk = allow_bulk
     self._allow_pagination = allow_pagination
     self._allow_sorting = allow_sorting
     self._native_bulk = self._is_native_bulk_supported()
     self._native_pagination = self._is_native_pagination_supported()
     self._native_sorting = self._is_native_sorting_supported()
     self._policy_attrs = self._init_policy_attrs()
     self._notifier = n_rpc.get_notifier('network')
     self._member_actions = member_actions
     self._primary_key = self._get_primary_key()
     if self._allow_pagination and self._native_pagination:
         # Native pagination need native sorting support
         if not self._native_sorting:
             raise exceptions.Invalid(
                 _("Native pagination depend on native sorting"))
         if not self._allow_sorting:
             LOG.info(
                 _LI("Allow sorting is enabled because native "
                     "pagination requires native sorting"))
             self._allow_sorting = True
     self.parent = parent
     if parent:
         self._parent_id_name = '%s_id' % parent['member_name']
         parent_part = '_%s' % parent['member_name']
     else:
         self._parent_id_name = None
         parent_part = ''
     self._plugin_handlers = {
         self.LIST: 'get%s_%s' % (parent_part, self._collection),
         self.SHOW: 'get%s_%s' % (parent_part, self._resource)
     }
     for action in [self.CREATE, self.UPDATE, self.DELETE]:
         self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                      self._resource)
 def __init__(self, path):
     LOG.info(_LI('Initializing extension manager.'))
     self.path = path
     self.extensions = {}
     self._load_all_extensions()