summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ceilometerclient/v2/shell.py95
1 files changed, 63 insertions, 32 deletions
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index f5c6365..3bf4131 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -482,6 +482,11 @@ def common_alarm_arguments(create=False):
'name=<CONSTRAINT_NAME>;start=<CRON>;'
'duration=<SECONDS>;[description=<DESCRIPTION>;'
'[timezone=<IANA Timezone>]]'))
+ @utils.arg('--repeat-actions', dest='repeat_actions',
+ metavar='{True|False}', type=strutils.bool_from_string,
+ default=False,
+ help=('True if actions should be repeatedly notified '
+ 'while alarm remains in target state.'))
@functools.wraps(func)
def _wrapped(*args, **kwargs):
return func(*args, **kwargs)
@@ -509,11 +514,6 @@ def common_alarm_gnocchi_arguments(rule_namespace, create=False):
dest=rule_namespace + '/threshold',
required=create,
help='Threshold to evaluate against.')
- @utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- default=False,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@functools.wraps(func)
def _wrapped(*args, **kwargs):
return func(*args, **kwargs)
@@ -580,6 +580,22 @@ def common_alarm_gnocchi_resources_arguments(create=False):
return _wrapper
+def common_alarm_event_arguments():
+ def _wrapper(func):
+ @utils.arg('--event-type', dest='event_rule/event_type',
+ metavar='<EVENT_TYPE>',
+ help='Event type for event alarm.')
+ @utils.arg('-q', '--query', dest='event_rule/query', metavar='<QUERY>',
+ help=('key[op]data_type::value; list for filtering events. '
+ 'data_type is optional, but if supplied must be '
+ 'string, integer, float or datetime.'))
+ @functools.wraps(func)
+ def _wrapped(*args, **kwargs):
+ return func(*args, **kwargs)
+ return _wrapped
+ return _wrapper
+
+
@common_alarm_arguments(create=True)
@utils.arg('--period', type=int, metavar='<PERIOD>',
help='Length of each period (seconds) to evaluate over.')
@@ -598,11 +614,6 @@ def common_alarm_gnocchi_resources_arguments(create=False):
metavar='<Matching Metadata>', action='append', default=None,
help=('A meter should match this resource metadata (key=value) '
'additionally to the meter_name.'))
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- default=False,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_create(cc, args={}):
@@ -680,11 +691,6 @@ def do_alarm_gnocchi_aggregation_by_resources_threshold_create(cc, args={}):
dest='threshold_rule/query',
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float, or boolean.')
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- default=False,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_threshold_create(cc, args={}):
@@ -708,11 +714,6 @@ def do_alarm_threshold_create(cc, args={}):
dest='combination_rule/operator',
help='Operator to compare with, one of: ' + str(
ALARM_COMBINATION_OPERATORS) + '.')
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- default=False,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_combination_create(cc, args={}):
@@ -725,6 +726,23 @@ def do_alarm_combination_create(cc, args={}):
_display_alarm(alarm)
+@common_alarm_arguments(create=True)
+@common_alarm_event_arguments()
+@_restore_shadowed_arg('project_id', 'alarm_project_id')
+@_restore_shadowed_arg('user_id', 'alarm_user_id')
+def do_alarm_event_create(cc, args={}):
+ """Create a new alarm based on events."""
+ fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields['type'] = 'event'
+ fields['event_rule'] = fields.get('event_rule', {})
+ if 'query' in fields['event_rule']:
+ fields['event_rule']['query'] = options.cli_to_array(
+ fields['event_rule']['query'])
+ alarm = cc.alarms.create(**fields)
+ _display_alarm(alarm)
+
+
@utils.arg('-a', '--alarm_id', metavar='<ALARM_ID>',
action=obsoleted_by('alarm_id'), help=argparse.SUPPRESS,
dest='alarm_id_deprecated')
@@ -752,10 +770,6 @@ def do_alarm_combination_create(cc, args={}):
metavar='<Matching Metadata>', action='append', default=None,
help=('A meter should match this resource metadata (key=value) '
'additionally to the meter_name.'))
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_update(cc, args={}):
@@ -805,10 +819,6 @@ def do_alarm_update(cc, args={}):
dest='threshold_rule/query',
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float, or boolean.')
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_threshold_update(cc, args={}):
@@ -925,10 +935,6 @@ def do_alarm_gnocchi_aggregation_by_resources_threshold_update(cc, args={}):
dest='combination_rule/operator',
help='Operator to compare with, one of: ' + str(
ALARM_COMBINATION_OPERATORS) + '.')
-@utils.arg('--repeat-actions', dest='repeat_actions',
- metavar='{True|False}', type=strutils.bool_from_string,
- help=('True if actions should be repeatedly notified '
- 'while alarm remains in target state.'))
@_restore_shadowed_arg('project_id', 'alarm_project_id')
@_restore_shadowed_arg('user_id', 'alarm_user_id')
def do_alarm_combination_update(cc, args={}):
@@ -949,6 +955,31 @@ def do_alarm_combination_update(cc, args={}):
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()
+@common_alarm_event_arguments()
+@_restore_shadowed_arg('project_id', 'alarm_project_id')
+@_restore_shadowed_arg('user_id', 'alarm_user_id')
+def do_alarm_event_update(cc, args={}):
+ """Update an existing alarm based on events."""
+ fields = dict(filter(lambda x: x[1] is not None, vars(args).items()))
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields.pop('alarm_id')
+ fields['type'] = 'event'
+ if fields.get('event_rule') and 'query' in fields['event_rule']:
+ fields['event_rule']['query'] = options.cli_to_array(
+ fields['event_rule']['query'])
+ try:
+ alarm = cc.alarms.update(args.alarm_id, **fields)
+ except exc.HTTPNotFound:
+ raise exc.CommandError('Alarm not found: %s' % args.alarm_id)
+ _display_alarm(alarm)
+
+
+@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."""