Add command to show pool information for backends

An admin-api extension to show pool info was supported at commit
https://review.openstack.org/#/c/119938/.

This change adds a command to show pool information for backends
using the admin-api. This change also closes the gap for end users.

Partial-Bug: 1403902
Change-Id: I20e0828c5403b73bc44d07eebf08e2aa2deb428a
This commit is contained in:
Mitsuhiro Tanino 2015-01-02 16:25:17 -05:00
parent 59177814a4
commit 1d38426680
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

@ -550,3 +550,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

@ -1948,3 +1948,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)