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 ...
随机推荐
- Linux 随机生成随机数
#!/bin/bash echo $(($RANDOM % 39)) 表示生成0-39的随机数 并且不为0和39
- Javascript模式(第二章基本技巧)------读书笔记
本章主要帮助大家写出高质量的JS代码的方法,模式和习惯,例如:避免使用全局变量,使用单个的var变量声明,缓存for循环的长度变量length等 一.尽量避免使用全局变量 1 每一个js环境都有一个全 ...
- mybatis实战教程(mybatis in action)之一:开发环境搭建
mybatis 的开发环境搭建,选择: eclipse j2ee 版本,mysql 5.1 ,jdk 1.7,mybatis3.2.0.jar包.这些软件工具均可以到各自的官方网站上下载. 首先建立一 ...
- TinyHTTP代码核心流程
TinyHTTPd是一个超轻量型Http Server,使用C语言开发,全部代码不到600行 研究HTTP服务器,为了更好的造轮子,看了TinyHTTPd代码,对逻辑处理画个简单流程图(不含底层)
- NVMe over Fabrics:概念、应用和实现
对于大部分人来说,NVMe over Fabrics(简称NVMf)还是个新东西,因为其第一个正式版本的协议在今年6月份才发布.但是这并不影响人们对NVMf的关注,因为这项依托于NVMe的技术很可能继 ...
- Map以及Set的遍历(EntrySet方法,补充enumeration和Iterator的区别)
public void mearge(Map map) { Map returnMap = new HashMap<>(); // 转换为Entry Set<Map.Entry< ...
- ASP.NET webform基于Jquery,AJAX的三级联动
主要html代码 <select id="province"> <option value="0">--请选择省份--</opti ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- ubuntu 安装redis两种方式 教程
方式一: 下载地址:http://redis.io/download,下载最新文档版本. 本教程使用的最新文档版本为 2.8.17,下载并安装: $ wget http://download.redi ...
- mysql临时表的产生
sql执行会生成一个巨大的临时表,当内存放不下时,要全部copy 到磁盘,导致IO飙升,时间开销增大. 额外收获知识收藏如下: 临时表存储 MySQL临时表分为"内存临时表"和&q ...