处理领事的有用工具。
consul-utils的Python项目详细描述
执政官
简介
Consul是一个高度可用的分布式服务发现和千伏存储,设计支持现代数据中心。consul提供了一个有用的ui,但它不方便自动化和批处理。consul utils是基于consul的api的用于这些作业的有用命令行工具。
安装
pip易于安装
pip install consul_utils
用法
显示帮助的方式
consul_utils --help
consul utils提供了几个有用的工具来处理consul。
配置
首先,您应该创建一个配置文件来保存以下常见设置:
# consul configuration
consul:
# consul host
host: "test.consul.com"
# consul port
port: 8500
# consul scheme
scheme: "http"
# consul ACL token
token: ""
# default root
root: ""
# cache configuration
cache:
# cache enabled or not
cache_enabled: true
# cache file
cache_dir: ".consul_cache"
# cache expire seconds
cache_ttl: 600
# log configuration
log:
# log level
log_level: "INFO"
# output configuration
reporter:
# result output type, text, json or csv
output_type: "text"
# result output file, leave empty to print to console
output_file: ""
# output all scan data
show_all_scan: false
# output filtered data
show_filtered: true
# output not filtered data
show_no_filtered: false
# output flags data
show_flags: false
# search command configuration
search:
# search results limit
limit: 10
# search fields, keys or values
fields: "keys"
# use regex for search or not
regex: false
将此文件保存到config.yml
,记住这不是必需的,所有设置都可以通过命令行选项指定。如果在配置文件和选项中都存在相同的设置,则选项值将重写配置文件。
转储领事密钥值
转储键和值
consul_utils dump -c config.yml
指定目录
consul_utils dump -c config.yml -r test/test_root
更改输出类型、文本(默认)、JSON或CSV
consul_utils dump -c config.yml -r test/test_root -x json
输出到文件而不是控制台
consul_utils dump -c config.yml -r test/test_root -o out.txt
在consun键值中搜索
包含test
consul_utils search -c config.yml -q test
搜索包含test
consul_utils search -c config.yml -q test -f values
限制输出结果编号,默认值10
consul_utils search -c config.yml -q test --limit 5
使用regex进行搜索
consul_utils search -c config.yml -q ^test$ -e
将键值从一个位置复制到另一个位置
将源根下的键值复制到目标根下
consul_utils copy -c config.yml --root test/source --target-root test/target
比较两个键值
比较两个键值和两个指定根下的所有子键值 此命令将比较具有相同相对路径的键的所有值。
consul_utils diff -c config.yml --root1 test1/aa --root2 test2/bb
比较两个不同主机的键值。如果未指定,将使用默认设置(主机、端口、方案、令牌)。
consul_utils diff -c config.yml --host1 test1.consul.com --root1 test1/aa --host2 test2.consul.com --root2 test2/bb
测试
在http://test.consul.com:8500准备一个consun节点(您可以更改hosts文件)。
安装pytest并由pytest运行
pytest
作者
吴文涛