Support volume summary command

This patch added volume summary command support.

Change-Id: I7cf6e149b9ce9cae21818c60146e6db9cc2904bd
This commit is contained in:
wangxiyuan
2017-06-15 09:39:50 +08:00
parent 6a00d30e96
commit a570f26d97
6 changed files with 54 additions and 0 deletions

View File

@@ -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
#

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)"""

View File

@@ -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.

View File

@@ -0,0 +1,4 @@
---
features:
- |
Support get volume summary command in V3.12.