diff options
author | wangxiyuan <wangxiyuan@huawei.com> | 2017-06-15 09:39:50 +0800 |
---|---|---|
committer | wangxiyuan <wangxiyuan@huawei.com> | 2017-07-12 09:18:31 +0800 |
commit | a570f26d97cde31d1dfb734fd2f8d2fff7a054f5 (patch) | |
tree | c8b4e4356836212d5d6085bad88d0ec76a2e15ca | |
parent | 6a00d30e966d5fbd24cc8817afae32d9969adfb5 (diff) | |
download | python-cinderclient-a570f26d97cde31d1dfb734fd2f8d2fff7a054f5.tar.gz |
Support volume summary command
This patch added volume summary command support.
Change-Id: I7cf6e149b9ce9cae21818c60146e6db9cc2904bd
-rw-r--r-- | cinderclient/tests/unit/v3/fakes.py | 9 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 4 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_volumes.py | 8 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 21 | ||||
-rw-r--r-- | cinderclient/v3/volumes.py | 8 | ||||
-rw-r--r-- | releasenotes/notes/support-volume-summary-d6d5bb2acfef6ad5.yaml | 4 |
6 files changed, 54 insertions, 0 deletions
diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py index c06ca3e..b02d079 100644 --- a/cinderclient/tests/unit/v3/fakes.py +++ b/cinderclient/tests/unit/v3/fakes.py @@ -557,6 +557,15 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient): 'levels': {'prefix3': 'WARNING', 'prefix4': 'ERROR'}}] return (200, {}, {'log_levels': levels}) + def get_volumes_summary(self, **kw): + return 200, {}, {"volume-summary": {'total_size': 5, + 'total_count': 5, + 'metadata': { + "test_key": ["test_value"] + } + } + } + # # resource filters # diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 96dd7cf..6f2d86b 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -204,6 +204,10 @@ class ShellTest(utils.TestCase): # NOTE(jdg): we default to detail currently self.assert_called('GET', '/volumes/detail') + def test_summary(self): + self.run_command('--os-volume-api-version 3.12 summary') + self.assert_called('GET', '/volumes/summary') + def test_list_with_group_id_before_3_10(self): self.assertRaises(exceptions.UnsupportedAttribute, self.run_command, diff --git a/cinderclient/tests/unit/v3/test_volumes.py b/cinderclient/tests/unit/v3/test_volumes.py index 5eb9750..72ef916 100644 --- a/cinderclient/tests/unit/v3/test_volumes.py +++ b/cinderclient/tests/unit/v3/test_volumes.py @@ -94,6 +94,14 @@ class VolumesTest(utils.TestCase): cs.assert_called('POST', '/volumes', body=expected) self._assert_request_id(vol) + @ddt.data((False, '/volumes/summary'), + (True, '/volumes/summary?all_tenants=True')) + def test_volume_summary(self, all_tenants_input): + all_tenants, url = all_tenants_input + cs = fakes.FakeClient(api_versions.APIVersion('3.12')) + cs.volumes.summary(all_tenants=all_tenants) + cs.assert_called('GET', url) + def test_volume_list_manageable(self): cs = fakes.FakeClient(api_versions.APIVersion('3.8')) cs.volumes.list_manageable('host1', detailed=False) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index a389f09..9655e97 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -600,6 +600,27 @@ def do_metadata(cs, args): reverse=True)) +@api_versions.wraps('3.12') +@utils.arg('--all-tenants', + dest='all_tenants', + metavar='<0|1>', + nargs='?', + type=int, + const=1, + default=utils.env('ALL_TENANTS', default=0), + help='Shows details for all tenants. Admin only.') +def do_summary(cs, args): + """Get volumes summary.""" + all_tenants = args.all_tenants + info = cs.volumes.summary(all_tenants) + + formatters = ['total_size', 'total_count'] + if cs.api_version >= api_versions.APIVersion("3.36"): + formatters.append('metadata') + + utils.print_dict(info['volume-summary'], formatters=formatters) + + @api_versions.wraps('3.11') def do_group_type_list(cs, args): """Lists available 'group types'. (Admin only will see private types)""" diff --git a/cinderclient/v3/volumes.py b/cinderclient/v3/volumes.py index ebe4ed2..2e4eadc 100644 --- a/cinderclient/v3/volumes.py +++ b/cinderclient/v3/volumes.py @@ -124,6 +124,14 @@ class VolumeManager(volumes.VolumeManager): return self._action('revert', volume, info={'snapshot_id': base.getid(snapshot.id)}) + def summary(self, all_tenants): + """Get volumes summary.""" + url = "/volumes/summary" + if all_tenants: + url += "?all_tenants=True" + _, body = self.api.client.get(url) + return body + @api_versions.wraps("3.0") def delete_metadata(self, volume, keys): """Delete specified keys from volumes metadata. diff --git a/releasenotes/notes/support-volume-summary-d6d5bb2acfef6ad5.yaml b/releasenotes/notes/support-volume-summary-d6d5bb2acfef6ad5.yaml new file mode 100644 index 0000000..a9856e1 --- /dev/null +++ b/releasenotes/notes/support-volume-summary-d6d5bb2acfef6ad5.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Support get volume summary command in V3.12. |