diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index 18dc30588..e224c3cfd 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -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"}}] + }) diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index aa03844cc..342c9aa66 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -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') diff --git a/cinderclient/tests/v2/test_volumes.py b/cinderclient/tests/v2/test_volumes.py index beda5fa3e..2ad289d80 100644 --- a/cinderclient/tests/v2/test_volumes.py +++ b/cinderclient/tests/v2/test_volumes.py @@ -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') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index b52894776..3c07b6880 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -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) diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index 59853adb7..7fc126755 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -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)