Merge "Add command to show pool information for backends"

This commit is contained in:
Jenkins 2015-01-13 08:38:06 +00:00 committed by Gerrit Code Review
commit fdf6fd1d67
5 changed files with 56 additions and 0 deletions

View File

@ -954,3 +954,13 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_os_reenable_replica_1234(self, **kw):
return (202, {}, {})
def get_scheduler_stats_get_pools(self, **kw):
return (200, {}, {
"pools": [
{"name": "test1@backend1#pool",
"capabilities": {
"pool_name": "pool",
"volume_backend_name": "backend",
"storage_protocol": "iSCSI"}}]
})

View File

@ -569,3 +569,11 @@ class ShellTest(utils.TestCase):
'k2': 'v2'}}}
self.run_command('snapshot-create 1234 --metadata k1=v1 k2=v2')
self.assert_called_anytime('POST', '/snapshots', partial_body=expected)
def test_get_pools(self):
self.run_command('get-pools')
self.assert_called('GET', '/scheduler-stats/get_pools')
def test_get_pools_detail(self):
self.run_command('get-pools --detail')
self.assert_called('GET', '/scheduler-stats/get_pools?detail=True')

View File

@ -215,3 +215,11 @@ class VolumesTest(utils.TestCase):
cs.volumes.reenable(v)
cs.assert_called('POST', '/volumes/1234/action',
{'os-reenable-replica': None})
def test_get_pools(self):
cs.volumes.get_pools('')
cs.assert_called('GET', '/scheduler-stats/get_pools')
def test_get_pools_detail(self):
cs.volumes.get_pools('--detail')
cs.assert_called('GET', '/scheduler-stats/get_pools?detail=True')

View File

@ -1952,3 +1952,21 @@ def do_cgsnapshot_delete(cs, args):
if failure_count == len(args.cgsnapshot):
raise exceptions.CommandError("Unable to delete any of specified "
"cgsnapshots.")
@utils.arg('--detail',
action='store_true',
help='Show detailed information about pools.')
@utils.service_type('volumev2')
def do_get_pools(cs, args):
"""Show pool information for backends. Admin only."""
pools = cs.volumes.get_pools(args.detail)
infos = dict()
infos.update(pools._info)
for info in infos['pools']:
backend = dict()
backend['name'] = info['name']
if args.detail:
backend.update(info['capabilities'])
utils.print_dict(backend)

View File

@ -160,6 +160,10 @@ class Volume(base.Resource):
"""Sync the secondary volume with primary for a relationship."""
self.manager.reenable(volume)
def get_pools(self, detail):
"""Show pool information for backends."""
self.manager.get_pools(detail)
class VolumeManager(base.ManagerWithFind):
"""Manage :class:`Volume` resources."""
@ -519,3 +523,11 @@ class VolumeManager(base.ManagerWithFind):
def reenable(self, volume):
"""Sync the secondary volume with primary for a relationship."""
return self._action('os-reenable-replica', volume, None)
def get_pools(self, detail):
"""Show pool information for backends."""
query_string = ""
if detail:
query_string = "?detail=True"
return self._get('/scheduler-stats/get_pools%s' % query_string, None)