client support for resource api changes
- added support for query in resource list - changed call to resource list from GET to POST - added support for resource count new api Story: 2004669 Task: 28652 Task: 28655 Depends-On: https://review.openstack.org/627309 Change-Id: Ib75b67c15c0a175e804fd020958fb7e50ec4df07
This commit is contained in:
parent
8ce7631592
commit
3deddd8ce6
@ -165,6 +165,7 @@ You'll find complete documentation on the shell by running
|
||||
healthcheck Check api health status
|
||||
help print detailed help for another command (cliff)
|
||||
rca show Show the Root Cause Analysis for a certain alarm
|
||||
resource count Show a count of all resources
|
||||
resource list List resources
|
||||
resource show Show a resource
|
||||
template add Add a template
|
||||
@ -718,6 +719,27 @@ resource show::
|
||||
| vitrage_type | nova.instance |
|
||||
+---------------------------+--------------------------------------+
|
||||
|
||||
resource count::
|
||||
|
||||
vitrage resource count
|
||||
{
|
||||
"nova.instance": 394,
|
||||
"openstack.cluster": 1,
|
||||
"cinder.volume": 405,
|
||||
"nova.host": 16,
|
||||
"neutron.network": 7,
|
||||
"neutron.port": 1127,
|
||||
"nova.zone": 3,
|
||||
"tripleo.controller": 3
|
||||
}
|
||||
|
||||
vitrage resource count --type nova.instance --group-by state
|
||||
{
|
||||
"ACTIVE": 359,
|
||||
"ERROR": 27,
|
||||
"SUBOPTIMAL": 8
|
||||
}
|
||||
|
||||
Alarms Examples
|
||||
---------------
|
||||
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
||||
|
4
releasenotes/notes/resource_count-52fc0ec86b983197.yaml
Normal file
4
releasenotes/notes/resource_count-52fc0ec86b983197.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Resource count new API with support for queries and group-by.
|
||||
Allows retrieving quick summaries of graph nodes.
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Resource list API now supports using a query
|
@ -49,6 +49,7 @@ openstack.rca.v1 =
|
||||
rca_alarm_count = vitrageclient.v1.cli.alarm:AlarmCount
|
||||
rca_resource_list = vitrageclient.v1.cli.resource:ResourceList
|
||||
rca_resource_show = vitrageclient.v1.cli.resource:ResourceShow
|
||||
rca_resource_count = vitrageclient.v1.cli.resource:ResourceCount
|
||||
rca_template_list = vitrageclient.v1.cli.template:TemplateList
|
||||
rca_template_show = vitrageclient.v1.cli.template:TemplateShow
|
||||
rca_template_validate = vitrageclient.v1.cli.template:TemplateValidate
|
||||
|
@ -19,7 +19,8 @@ _vitrage()
|
||||
cmds_rca='show'
|
||||
cmds_rca_show='-h --help -f --format -c --column --max-width --fit-width --print-empty --noindent --variable --prefix --all-tenants'
|
||||
cmds_resource='list show'
|
||||
cmds_resource_list='-h --help -f --format -c --column --max-width --fit-width --print-empty --quote --noindent --sort-column --type --all-tenants'
|
||||
cmds_resource_count='-h --help --type --all-tenants --filter --group-by'
|
||||
cmds_resource_list='-h --help -f --format -c --column --max-width --fit-width --print-empty --quote --noindent --sort-column --type --all-tenants --filter'
|
||||
cmds_resource_show='-h --help -f --format -c --column --max-width --fit-width --print-empty --noindent --variable --prefix'
|
||||
cmds_template='add delete list show validate'
|
||||
cmds_template_add='-h --help -f --format -c --column --max-width --fit-width --print-empty --quote --noindent --sort-column --path --type'
|
||||
|
@ -51,6 +51,7 @@ class VitrageCommandManager(commandmanager.CommandManager):
|
||||
'topology show': topology.TopologyShow,
|
||||
'resource show': resource.ResourceShow,
|
||||
'resource list': resource.ResourceList,
|
||||
'resource count': resource.ResourceCount,
|
||||
'alarm list': alarm.AlarmList,
|
||||
'alarm history': alarm.AlarmHistory,
|
||||
'alarm show': alarm.AlarmShow,
|
||||
|
@ -47,15 +47,20 @@ class ResourceList(lister.Lister):
|
||||
dest='all_tenants',
|
||||
action='store_true',
|
||||
help='Shows resources of all the tenants')
|
||||
parser.add_argument('--filter',
|
||||
metavar='<query>',
|
||||
help='resource query')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resource_type = parsed_args.resource_type
|
||||
all_tenants = parsed_args.all_tenants
|
||||
query = parsed_args.filter
|
||||
resources = utils.get_client(self).resource.list(
|
||||
resource_type=resource_type,
|
||||
all_tenants=all_tenants)
|
||||
all_tenants=all_tenants,
|
||||
query=query)
|
||||
# cluster, zone and host don't have "project_id" property
|
||||
# neutron.port don't have "name" property
|
||||
# cluster don't have "update_timestamp"
|
||||
@ -72,3 +77,46 @@ class ResourceList(lister.Lister):
|
||||
('State', 'vitrage_operational_state'),
|
||||
('Metadata', 'metadata'),
|
||||
), resources)
|
||||
|
||||
|
||||
class ResourceCount(show.ShowOne):
|
||||
"""Show a count of all resources"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ResourceCount, self).get_parser(prog_name)
|
||||
parser.add_argument('--type',
|
||||
dest='resource_type',
|
||||
metavar='<resource type>',
|
||||
help='Type of resource')
|
||||
parser.add_argument('--all-tenants',
|
||||
default=False,
|
||||
dest='all_tenants',
|
||||
action='store_true',
|
||||
help='Shows resources of all the tenants')
|
||||
parser.add_argument('--filter',
|
||||
metavar='<query>',
|
||||
help='resource query'),
|
||||
parser.add_argument(
|
||||
'--group-by',
|
||||
dest='group_by',
|
||||
metavar='<group_by>',
|
||||
default='vitrage_type',
|
||||
help='A resource data field, to group by it\'s values'),
|
||||
return parser
|
||||
|
||||
@property
|
||||
def formatter_default(self):
|
||||
return 'json'
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resource_type = parsed_args.resource_type
|
||||
all_tenants = parsed_args.all_tenants
|
||||
query = parsed_args.filter
|
||||
group_by = parsed_args.group_by
|
||||
resource_count = utils.get_client(self).resource.count(
|
||||
resource_type=resource_type,
|
||||
all_tenants=all_tenants,
|
||||
query=query,
|
||||
group_by=group_by)
|
||||
|
||||
return self.dict2columns(resource_count)
|
||||
|
@ -17,15 +17,16 @@ class Resource(object):
|
||||
def __init__(self, api):
|
||||
self.api = api
|
||||
|
||||
def list(self, resource_type=None, all_tenants=False):
|
||||
def list(self, resource_type=None, all_tenants=False, query=None):
|
||||
"""Get a all resources
|
||||
|
||||
:param all_tenants: should return all tenants resources
|
||||
:param resource_type: the type for the resources
|
||||
:param query: the query filter for the vertices
|
||||
"""
|
||||
params = dict(resource_type=resource_type,
|
||||
all_tenants=all_tenants)
|
||||
return self.api.get(self.url, params=params).json()
|
||||
params = dict(resource_type=resource_type, all_tenants=all_tenants,
|
||||
query=query)
|
||||
return self.api.post(self.url, json=params).json()
|
||||
|
||||
def get(self, vitrage_id):
|
||||
"""Get a resource
|
||||
@ -34,3 +35,16 @@ class Resource(object):
|
||||
"""
|
||||
url = self.url + vitrage_id
|
||||
return self.api.get(url).json()
|
||||
|
||||
def count(self, resource_type=None, all_tenants=False, query=None,
|
||||
group_by=None):
|
||||
"""Get a count of all resources
|
||||
|
||||
:param all_tenants: should return all tenants resources
|
||||
:param resource_type: the type for the resources
|
||||
:param query: the query filter for the vertices
|
||||
:param group_by: a property name to group by it's values
|
||||
"""
|
||||
params = dict(resource_type=resource_type, all_tenants=all_tenants,
|
||||
query=query, group_by=group_by)
|
||||
return self.api.post(self.url + 'count/', json=params).json()
|
||||
|
Loading…
Reference in New Issue
Block a user