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的更多相关文章

  1. jenkins+docker+git+etcd实现应用配置文件管理

    两台机器: 一台机器安装gitlab: http://www.cnblogs.com/cjsblogs/p/8716932.html 另一台机器安装etcd+docker+jenkins jenkin ...

  2. Python 检测系统时间,k8s版本,redis集群,etcd,mysql,ceph,kafka

    一.概述 线上有一套k8s集群,部署了很多应用.现在需要对一些基础服务做一些常规检测,比如: 系统时间,要求:k8s的每一个节点的时间,差值上下不超过2秒 k8s版本,要求:k8s的每一个节点的版本必 ...

  3. 使用Python进行分布式系统协调 (ZooKeeper/Consul/etcd)

    来源:naughty 链接:my.oschina.net/taogang/blog/410864 笔者之前的博文提到过,随着大数据时代的到来,分布式是解决大数据问题的一个主要手段,随着越来越多的分布式 ...

  4. python使用etcd

    import sys import etcd client = etcd.Client( host='127.0.0.1', port=2379, allow_reconnect=True) clie ...

  5. etcd api 接口

    etcd api接口 基本操作api: https://github.com/coreos/etcd/blob/6acb3d67fbe131b3b2d5d010e00ec80182be4628/Doc ...

  6. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

  7. 基于docker+etcd+confd + haproxy构建高可用、自发现的web服务

    基于docker+etcd+confd + haproxy构建高可用.自发现的web服务 2016-05-16 15:12 595人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主 ...

  8. Python从零搭建Conf_Web配置管理平台

    环境 CentOS 6/7 x64 Python:2 .7.6 Etcd: 3.2.18 Confd:0 .16.0 Nginx: 1.12.1 效果演示 一,拓扑图: 二.涉及软件 ETD: .分布 ...

  9. saltstack自动化运维系列11基于etcd的saltstack的自动化扩容

    saltstack自动化运维系列11基于etcd的saltstack的自动化扩容 自动化运维-基于etcd加saltstack的自动化扩容# tar -xf etcd-v2.2.1-linux-amd ...

  10. 007.基于Docker的Etcd分布式部署

    一 环境准备 1.1 基础环境 ntp配置:略 #建议配置ntp服务,保证时间一致性 etcd版本:v3.3.9 防火墙及SELinux:关闭防火墙和SELinux 名称 地址 主机名 备注 etcd ...

随机推荐

  1. 设置XtraForm标题居中

    public class CustomFormPainter : FormPainter { public CustomFormPainter(Control owner, DevExpress.Sk ...

  2. 多线程下的 Lambda表达式 异步 WebClient 读取程序图标,来作为托盘 图标 logo ico

    //读取程序图标,来作为托盘图标this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Form ...

  3. _IntfClear报错问题

    delphi对象在释放时会清除对象相关接口.如果开发人员在这之前已经将接口对应的对象释放掉,那么当清除到该接口时经常会报访问内存错误,如下图

  4. Java基础进阶整理

    Java学习笔记整理 本文档是我个人整理的,首先是想通过完成本文档更加扎实自己的基础加强对java语言的理解,然后就是想给入了门的同志们做下贡献. 当然,本文档主要是对java语言基础(当然还有很多基 ...

  5. Spring JDBC实现查询

    1 db.properties jdbc.user=root jdbc.password=920614 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbc ...

  6. 1.系统生命开发周期(SDLC)

    哎,首先我恭喜我,这学期学了一门老师们都说非常重要,而学生们都说哪里重要的课,它就是与<软件工程>课齐名的<系统分析与设计>!!骚年,不背不记,你就死定了!! 首先俺领你认识一 ...

  7. MongoDB的下载与安装

      MongoDB的下载与安装 一.简介 MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案.MongoDB 是一个介于关系 ...

  8. 【学】React的学习之旅6-组件的嵌套2

    <input type=text placeholder='aaa'>, placeholder属性是定义文本框在没有输入值之前显示的一段灰色提示 ()=>{}箭头函数在ECMA6里 ...

  9. OAF_开发系列10_实现OAF动态LOV设定

    20150712 Created By BaoXinjian

  10. Linux命令(22)find的使用

    在linux下面工作,有些命令能够大大提高效率. 比如说find命令,他哥俩可以算是必会的linux命令,几乎每天都要用到他们. find命令 find命令的一般形式 find命令的常用选项及实例 f ...