Supported resources list cli support

Currently there is no other way of getting list of supported
resource type than looking directly in the source codes.

This change set implements the CLI command 'resource list-types'
to list the resource type Gnocchi supports.

Change-Id: Id22209d8c515c2a97f8abf77380c656e2a52e088
Co-Authored-By: xialinjuan(ljxiash@cn.ibm.com)
Closes-bug: 1510024
This commit is contained in:
jizilian 2016-01-05 02:09:39 -05:00 committed by Zi Lian Ji
parent d114f98f0c
commit a261b4a28a
4 changed files with 33 additions and 0 deletions

View File

@ -45,6 +45,7 @@ class GnocchiCommandManager(commandmanager.CommandManager):
"resource create": resource_cli.CliResourceCreate,
"resource update": resource_cli.CliResourceUpdate,
"resource delete": resource_cli.CliResourceDelete,
"resource list-types": resource_cli.CliResourceTypeList,
"archive-policy list": archive_policy_cli.CliArchivePolicyList,
"archive-policy show": archive_policy_cli.CliArchivePolicyShow,
"archive-policy create": archive_policy_cli.CliArchivePolicyCreate,

View File

@ -173,3 +173,14 @@ class ResourceClientTest(base.ClientTestBase):
resource_ids = [r['id'] for r in self.parser.listing(result)]
self.assertNotIn(self.RESOURCE_ID, resource_ids)
self.assertNotIn(self.RESOURCE_ID2, resource_ids)
# LIST THE RESOUCES TYPES
resource_type = ('instance', 'generic', 'volume',
'instance_disk', 'stack', 'identity')
result = self.gnocchi(
'resource', params="list-types")
result_list = self.parser.listing(result)
type_from_list = [t['resource_type'] for t in result_list]
for one_type in resource_type:
self.assertIn(one_type, type_from_list)

View File

@ -168,3 +168,13 @@ class ResourceManager(base.Manager):
return self._post(
url, headers={'Content-Type': "application/json"},
data=jsonutils.dumps(query)).json()
def list_types(self):
"""List the resource types supported by gnocchi"""
# (Note/jzl)Based on the discussion result, keep the keyword
# 'resource-type' and use the command 'resource list-types' to
# list the types supported by gnocchi.
# Opened a reminding bug to me to handle with it,
# when resource-type is ready
# https://bugs.launchpad.net/python-gnocchiclient/+bug/1535176
return self._get(self.url).json()

View File

@ -211,3 +211,14 @@ class CliResourceDelete(command.Command):
def take_action(self, parsed_args):
self.app.client.resource.delete(parsed_args.resource_id)
class CliResourceTypeList(lister.Lister):
"""List the resource types that gnocchi supports"""
COLS = ('resource_type',
'resource_controller_url')
def take_action(self, parsed_args):
resources = self.app.client.resource.list_types()
return self.COLS, list(resources.items())