Merge "Added offset and limit for list based commands"
This commit is contained in:
commit
abb0d40c44
@ -84,6 +84,8 @@ class AlarmsManager(monasca_manager.MonascaManager):
|
||||
newheaders = self.get_headers()
|
||||
url_str = self.base_url + '/%s/state-history' % kwargs['alarm_id']
|
||||
del kwargs['alarm_id']
|
||||
if kwargs:
|
||||
url_str = url_str + '?%s' % urlutils.urlencode(kwargs, True)
|
||||
resp, body = self.client.json_request('GET', url_str,
|
||||
headers=newheaders)
|
||||
return body['elements'] if type(body) is dict else body
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from monascaclient.common import monasca_manager
|
||||
from monascaclient.openstack.common.apiclient import base
|
||||
from monascaclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
|
||||
class Notifications(base.Resource):
|
||||
@ -43,11 +44,15 @@ class NotificationsManager(monasca_manager.MonascaManager):
|
||||
headers=newheaders)
|
||||
return body
|
||||
|
||||
def list(self):
|
||||
def list(self, **kwargs):
|
||||
"""Get a list of notifications."""
|
||||
newheaders = self.get_headers()
|
||||
resp, body = self.client.json_request(
|
||||
'GET', self.base_url, headers=newheaders)
|
||||
url_str = self.base_url
|
||||
if kwargs:
|
||||
url_str = url_str + '?%s' % urlutils.urlencode(kwargs, True)
|
||||
|
||||
resp, body = self.client.json_request('GET', url_str,
|
||||
headers=newheaders)
|
||||
return body['elements'] if type(body) is dict else body
|
||||
|
||||
def delete(self, **kwargs):
|
||||
|
@ -105,6 +105,10 @@ def do_metric_create_raw(mc, args):
|
||||
'Dimensions need quoting when they contain special chars [&,(,),{,},>,<] '
|
||||
'that confuse the CLI parser.',
|
||||
action='append')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_metric_list(mc, args):
|
||||
'''List metrics for this tenant.'''
|
||||
fields = {}
|
||||
@ -112,6 +116,11 @@ def do_metric_list(mc, args):
|
||||
fields['name'] = args.name
|
||||
if args.dimensions:
|
||||
fields['dimensions'] = utils.format_parameters(args.dimensions)
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
|
||||
try:
|
||||
metric = mc.metrics.list(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -254,6 +263,10 @@ def format_metric_dimensions(metrics):
|
||||
help='measurements >= UTC time. format: 2014-01-01T00:00:00Z.')
|
||||
@utils.arg('--endtime', metavar='<UTC_END_TIME>',
|
||||
help='measurements <= UTC time. format: 2014-01-01T00:00:00Z.')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_measurement_list(mc, args):
|
||||
'''List measurements for the specified metric.'''
|
||||
fields = {}
|
||||
@ -264,6 +277,11 @@ def do_measurement_list(mc, args):
|
||||
fields['start_time'] = args.starttime
|
||||
if args.endtime:
|
||||
fields['end_time'] = args.endtime
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
|
||||
try:
|
||||
metric = mc.metrics.list_measurements(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -315,6 +333,10 @@ def do_measurement_list(mc, args):
|
||||
help='measurements <= UTC time. format: 2014-01-01T00:00:00Z.')
|
||||
@utils.arg('--period', metavar='<PERIOD>',
|
||||
help='number of seconds per interval (default is 300)')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_metric_statistics(mc, args):
|
||||
'''List measurement statistics for the specified metric.'''
|
||||
statistic_types = ['AVG', 'MIN', 'MAX', 'COUNT', 'SUM']
|
||||
@ -335,6 +357,11 @@ def do_metric_statistics(mc, args):
|
||||
if args.period:
|
||||
fields['period'] = args.period
|
||||
fields['statistics'] = args.statistics
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
|
||||
try:
|
||||
metric = mc.metrics.list_statistics(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -439,10 +466,20 @@ def do_notification_show(mc, args):
|
||||
utils.print_dict(notification, formatters=formatters)
|
||||
|
||||
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_notification_list(mc, args):
|
||||
'''List notifications for this tenant.'''
|
||||
fields = {}
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
|
||||
try:
|
||||
notification = mc.notifications.list()
|
||||
notification = mc.notifications.list(**fields)
|
||||
except exc.HTTPException as he:
|
||||
raise exc.CommandError(
|
||||
'HTTPException code=%s message=%s' %
|
||||
@ -617,6 +654,10 @@ def do_alarm_definition_show(mc, args):
|
||||
'Dimensions need quoting when they contain special chars [&,(,),{,},>,<] '
|
||||
'that confuse the CLI parser.',
|
||||
action='append')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_alarm_definition_list(mc, args):
|
||||
'''List alarm definitions for this tenant.'''
|
||||
fields = {}
|
||||
@ -624,6 +665,10 @@ def do_alarm_definition_list(mc, args):
|
||||
fields['name'] = args.name
|
||||
if args.dimensions:
|
||||
fields['dimensions'] = utils.format_parameters(args.dimensions)
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
try:
|
||||
alarm = mc.alarm_definitions.list(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -814,6 +859,10 @@ def do_alarm_definition_patch(mc, args):
|
||||
action='append')
|
||||
@utils.arg('--state', metavar='<ALARM_STATE>',
|
||||
help='ALARM_STATE is one of [UNDETERMINED, OK, ALARM].')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_alarm_list(mc, args):
|
||||
'''List alarms for this tenant.'''
|
||||
fields = {}
|
||||
@ -830,6 +879,10 @@ def do_alarm_list(mc, args):
|
||||
print(errmsg)
|
||||
return
|
||||
fields['state'] = args.state
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
try:
|
||||
alarm = mc.alarms.list(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -980,10 +1033,18 @@ def output_alarm_history(args, alarm_history):
|
||||
|
||||
@utils.arg('id', metavar='<ALARM_ID>',
|
||||
help='The ID of the alarm.')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_alarm_history(mc, args):
|
||||
'''Alarm state transition history.'''
|
||||
fields = {}
|
||||
fields['alarm_id'] = args.id
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
try:
|
||||
alarm = mc.alarms.history(**fields)
|
||||
except exc.HTTPException as he:
|
||||
@ -1005,6 +1066,10 @@ def do_alarm_history(mc, args):
|
||||
help='measurements >= UTC time. format: 2014-01-01T00:00:00Z.')
|
||||
@utils.arg('--endtime', metavar='<UTC_END_TIME>',
|
||||
help='measurements <= UTC time. format: 2014-01-01T00:00:00Z.')
|
||||
@utils.arg('--offset', metavar='<OFFSET LOCATION>',
|
||||
help='The offset used to paginate the return data.')
|
||||
@utils.arg('--limit', metavar='<RETURN LIMIT>',
|
||||
help='The amount of data to be returned up to the API maximum limit.')
|
||||
def do_alarm_history_list(mc, args):
|
||||
'''List alarms state history.'''
|
||||
fields = {}
|
||||
@ -1014,6 +1079,10 @@ def do_alarm_history_list(mc, args):
|
||||
fields['start_time'] = args.starttime
|
||||
if args.endtime:
|
||||
fields['end_time'] = args.endtime
|
||||
if args.limit:
|
||||
fields['limit'] = args.limit
|
||||
if args.offset:
|
||||
fields['offset'] = args.offset
|
||||
try:
|
||||
alarm = mc.alarms.history_list(**fields)
|
||||
except exc.HTTPException as he:
|
||||
|
Loading…
Reference in New Issue
Block a user