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(
                "Creating instance of CountableResource for "
                "resource:%s", resource_name)
            return resource.CountableResource(resource_name,
                                              resource._count_resource,
                                              'quota_%s' % resource_name)
        else:
            LOG.info("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 __init__(self, *args, **kwargs):
        super(GBPQuotaBase, self).__init__(*args, **kwargs)

        tenant_id = kwargs['tenant_id']
        ctx = context.Context(user_id=None, tenant_id=tenant_id)
        class_name = self.__class__.__name__
        resource = DB_CLASS_TO_RESOURCE_NAMES[class_name]
        d = {
            resource:
            quota_resource.CountableResource(resource, None,
                                             "quota_" + resource)
        }
        resource_quota = QUOTA_DRIVER.get_tenant_quotas(ctx, d,
                                                        tenant_id)[resource]
        if resource_quota == -1:
            return
        count = self._get_collection_count(ctx, self.__class__)
        if count >= resource_quota:
            raise nexcp.OverQuota(overs=[resource])