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 ...
随机推荐
- AVL的删除写法的一个错误
今天在写AVL删除的时候犯了一个傻逼错误,调了很久,教训惨痛,引以为鉴. 树中允许有重复节点,如果删除的节点有重复,则只删除1个. AVL删除采取的方法是首先判断待删除节点是否存在,如果存在,那么判断 ...
- 使用SQL语句 检测 MSSQL死锁
select spid, blocked, loginame, last_batch, status, cmd, hostname, program_name from sys.sysprocesse ...
- 01从c到c++
c++的发展历史 + 80年代贝尔实验室 本贾尼 + 83年 正式命名c++ + 87年 gnu制定了c++标准 + 92年 微软和IBM分别制定了c++标准 + 98年 ansi ISO 制定了标 ...
- 获取小众ftp服务器指定目录内容列表
今天获取小众ftp服务器指定目录内容列表时费劲急了. ///parama url="ftp://x.x.x.x/dir_name" public string GetFTPDir( ...
- 使用PowerDesigner把oom设计图导出jpg格式的图片
1: 按住Shift键点击鼠标选择要导出的对象,必须先选择. 2: 选择Edit—>Export Image 到出你需要的格式,如下图
- PHP扩展下载指导
http://pecl.php.net/package/ 相信很多人为了找PHP扩展包,很发愁. 其实可以去官网下载,还有各个版本选择,不必担心下载到了错误版本,浪费时间以及网站积分. 简单说下方法: ...
- canvas ---个性时钟
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- CSS详解
Web前端开发css基础样式总结 颜色和单位的使用 颜色 用颜色的名字表示颜色,比如:red 用16进制表示演示 比如:#FF0000 用rgb数值表示颜色,rgb(红,绿,蓝),每个值都在0-255 ...
- OAF_开发系列28_实现OAF中反编译获取class包代码JD Compiler(案例)
20150730 Created By BaoXinjian
- JAVA 取得当前目录的路径/Servlet/class/文件路径/web路径/url地址
在写java程序时不可避免要获取文件的路径...总结一下,遗漏的随时补上 1.可以在servlet的init方法里 String path = getServletContext().getRealP ...