The fetcher retrieves a list of scopes to rate. These scopes are then passed to the collector, in combination with each metric type.
Fetchers are extremely simple. A custom fetcher must implement the following class:
- class cloudkitty.fetcher.BaseFetcher[source]¶
CloudKitty tenants fetcher.
Provides Cloudkitty integration with a backend announcing ratable scopes.
get_tenants method takes no parameters and returns a list of unique
scope_ids, represented as
The name of the new fetcher must be specified as a class attribute.
Options for the new fetcher must be registered under the
A new scope fetcher must be implemented in a new module, in
cloudkitty.fetcher.<name>.py. Its class must be called
An entrypoint must be registered for new fetchers. This is done in the
setup.cfg file, located at the root of the repository:
cloudkitty.fetchers = keystone = cloudkitty.fetcher.keystone:KeystoneFetcher source = cloudkitty.fetcher.source:SourceFetcher # [...] custom = cloudkitty.fetcher.custom:CustomFetcher
The most simple scope fetcher is the
SourceFetcher. It simply returns a
list of scopes read from the configuration file:
# In cloudkitty/fetcher/source.py from oslo_config import cfg from cloudkitty import fetcher FETCHER_SOURCE_OPTS = 'fetcher_source' fetcher_source_opts = [ cfg.ListOpt( 'sources', default=list(), help='list of source identifiers', ), ] # Registering the 'sources' option in the 'fetcher_source' option cfg.CONF.register_opts(fetcher_source_opts, FETCHER_SOURCE_OPTS) CONF = cfg.CONF class SourceFetcher(fetcher.BaseFetcher): # Defining the name of the fetcher name = 'source' # Returning the list of scopes read from the configuration file def get_tenants(self): return CONF.fetcher_source.sources
More complex examples can be found in the