diff options
author | Giuseppe Lavagetto <lavagetto@gmail.com> | 2013-11-23 23:57:05 +0100 |
---|---|---|
committer | Giuseppe Lavagetto <lavagetto@gmail.com> | 2013-12-02 19:34:25 +0100 |
commit | 0e5789150352a6e841326edd51fb719d8f3cb1e9 (patch) | |
tree | 25ac3f088b28f426258486e8e8ac81c185656a5a | |
parent | c145d54b78e64f4f266eda14511854059f108ff7 (diff) |
Correctly handling info on the creation of a key.
In order to be able to return the info that the key was created,
we need to return all the http response from api_execute (which is
IMO the right thing to do anyway).
-rw-r--r-- | src/etcd/client.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/etcd/client.py b/src/etcd/client.py index bc1a76f..a770575 100644 --- a/src/etcd/client.py +++ b/src/etcd/client.py @@ -11,6 +11,7 @@ import json import ssl import etcd +import logging class Client(object): @@ -161,7 +162,7 @@ class Client(object): return [ node.strip() for node in self.api_execute( self.version_prefix + '/machines', - self._MGET).split(',') + self._MGET).data.split(',') ] @property @@ -175,7 +176,7 @@ class Client(object): """ return self.api_execute( self.version_prefix + '/leader', - self._MGET) + self._MGET).data @property def key_endpoint(self): @@ -412,12 +413,12 @@ class Client(object): def _result_from_response(self, response): """ Creates an EtcdResult from json dictionary """ try: - res = json.loads(response) - if isinstance(res, list): - return [etcd.EtcdResult(**v) for v in res] + res = json.loads(response.data) + if response.status == 201: + res['newKey'] = True return etcd.EtcdResult(**res) except Exception, e: - raise etcd.EtcdException('Unable to decode server response: %s', e) + raise etcd.EtcdException('Unable to decode server response: %s' % e) def _next_server(self): """ Selects the next server in the list, refreshes the server list. """ @@ -459,12 +460,8 @@ class Client(object): self._machines_cache = self.machines self._machines_cache.remove(self._base_uri) - if response.status == 200: - return response.data - elif response.status == 201: - #we still need to know this from the response, I guess - response.data['newKey'] = True - return response.data + if response.status in [200,201]: + return response else: #throw the appropriate exception |