diff --git a/manilaclient/base.py b/manilaclient/base.py index 4e5b02f75..886ecf1fd 100644 --- a/manilaclient/base.py +++ b/manilaclient/base.py @@ -63,7 +63,8 @@ class Manager(utils.HookableMixin): def api_version(self): return self.api.api_version - def _list(self, url, response_key, manager=None, body=None): + def _list(self, url, response_key, manager=None, body=None, + return_raw=None): """List the collection. :param url: a partial URL, e.g., '/shares' @@ -96,6 +97,8 @@ class Manager(utils.HookableMixin): pass with self.completion_cache('human_id', obj_class, mode="w"): with self.completion_cache('uuid', obj_class, mode="w"): + if return_raw: + return data resource = [obj_class(manager, res, loaded=True) for res in data if res] if 'count' in body: @@ -167,9 +170,11 @@ class Manager(utils.HookableMixin): except UnicodeEncodeError: pass - def _get(self, url, response_key=None): + def _get(self, url, response_key, return_raw=False): resp, body = self.api.client.get(url) if response_key: + if return_raw: + return body[response_key] return self.resource_class(self, body[response_key], loaded=True) else: return self.resource_class(self, body, loaded=True) diff --git a/manilaclient/tests/unit/v2/test_shares.py b/manilaclient/tests/unit/v2/test_shares.py index 0acf67cc8..a98eb30a1 100644 --- a/manilaclient/tests/unit/v2/test_shares.py +++ b/manilaclient/tests/unit/v2/test_shares.py @@ -332,15 +332,15 @@ class SharesTest(utils.TestCase): if version >= api_versions.APIVersion('2.69'): manager.do_list.assert_called_once_with( detailed=False, search_opts=search_opts3, - sort_key=None, sort_dir=None) + sort_key=None, sort_dir=None, return_raw=False) elif version >= api_versions.APIVersion('2.35'): manager.do_list.assert_called_once_with( detailed=False, search_opts=search_opts2, - sort_key=None, sort_dir=None) + sort_key=None, sort_dir=None, return_raw=False) else: manager.do_list.assert_called_once_with( detailed=False, search_opts=search_opts1, - sort_key=None, sort_dir=None) + sort_key=None, sort_dir=None, return_raw=False) def test_list_shares_index_with_search_opts(self): search_opts = { diff --git a/manilaclient/v2/shares.py b/manilaclient/v2/shares.py index 0964dd027..20aea68b5 100644 --- a/manilaclient/v2/shares.py +++ b/manilaclient/v2/shares.py @@ -127,7 +127,7 @@ class ShareManager(base.ManagerWithFind): def create(self, share_proto, size, snapshot_id=None, name=None, description=None, metadata=None, share_network=None, share_type=None, is_public=False, availability_zone=None, - share_group_id=None, scheduler_hints=None): + share_group_id=None, scheduler_hints=None, return_raw=False): """Create a share. :param share_proto: text - share protocol for new share available @@ -166,7 +166,8 @@ class ShareManager(base.ManagerWithFind): if share_group_id: body['share_group_id'] = share_group_id - return self._create('/shares', {'share': body}, 'share') + return self._create('/shares', {'share': body}, 'share', + return_raw=return_raw) @api_versions.wraps("2.29") @api_versions.experimental_api @@ -321,14 +322,15 @@ class ShareManager(base.ManagerWithFind): info = {'snapshot_id': snapshot_id} return self._action('revert', share, info=info) - def get(self, share): + def get(self, share, return_raw=False): """Get a share. :param share: either share object or text with its ID. :rtype: :class:`Share` """ share_id = base.getid(share) - return self._get("/shares/%s" % share_id, "share") + return self._get("/shares/%s" % share_id, "share", + return_raw=return_raw) def update(self, share, **kwargs): """Updates a share. @@ -345,31 +347,34 @@ class ShareManager(base.ManagerWithFind): @api_versions.wraps("1.0", "2.34") def list(self, detailed=True, search_opts=None, - sort_key=None, sort_dir=None): + sort_key=None, sort_dir=None, return_raw=False): """Get a list of all shares.""" search_opts = search_opts or {} search_opts.pop("export_location", None) search_opts.pop("is_soft_deleted", None) return self.do_list(detailed=detailed, search_opts=search_opts, - sort_key=sort_key, sort_dir=sort_dir) + sort_key=sort_key, sort_dir=sort_dir, + return_raw=return_raw) @api_versions.wraps("2.35", "2.68") # noqa def list(self, detailed=True, search_opts=None, # noqa - sort_key=None, sort_dir=None): + sort_key=None, sort_dir=None, return_raw=False): """Get a list of all shares.""" search_opts.pop("is_soft_deleted", None) return self.do_list(detailed=detailed, search_opts=search_opts, - sort_key=sort_key, sort_dir=sort_dir) + sort_key=sort_key, sort_dir=sort_dir, + return_raw=return_raw) @api_versions.wraps("2.69") # noqa def list(self, detailed=True, search_opts=None, # noqa - sort_key=None, sort_dir=None): + sort_key=None, sort_dir=None, return_raw=False): """Get a list of all shares.""" return self.do_list(detailed=detailed, search_opts=search_opts, - sort_key=sort_key, sort_dir=sort_dir) + sort_key=sort_key, sort_dir=sort_dir, + return_raw=return_raw) def do_list(self, detailed=True, search_opts=None, - sort_key=None, sort_dir=None): + sort_key=None, sort_dir=None, return_raw=False): """Get a list of all shares. :param detailed: Whether to return detailed share info or not. @@ -440,7 +445,7 @@ class ShareManager(base.ManagerWithFind): else: path = "/shares%s" % (query_string,) - return self._list(path, 'shares') + return self._list(path, 'shares', return_raw=return_raw) def delete(self, share, share_group_id=None): """Delete a share.