summaryrefslogtreecommitdiff
path: root/keystoneclient/openstack/common/apiclient/base.py
diff options
context:
space:
mode:
authorAaron Rosen <aaronorosen@gmail.com>2014-09-05 12:24:27 -0700
committerAaron Rosen <aaronorosen@gmail.com>2014-09-09 13:57:39 -0700
commit9b589ff9ff404330bd49e6c07dc82c7f9c367644 (patch)
tree0f61e5d3c776232087873057d8b93449257600f4 /keystoneclient/openstack/common/apiclient/base.py
parent1643f7da32b1f729f12d042565d8c67f10f91b8c (diff)
downloadpython-keystoneclient-9b589ff9ff404330bd49e6c07dc82c7f9c367644.tar.gz
Sync with latest oslo-incubator
Last commit: 32e7f0b56f527427544050f251999f3de588ac93 This patch syncs the python-keystoneclient with olso-incubator as I need this patch 4ef01931 which fixes a bug that's I am hitting in another client which uses the keystoneclient. Closes-bug: 1277565 Change-Id: I22f10f4fe27be16a6808b75c154ee342fea2bdda
Diffstat (limited to 'keystoneclient/openstack/common/apiclient/base.py')
-rw-r--r--keystoneclient/openstack/common/apiclient/base.py47
1 files changed, 19 insertions, 28 deletions
diff --git a/keystoneclient/openstack/common/apiclient/base.py b/keystoneclient/openstack/common/apiclient/base.py
index 511fd73..9d7119d 100644
--- a/keystoneclient/openstack/common/apiclient/base.py
+++ b/keystoneclient/openstack/common/apiclient/base.py
@@ -32,7 +32,6 @@ from six.moves.urllib import parse
from keystoneclient.openstack.common.apiclient import exceptions
from keystoneclient.openstack.common.gettextutils import _
from keystoneclient.openstack.common import strutils
-from keystoneclient.openstack.common import uuidutils
def getid(obj):
@@ -100,12 +99,13 @@ class BaseManager(HookableMixin):
super(BaseManager, self).__init__()
self.client = client
- def _list(self, url, response_key, obj_class=None, json=None):
+ def _list(self, url, response_key=None, obj_class=None, json=None):
"""List the collection.
:param url: a partial URL, e.g., '/servers'
:param response_key: the key to be looked up in response dictionary,
- e.g., 'servers'
+ e.g., 'servers'. If response_key is None - all response body
+ will be used.
:param obj_class: class for constructing the returned objects
(self.resource_class will be used by default)
:param json: data that will be encoded as JSON and passed in POST
@@ -119,7 +119,7 @@ class BaseManager(HookableMixin):
if obj_class is None:
obj_class = self.resource_class
- data = body[response_key]
+ data = body[response_key] if response_key is not None else body
# NOTE(ja): keystone returns values as list as {'values': [ ... ]}
# unlike other services which just return the list...
try:
@@ -129,15 +129,17 @@ class BaseManager(HookableMixin):
return [obj_class(self, res, loaded=True) for res in data if res]
- def _get(self, url, response_key):
+ def _get(self, url, response_key=None):
"""Get an object from collection.
:param url: a partial URL, e.g., '/servers'
:param response_key: the key to be looked up in response dictionary,
- e.g., 'server'
+ e.g., 'server'. If response_key is None - all response body
+ will be used.
"""
body = self.client.get(url).json()
- return self.resource_class(self, body[response_key], loaded=True)
+ data = body[response_key] if response_key is not None else body
+ return self.resource_class(self, data, loaded=True)
def _head(self, url):
"""Retrieve request headers for an object.
@@ -147,21 +149,23 @@ class BaseManager(HookableMixin):
resp = self.client.head(url)
return resp.status_code == 204
- def _post(self, url, json, response_key, return_raw=False):
+ def _post(self, url, json, response_key=None, return_raw=False):
"""Create an object.
:param url: a partial URL, e.g., '/servers'
:param json: data that will be encoded as JSON and passed in POST
request (GET will be sent by default)
:param response_key: the key to be looked up in response dictionary,
- e.g., 'servers'
+ e.g., 'server'. If response_key is None - all response body
+ will be used.
:param return_raw: flag to force returning raw JSON instead of
Python object of self.resource_class
"""
body = self.client.post(url, json=json).json()
+ data = body[response_key] if response_key is not None else body
if return_raw:
- return body[response_key]
- return self.resource_class(self, body[response_key])
+ return data
+ return self.resource_class(self, data)
def _put(self, url, json=None, response_key=None):
"""Update an object with PUT method.
@@ -170,7 +174,8 @@ class BaseManager(HookableMixin):
:param json: data that will be encoded as JSON and passed in POST
request (GET will be sent by default)
:param response_key: the key to be looked up in response dictionary,
- e.g., 'servers'
+ e.g., 'servers'. If response_key is None - all response body
+ will be used.
"""
resp = self.client.put(url, json=json)
# PUT requests may not return a body
@@ -188,7 +193,8 @@ class BaseManager(HookableMixin):
:param json: data that will be encoded as JSON and passed in POST
request (GET will be sent by default)
:param response_key: the key to be looked up in response dictionary,
- e.g., 'servers'
+ e.g., 'servers'. If response_key is None - all response body
+ will be used.
"""
body = self.client.patch(url, json=json).json()
if response_key is not None:
@@ -437,21 +443,6 @@ 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