def count(self, context, resource_name, *args, **kwargs): """Count a resource. For countable resources, invokes the count() function and returns its result. Arguments following the context and resource are passed directly to the count function declared by the resource. :param context: The request context, for access checks. :param resource_name: The name of the resource, as a string. """ # Get the resource res = resource_registry.get_resource(resource_name) if not res or not hasattr(res, 'count'): raise exceptions.QuotaResourceUnknown(unknown=[resource_name]) return res.count(context, *args, **kwargs)
def _call_on_drivers(self, method_name, context, continue_on_failure=False, raise_db_retriable=False): super(MechanismManager, self)._call_on_drivers( method_name, context, continue_on_failure=False, raise_db_retriable=False) if method_name.endswith('_precommit'): # This does the same thing as: # https://github.com/openstack/neutron/blob/newton-eol/neutron/ # api/v2/base.py#L489 # but from within the scope of the plugin's transaction, such # that if it fails, everything that happened prior to this in # precommit phase can also be rolled back. resource_name = method_name.replace('_precommit', '').replace( 'create_', '').replace('update_', '').replace( 'delete_', '') tracked_resource = resource_registry.get_resource(resource_name) tracked_resource._dirty_tenants.add(context.current['tenant_id']) resource_registry.set_resources_dirty(context._plugin_context)