diff options
Diffstat (limited to 'ceilometerclient/v2/shell.py')
-rw-r--r-- | ceilometerclient/v2/shell.py | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 72f780d..ce586e8 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -51,11 +51,21 @@ SIMPLE_OPERATORS = ["=", "!=", "<", "<=", '>', '>='] class NotEmptyAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): + values = values or getattr(namespace, self.dest) if not values or values.isspace(): raise exc.CommandError('%s should not be empty' % self.dest) setattr(namespace, self.dest, values) +def obsoleted_by(new_dest): + class ObsoletedByAction(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + old_dest = option_string or self.dest + print('%s is obsolete! See help for more details.' % old_dest) + setattr(namespace, new_dest, values) + return ObsoletedByAction + + @utils.arg('-q', '--query', metavar='<QUERY>', help='key[op]data_type::value; list. data_type is optional, ' 'but if supplied must be string, integer, float, or boolean.') @@ -333,7 +343,10 @@ def _display_alarm(alarm): utils.print_dict(data, wrap=72) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm to show.') def do_alarm_show(cc, args={}): '''Show an alarm.''' @@ -490,7 +503,10 @@ def do_alarm_combination_create(cc, args={}): _display_alarm(alarm) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm to update.') @common_alarm_arguments() @utils.arg('--remove-time-constraint', action='append', @@ -531,7 +547,10 @@ def do_alarm_update(cc, args={}): _display_alarm(alarm) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm to update.') @common_alarm_arguments() @utils.arg('--remove-time-constraint', action='append', @@ -583,7 +602,10 @@ def do_alarm_threshold_update(cc, args={}): _display_alarm(alarm) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm to update.') @common_alarm_arguments() @utils.arg('--remove-time-constraint', action='append', @@ -615,7 +637,10 @@ def do_alarm_combination_update(cc, args={}): _display_alarm(alarm) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm to delete.') def do_alarm_delete(cc, args={}): '''Delete an alarm.''' @@ -625,7 +650,10 @@ def do_alarm_delete(cc, args={}): raise exc.CommandError('Alarm not found: %s' % args.alarm_id) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm state to set.') @utils.arg('--state', metavar='<STATE>', required=True, help='State of the alarm, one of: ' + str(ALARM_STATES) + @@ -639,7 +667,10 @@ def do_alarm_state_set(cc, args={}): utils.print_dict({'state': state}, wrap=72) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm state to show.') def do_alarm_state_get(cc, args={}): '''Get the state of an alarm.''' @@ -650,8 +681,10 @@ def do_alarm_state_get(cc, args={}): utils.print_dict({'state': state}, wrap=72) -@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', required=True, - action=NotEmptyAction, +@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>', + action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS, + dest='alarm_id_deprecated') +@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?', action=NotEmptyAction, help='ID of the alarm for which history is shown.') @utils.arg('-q', '--query', metavar='<QUERY>', help='key[op]data_type::value; list. data_type is optional, ' @@ -688,7 +721,7 @@ def do_resource_list(cc, args={}): sortby=1) -@utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>', required=True, +@utils.arg('resource_id', metavar='<RESOURCE_ID>', action=NotEmptyAction, help='ID of the resource to show.') def do_resource_show(cc, args={}): '''Show the resource.''' @@ -719,9 +752,8 @@ def do_event_list(cc, args={}): )}) -@utils.arg('-m', '--message_id', metavar='<message_id>', - help='The ID of the event. Should be a UUID.', - required=True, action=NotEmptyAction) +@utils.arg('message_id', metavar='<message_id>', action=NotEmptyAction, + help='The ID of the event. Should be a UUID.') def do_event_show(cc, args={}): '''Show a particular event.''' event = cc.events.get(args.message_id) |