Support etcd v2. Use this version by default (#12312)

* Support etcd v2. Use this version by default

* default to etcd v1
pull/12806/merge
rdezavalia 9 years ago committed by Brian Coca
parent 9342c7cc02
commit a7274774ed

@ -32,10 +32,16 @@ ANSIBLE_ETCD_URL = 'http://127.0.0.1:4001'
if os.getenv('ANSIBLE_ETCD_URL') is not None: if os.getenv('ANSIBLE_ETCD_URL') is not None:
ANSIBLE_ETCD_URL = os.environ['ANSIBLE_ETCD_URL'] ANSIBLE_ETCD_URL = os.environ['ANSIBLE_ETCD_URL']
ANSIBLE_ETCD_VERSION = 'v1'
if os.getenv('ANSIBLE_ETCD_VERSION') is not None:
ANSIBLE_ETCD_URL = os.environ['ANSIBLE_ETCD_VERSION']
class Etcd: class Etcd:
def __init__(self, url=ANSIBLE_ETCD_URL, validate_certs=True): def __init__(self, url=ANSIBLE_ETCD_URL, version=ANSIBLE_ETCD_VERSION,
validate_certs=True):
self.url = url self.url = url
self.baseurl = '%s/v1/keys' % (self.url) self.version = version
self.baseurl = '%s/%s/keys' % (self.url,self.version)
self.validate_certs = validate_certs self.validate_certs = validate_certs
def get(self, key): def get(self, key):
@ -52,8 +58,13 @@ class Etcd:
try: try:
# {"action":"get","key":"/name","value":"Jane Jolie","index":5} # {"action":"get","key":"/name","value":"Jane Jolie","index":5}
item = json.loads(data) item = json.loads(data)
if 'value' in item: if self.version == 'v1':
value = item['value'] if 'value' in item:
value = item['value']
else:
if 'node' in item:
value = item['node']['value']
if 'errorCode' in item: if 'errorCode' in item:
value = "ENOENT" value = "ENOENT"
except: except:

Loading…
Cancel
Save