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. selenium浏览器操作

    在元素定位中xpath使用的还算比较多,介绍一下常见的firfox和chrome浏览器插件安装 一.浏览器定位工具安装 1.firfox firfox比较简单,主要浏览器自带的定位功能也比较强大国内也 ...

  2. Java实现多线程的三种方式

    Java多线程实现方式主要有三种:继承Thread类.实现Runnable接口.使用ExecutorService.Callable.Future实现有返回结果的多线程.前两种方式启动的线程没有返回值 ...

  3. knockout+bootstrap--一些复杂的应用合集

    一.针对My97日历控件的绑定 普通绑定和特殊格式绑定(红色部分) <!-- ko foreach: items --> <td class="ruyeeTableTDLa ...

  4. Python 网络编程(二)

    Python 网络编程 上一篇博客介绍了socket的基本概念以及实现了简单的TCP和UDP的客户端.服务器程序,本篇博客主要对socket编程进行更深入的讲解 一.简化版ssh实现 这是一个极其简单 ...

  5. Android Studio 高级配置

    http://liukun.engineer/2016/04/10/Android-Studio-advanced-configuration/

  6. java和h5 canvas德州扑克开发中(一)

    先附上我的德州扑克测试地址 http://120.26.217.116:8080/LxrTexas/texasIndex.html 我和一个朋友的德州扑克历时一个多月开发,目前已经基本可玩. 前端主要 ...

  7. A New Beginning

    不知不觉中,接触前端已经快两个月了,从一开始的懵懂无知,到现在的--依旧不是很懂,似乎浪费了很多时间,一直都有记纸质笔记.写总结的习惯,写满一本又换一本,却在不知不觉中忽略了自己的实践能力,花费了太多 ...

  8. 阿里云CentOS6上配置iptables

    参考:http://blog.abv.cn/?p=50 阿里云CentOS6默认没有启动iptables 1.检查iptables状态 [root@iZ94jj63a3sZ ~]# service i ...

  9. FPGA低级建模---按键去抖动

    FPGA低级建模,原则上一个模块一个功能,如按键去抖动建模中,有两个模块. 1.detect_module 这个是按键检测模块,主要检测按键的高低电平变化,现在按键是按下还是释放. 2.delay_m ...

  10. Git Pro - (2)分支

    Git 保存的不是文件差异或者变化量,而只是一系列文件快照. 在 Git中提交时,会保存一个提交(commit)对象,它包含一个指向暂存内容快照的指针,作者和相关附属信息,以及一定数量(也可能没有)指 ...