python-etcd
Client 对象
['_MDELETE', '_MGET', '_MPOST', '_MPUT', '__class__', '__contains__', '__del__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_allow_reconnect', '_allow_redirect', '_base_uri', '_check_cluster_id', '_comparison_conditions', '_del_conditions', '_discover', '_get_headers', '_handle_server_response', '_machines_cache', '_next_server', '_protocol', '_read_options', '_read_timeout', '_result_from_response', '_sanitize_key', '_stats', '_use_proxies', '_wrap_request', 'allow_redirect', 'api_execute', 'api_execute_json', 'base_uri', 'delete', 'election', 'eternal_watch', 'expected_cluster_id', 'get', 'get_lock', 'host', 'http', 'key_endpoint', 'leader', 'leader_stats', 'machines', 'members', 'password', 'pop', 'port', 'protocol', 'read', 'read_timeout', 'set', 'stats', 'store_stats', 'test_and_set', 'update', 'username', 'version_prefix', 'watch', 'write']
类属性
http
实例属性
allow_redirect
base_uri
election # Election primitives were removed from etcd 2.0
expected_cluster_id
host
key_endpoint
leader
leader_stats
machines
members
port
protocol
read
read_timeout
stats
store_stats
version_prefix
instancemethod 实例方法
api_execute
api_execute_json
delete
eternal_watch
get
get_lock
pop
set
test_and_set
update
watch
write
实例化对象
函数原型:
def __init__(
self,
host='127.0.0.1', # mixed:类型-字符串(IP地址),元组((host,port),(host.port),...) 支持多个etcd服务端的连接。
port=, #
srv_domain=None,
version_prefix='/v2',
read_timeout=,
allow_redirect=True,
protocol='http',
cert=None,
ca_cert=None,
username=None,
password=None,
allow_reconnect=False,
use_proxies=False,
expected_cluster_id=None,
per_host_pool_size=
):
实例:
import etcd
#
client = etcd.Client() # this will create a client against etcd server running on localhost on port
client = etcd.Client(port=)
client = etcd.Client(host='127.0.0.1', port=)
client = etcd.Client(host='127.0.0.1', port=, allow_redirect=False) # wont let you run sensitive commands on non-leader machines, default is true
client = etcd.Client(
host='127.0.0.1',
port=,
allow_reconnect=True,
protocol='https',)
全局网络锁
client = etcd.Client()
lock = client.get_lock('/customer1', ttl=) # Use the lock object:
lock.acquire()
lock.is_locked() # True
lock.renew()
lock.release()
lock.is_locked() # False # The lock object may also be used as a context manager:
client = etcd.Client()
lock = client.get_lock('/customer1', ttl=)
with lock as my_lock:
do_stuff()
lock.is_locked() # True
lock.renew()
lock.is_locked() # False
# 创建etcd客户端对象,
# allow_redirect=True 这个参数是当断链的时候,etcd会再次复用connect创建可用的连接
client = etcd.Client(
host='127.0.0.1',
port=,
allow_reconnect=True,
protocol='https',) client.write('/nodes/n1', )
10
# with ttl 设置几秒,几秒后这数据就没了
client.write('/nodes/n2', , ttl=) # sets the ttl to seconds
12 # create only
client.write('/nodes/n3', 'test', prevExist=False) prevExist 如果数据有的话,就不再插入了。 client.write('/nodes/n3', 'test2', prevValue='test1') 保证value以前是test1 # mkdir
client.write('/nodes/queue', dir=True) 新版本不用这个也行,最少我不用指明dir 也是可以创建mkdir的
19 # Append a value to a queue dir
client.write('/nodes/queue', 'test', append=True) #will write i.e. /nodes/queue/
client.write('/nodes/queue', 'test2', append=True) #will write i.e. /nodes/queue/
对于数据的修改也可以用 update
result = client.read('/foo')
print(result.value) # bar
result.value += u'bar'
updated = client.update(result)
print(updated.value)
用read()方法 从etcd获取节点数据
client.read('/nodes/n2').value
#recursive递归的目录
#sorted 排序
r = client.read('/nodes', recursive=True, sorted=True)
for child in r.children:
print("%s: %s" % (child.key,child.value))
#相当于zookeeper的watch监听
client.read('/nodes/n2', wait=True) #Waits for a change in value in the key before returning.
client.read('/nodes/n2', wait=True, waitIndex=)
python-etcd的更多相关文章
- jenkins+docker+git+etcd实现应用配置文件管理
两台机器: 一台机器安装gitlab: http://www.cnblogs.com/cjsblogs/p/8716932.html 另一台机器安装etcd+docker+jenkins jenkin ...
- Python 检测系统时间,k8s版本,redis集群,etcd,mysql,ceph,kafka
一.概述 线上有一套k8s集群,部署了很多应用.现在需要对一些基础服务做一些常规检测,比如: 系统时间,要求:k8s的每一个节点的时间,差值上下不超过2秒 k8s版本,要求:k8s的每一个节点的版本必 ...
- 使用Python进行分布式系统协调 (ZooKeeper/Consul/etcd)
来源:naughty 链接:my.oschina.net/taogang/blog/410864 笔者之前的博文提到过,随着大数据时代的到来,分布式是解决大数据问题的一个主要手段,随着越来越多的分布式 ...
- python使用etcd
import sys import etcd client = etcd.Client( host='127.0.0.1', port=2379, allow_reconnect=True) clie ...
- etcd api 接口
etcd api接口 基本操作api: https://github.com/coreos/etcd/blob/6acb3d67fbe131b3b2d5d010e00ec80182be4628/Doc ...
- Python开源框架
info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...
- 基于docker+etcd+confd + haproxy构建高可用、自发现的web服务
基于docker+etcd+confd + haproxy构建高可用.自发现的web服务 2016-05-16 15:12 595人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主 ...
- Python从零搭建Conf_Web配置管理平台
环境 CentOS 6/7 x64 Python:2 .7.6 Etcd: 3.2.18 Confd:0 .16.0 Nginx: 1.12.1 效果演示 一,拓扑图: 二.涉及软件 ETD: .分布 ...
- saltstack自动化运维系列11基于etcd的saltstack的自动化扩容
saltstack自动化运维系列11基于etcd的saltstack的自动化扩容 自动化运维-基于etcd加saltstack的自动化扩容# tar -xf etcd-v2.2.1-linux-amd ...
- 007.基于Docker的Etcd分布式部署
一 环境准备 1.1 基础环境 ntp配置:略 #建议配置ntp服务,保证时间一致性 etcd版本:v3.3.9 防火墙及SELinux:关闭防火墙和SELinux 名称 地址 主机名 备注 etcd ...
随机推荐
- [转载]Eclipse调试Java的10个技巧
原文:http://www.oschina.net/question/82993_69439 我也特别喜欢的是Drop to frame. 在看这篇文章前,我推荐你看一下Eclipse 快捷键手册,我 ...
- ecstore-app接口
接口调用方式: 接口完整地址为:http://域名/index.php/wapapp/请求地址 比如获取商品信息就是 http://域名/index.php/wapapp/product.html 提 ...
- .net网站发布到局域网流程
将.net网站发布到局域网的服务器上,会遇到一些版本问题,下面把发布的流程简单说一下 一:发布网站 1.首先把需要的引用程序集都重新生成一下 2.程序集都重新生成之后,右击网站项目,选择发布选项 3. ...
- How Garbage Collection Really Works
Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...
- 【学】jQuery的源码思路3——添加事件及其他
这段添加的方法有: 各类事件函数 css() addEvent() toggle() //添加各种事件,将常用的事件名称放入数组,然后循环着加入到zQuery对象的原型上 var eventArr = ...
- tinyPng Photoshop Plugin 安装的坑
一定要注意两点: 第一: 注册表注册路径要修改为自己安装ps cc时的注册表路径[HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Photoshop\70.0]第二: Applic ...
- Spark性能测试报告与调优参数
1.代码中尽量避免group by函数,如果需要数据聚合,group形式的为rdd.map(x=>(x.chatAt(0),x)).groupbyKey().mapValues((x=>x ...
- 关于<meta http-equiv="X-UA-Compatible" content="IE=edge" />问题
我在做网页过程中都是在火狐浏览器下进行的,可是有一次我在IE浏览器下打开时却发现我设置的style.css中的大部分样式都失效率了,这个问题足足困扰了我两天,终于在百度的帮助下找到了答案,原来在网页的 ...
- 并发-Java中的Copy-On-Write容器
Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候,才会真正把内容Copy出去形成一个新的内容然后再改, ...
- controller共享数据
刚开始使用angularjs,能感受到他的强大,也在学习的途中遇到一些问题 一般我们在angularjs中共享数据使用DI的方法,具体代码如下: <script> angular.modu ...