keystone.common.driver_hints module¶
- class keystone.common.driver_hints.Hints[source]¶
Bases:
object
Encapsulate driver hints for listing entities.
Hints are modifiers that affect the return of entities from a list_<entities> operation. They are typically passed to a driver to give direction as to what filtering, pagination or list limiting actions are being requested.
It is optional for a driver to action some or all of the list hints, but any filters that it does satisfy must be marked as such by calling removing the filter from the list.
A Hint object contains filters, which is a list of dicts that can be accessed publicly. Also it contains a dict called limit, which will indicate the amount of data we want to limit our listing to.
If the filter is discovered to never match, then cannot_match can be set to indicate that there will not be any matches and the backend work can be short-circuited.
Each filter term consists of:
name
: the name of the attribute being matchedvalue
: the value against which it is being matchedcomparator
: the operation, which can be one ofequals
,contains
,startswith
orendswith
case_sensitive
: whether any comparison should take account ofcase
- add_filter(name, value, comparator='equals', case_sensitive=False)[source]¶
Add a filter to the filters list, which is publicly accessible.
- keystone.common.driver_hints.truncated(f)[source]¶
Ensure list truncation is detected in Driver list entity methods.
This is designed to wrap Driver list_{entity} methods in order to calculate if the resultant list has been truncated. Provided a limit dict is found in the hints list, we increment the limit by one so as to ask the wrapped function for one more entity than the limit, and then once the list has been generated, we check to see if the original limit has been exceeded, in which case we truncate back to that limit and set the ‘truncated’ boolean to ‘true’ in the hints limit dict.