使用zookeeper、etcd、consul管理配置的库
distconfig的Python项目详细描述
distconfig
合理
当您必须管理跨节点分布的给定服务的配置时,您可能需要 要考虑使用其中一个分布式配置管理器,例如zookeeper、etcd、consul…,请执行以下操作 库的目标是让开发人员能够方便地访问存储在以前后端中的配置。
安装:
要使用zookeeper作为后端,您应该使用distconfig
$ pip install distconfig[zookeeper]
使用etcd:
$ pip install distconfig[etcd]
使用consul:
$ pip install distconfig[consul]
用法:
使用zookeeper作为后端的示例
from kazoo import client from distconfig import Proxy client = client.KazooClient() # The user must call ``KazooClient.start()`` before using this particular # backend client.start() proxy = Proxy.configure( 'distconfig.backends.zookeeper.ZooKeeperBackend', client=client, ) # config is a read only mapping-like object. config = proxy.get_config('/distconfig/service_name/config') print config['key'] # Getting nested values works by supplying key seperated by '/' char. print config['key/inner'] # You can assert key value type by using typed get function e.g. # get_int, get_float, get_unicode, get_bytes ... . print config.get_int('key/inner/int_key') # Getting a inner config. print config.get_config('key/inner/dict_key')
发展:
从安装依赖项开始
$ pip install -r requirements/dev.txt requirements/base.txt
要运行单元测试,请使用tox
$ tox
要运行集成测试,建议您安装docker,然后运行
$ ./run-tests.sh
上面的脚本将为每个后端设置Docker容器 并对它们运行集成测试。
待办事项:
- 将文件添加为后端(使用https://pypi.python.org/pypi/watchdog)