范围获取器¶
该获取器检索需要评级的范围列表。然后,这些范围会与每种指标类型一起传递给收集器。
实现¶
获取器非常简单。自定义获取器必须实现以下类
get_tenants 方法不接受任何参数,并返回一个由 str 表示的唯一 scope_id 列表。
必须将新获取器的名称指定为类属性。
必须在新获取器的选项在 fetcher_<name> 配置节下注册。
必须在新模块中实现新的范围获取器,即 cloudkitty.fetcher.<name>.py。它的类必须命名为 <Name>Fetcher。
必须为新的获取器注册一个入口点。这在位于仓库根目录的 setup.cfg 文件中完成
cloudkitty.fetchers =
keystone = cloudkitty.fetcher.keystone:KeystoneFetcher
source = cloudkitty.fetcher.source:SourceFetcher
# [...]
custom = cloudkitty.fetcher.custom:CustomFetcher
示例¶
最简单的范围获取器是 SourceFetcher。它只是从配置文件中读取范围列表并返回
# 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
可以在 cloudkitty/fetcher 目录中找到更复杂的示例。