Consul服务发现和配置系统的客户端库
项目描述
Consulate是Consul服务发现和配置系统的Python客户端库和应用集。
安装
Consulate可通过pypi获取,并可以使用easy_install或pip进行安装
pip install consulate如果您需要通过Unix套接字与Consul通信,有额外的依赖项需要通过
pip install consulate[unixsocket]命令行工具
Consulate附带两个命令行工具,使从管理角度使用Consul变得更加容易。应用consulate提供了对常见任务的CLI包装。
应用passport已被移至独立应用,并在https://github.com/gmr/passport提供。
consulate
consulate应用提供了注册服务、备份和恢复KV数据库内容以及从KV数据库获取、设置和删除键的CLI接口。
usage: consulate [-h] [--api-scheme API_SCHEME] [--api-host API_HOST]
                 [--api-port API_PORT] [--datacenter DC] [--token TOKEN]
                 {register,deregister,kv,run_once} ...
CLI utilities for Consul
optional arguments:
  -h, --help            show this help message and exit
  --api-scheme API_SCHEME
                        The scheme to use for connecting to Consul with
  --api-host API_HOST   The consul host to connect on
  --api-port API_PORT   The consul API port to connect to
  --datacenter DC       The datacenter to specify for the connection
  --token TOKEN         ACL token
Commands:
  {register,deregister,kv,run_once}
    register            Register a service for this node
    deregister          Deregister a service for this node
    kv                  Key/Value Database Utilities
    run_once            Lock command
If the CONSUL_RPC_ADDR environment variable is set, it will be parsed and used
for default values when connecting.服务注册帮助
usage: consulate register [-h] [-a ADDRESS] [-p PORT] [-s SERVICE_ID]
                          [-t TAGS]
                          name {check,httpcheck,no-check,ttl} ...
positional arguments:
  name                  The service name
optional arguments:
  -h, --help            show this help message and exit
  -a ADDRESS, --address ADDRESS
                        Specify an address
  -p PORT, --port PORT  Specify a port
  -s SERVICE_ID, --service-id SERVICE_ID
                        Specify a service ID
  -t TAGS, --tags TAGS  Specify a comma delimited list of tags
Service Check Options:
  {check,httpcheck,no-check,ttl}
    check               Define an external script-based check
    httpcheck           Define an HTTP-based check
    no-check            Do not enable service monitoring
    ttl                 Define a duration based TTL checkKV数据库工具帮助
usage: consulate kv [-h] {backup,restore,ls,mkdir,get,set,rm} ...
optional arguments:
  -h, --help            show this help message and exit
Key/Value Database Utilities:
  {backup,restore,ls,mkdir,get,set,rm}
    backup              Backup to stdout or a JSON file
    restore             Restore from stdin or a JSON file
    ls                  List all of the keys
    mkdir               Create a folder
    get                 Get a key from the database
    set                 Set a key in the database
    rm                  Remove a key from the database锁定操作帮助
usage: consulate [-h] run_once [-i INTERVAL] prefix command
positional arguments:
  prefix                the name of the lock which will be held in Consul.
  command               the command to run
optional arguments:
  -h, --help            show this help message and exit
  -i, --interval        hold the lock for INTERVAL secondsAPI使用示例
以下示例突出了Consulate的使用,但并未记录完整Consulate API的范围。
使用Consulate与Consul kv数据库
consul = consulate.Consul()
# Set the key named release_flag to True
consul.kv['release_flag'] = True
# Get the value for the release_flag, if not set, raises AttributeError
try:
    should_release_feature = consul.kv['release_flag']
except AttributeError:
    should_release_feature = False
# Delete the release_flag key
del consul.kv['release_flag']
# Find all keys that start with "fl"
consul.kv.find('fl')
# Find all keys that start with "feature_flag" terminated by "/" separator
consul.kv.find('feature_flag', separator='/')
# Check to see if a key called "foo" is set
if "foo" in consul.kv:
    print 'Already Set'
# Return all of the items in the key/value store
consul.kv.items()使用Consulate.agent API
consul = consulate.Consul()
# Get all of the service checks for the local agent
checks = consul.agent.checks()
# Get all of the services registered with the local agent
services = consul.agent.services()
# Add a service to the local agent
consul.agent.service.register('redis',
                               port=6379,
                               tags=['master'],
                               ttl='10s')从Consul获取健康信息
consul = consulate.Session()
# Get the health of a individual node
health = consul.health.node('my-node')
# Get all checks that are critical
checks = consul.heath.state('critical')有关更多示例,请参阅Consulate文档。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
         consulate-0.6.0.tar.gz  (21.6 kB 查看哈希值)
      
    构建分发
         consulate-0.6.0-py2-none-any.whl  (25.8 kB 查看哈希值)
      
    
    
       关闭
    
      
        
    
    
  
consulate-0.6.0.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 78a839e71e62ea8b725b60740ef3ba282a6af7f7db4df83546ee4e762810d757 | |
| MD5 | 15bd25472f1a8c346f36903fdf54ece5 | |
| BLAKE2b-256 | 1c0b5856e3b28e4b1d78b452a6a3a708ed2b80e3db68cb7dcc274b09abd8f983 | 
    
       关闭
    
      
        
    
    
  
consulate-0.6.0-py2-none-any.whl的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 344a83570806db45a772380c7125762f669fceeb42a3dc2278e2a991b74a2719 | |
| MD5 | db8cbd06f07699ae226916977dcc23f7 | |
| BLAKE2b-256 | 4573712feb6bd02118d4650e7b26ba3431adb37454f3e9a14167e3ed85c01e14 |