summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Farrellee <matt@redhat.com>2014-07-10 23:09:22 -0400
committerMatthew Farrellee <matt@redhat.com>2014-07-10 23:09:22 -0400
commitd14fb4aa970c5abc2fd7ac2fd45456dec7927f3b (patch)
treea51b2f85fb1fa9c0f50c9425056d814e2b898679
parent40fc15445fbda1c8cb194143bf34b6d72a3b495b (diff)
downloadpython-saharaclient-d14fb4aa970c5abc2fd7ac2fd45456dec7927f3b.tar.gz
Update oslo-incubator apiclient module
Changes - * pep8: fixed multiple violations * Restore UUID and human-ID bash completion * Don't slugify names that don't exist Change-Id: I56ae5d529359584ad9576cfc2102996277101db1
-rw-r--r--saharaclient/openstack/common/apiclient/base.py24
-rw-r--r--saharaclient/openstack/common/apiclient/fake_client.py2
2 files changed, 22 insertions, 4 deletions
diff --git a/saharaclient/openstack/common/apiclient/base.py b/saharaclient/openstack/common/apiclient/base.py
index 5b897cc..5bd23ae 100644
--- a/saharaclient/openstack/common/apiclient/base.py
+++ b/saharaclient/openstack/common/apiclient/base.py
@@ -32,6 +32,7 @@ from six.moves.urllib import parse
from saharaclient.openstack.common.apiclient import exceptions
from saharaclient.openstack.common.gettextutils import _
from saharaclient.openstack.common import strutils
+from saharaclient.openstack.common import uuidutils
def getid(obj):
@@ -436,6 +437,21 @@ class Resource(object):
self._info = info
self._add_details(info)
self._loaded = loaded
+ self._init_completion_cache()
+
+ def _init_completion_cache(self):
+ cache_write = getattr(self.manager, 'write_to_completion_cache', None)
+ if not cache_write:
+ return
+
+ # NOTE(sirp): ensure `id` is already present because if it isn't we'll
+ # enter an infinite loop of __getattr__ -> get -> __init__ ->
+ # __getattr__ -> ...
+ if 'id' in self.__dict__ and uuidutils.is_uuid_like(self.id):
+ cache_write('uuid', self.id)
+
+ if self.human_id:
+ cache_write('human_id', self.human_id)
def __repr__(self):
reprkeys = sorted(k
@@ -448,8 +464,10 @@ class Resource(object):
def human_id(self):
"""Human-readable ID which can be used for bash completion.
"""
- if self.NAME_ATTR in self.__dict__ and self.HUMAN_ID:
- return strutils.to_slug(getattr(self, self.NAME_ATTR))
+ if self.HUMAN_ID:
+ name = getattr(self, self.NAME_ATTR, None)
+ if name is not None:
+ return strutils.to_slug(name)
return None
def _add_details(self, info):
@@ -463,7 +481,7 @@ class Resource(object):
def __getattr__(self, k):
if k not in self.__dict__:
- #NOTE(bcwaldon): disallow lazy-loading if already loaded once
+ # NOTE(bcwaldon): disallow lazy-loading if already loaded once
if not self.is_loaded():
self.get()
return self.__getattr__(k)
diff --git a/saharaclient/openstack/common/apiclient/fake_client.py b/saharaclient/openstack/common/apiclient/fake_client.py
index 09c1971..b163074 100644
--- a/saharaclient/openstack/common/apiclient/fake_client.py
+++ b/saharaclient/openstack/common/apiclient/fake_client.py
@@ -79,7 +79,7 @@ class FakeHTTPClient(client.HTTPClient):
def __init__(self, *args, **kwargs):
self.callstack = []
self.fixtures = kwargs.pop("fixtures", None) or {}
- if not args and not "auth_plugin" in kwargs:
+ if not args and "auth_plugin" not in kwargs:
args = (None, )
super(FakeHTTPClient, self).__init__(*args, **kwargs)