summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Abaakouk <mehdi.abaakouk@enovance.com>2015-01-22 10:22:32 +0100
committerMehdi Abaakouk <mehdi.abaakouk@enovance.com>2015-02-06 10:01:25 +0100
commita20cece111629c849aeb1812bb00a32fc501c020 (patch)
tree61f31c998e3c2dfd2cb5e968418aff5d2b7cb74d
parenta51d3f469b409d882842b07badf552182d271b79 (diff)
downloadpython-ceilometerclient-a20cece111629c849aeb1812bb00a32fc501c020.tar.gz
Allow create/update gnocchi alarm rule
Change-Id: Id1c6832c2db32c5cce0e31cd0022a86508630a7e
-rw-r--r--ceilometerclient/v2/shell.py146
1 files changed, 146 insertions, 0 deletions
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index 95a137f..878794e 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -406,6 +406,73 @@ def common_alarm_arguments(create=False):
return _wrapper
+def common_alarm_gnocchi_arguments(rule_namespace, create=False):
+ def _wrapper(func):
+ @utils.arg('--granularity', type=int, metavar='<GRANULARITY>',
+ dest=rule_namespace + '/granularity',
+ help='Length of each period (seconds) to evaluate over.')
+ @utils.arg('--evaluation-periods', type=int, metavar='<COUNT>',
+ dest=rule_namespace + '/evaluation_periods',
+ help='Number of periods to evaluate over.')
+ @utils.arg('--aggregation-method', metavar='<AGGREATION>',
+ dest=rule_namespace + '/aggregation_method',
+ help=('Aggregation method to use, one of: ' +
+ str(STATISTICS) + '.'))
+ @utils.arg('--comparison-operator', metavar='<OPERATOR>',
+ dest=rule_namespace + '/comparison_operator',
+ help=('Operator to compare with, one of: ' +
+ str(ALARM_OPERATORS) + '.'))
+ @utils.arg('--threshold', type=float, metavar='<THRESHOLD>',
+ 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)
+ return _wrapped
+ return _wrapper
+
+
+def common_alarm_gnocchi_metrics_arguments(create=False):
+ def _wrapper(func):
+ @utils.arg('-m', '--metrics', metavar='<METRICS>',
+ dest='gnocchi_metrics_threshold_rule/meter_name',
+ action='append', required=create,
+ help='Metric to evaluate against.')
+ @functools.wraps(func)
+ def _wrapped(*args, **kwargs):
+ return func(*args, **kwargs)
+ return _wrapped
+ return _wrapper
+
+
+def common_alarm_gnocchi_resources_arguments(create=False):
+ def _wrapper(func):
+ @utils.arg('-m', '--metric', metavar='<METRIC>',
+ dest='gnocchi_resources_threshold_rule/metric',
+ required=create,
+ help='Metric to evaluate against.')
+ @utils.arg('--resource-type', metavar='<RESOURCE_TYPE>',
+ dest='gnocchi_resources_threshold_rule/resource_type',
+ required=create,
+ help='Resource_type to evaluate against.')
+ @utils.arg('--resource-constraint', metavar='<RESOURCE_CONSTRAINT>',
+ dest='gnocchi_resources_threshold_rule/resource_constraint',
+ required=create,
+ help=('Resources to evaluate against or a expression '
+ 'to select multiple resources.'))
+ @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.')
@@ -439,6 +506,33 @@ def do_alarm_create(cc, args={}):
@common_alarm_arguments(create=True)
+@common_alarm_gnocchi_arguments('gnocchi_resources_threshold_rule',
+ create=True)
+@common_alarm_gnocchi_resources_arguments(create=True)
+def do_alarm_gnocchi_resources_threshold_create(cc, args={}):
+ """Create a new alarm based on computed statistics."""
+ fields = dict(filter(lambda x: not (x[1] is None), vars(args).items()))
+ fields = utils.args_array_to_list_of_dicts(fields, 'time_constraints')
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields['type'] = 'gnocchi_resources_threshold'
+ alarm = cc.alarms.create(**fields)
+ _display_alarm(alarm)
+
+
+@common_alarm_arguments(create=True)
+@common_alarm_gnocchi_arguments('gnocchi_metrics_threshold_rule', create=True)
+@common_alarm_gnocchi_metrics_arguments(create=True)
+def do_alarm_gnocchi_metrics_threshold_create(cc, args={}):
+ """Create a new alarm based on computed statistics."""
+ fields = dict(filter(lambda x: not (x[1] is None), vars(args).items()))
+ fields = utils.args_array_to_list_of_dicts(fields, 'time_constraints')
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields['type'] = 'gnocchi_metrics_threshold'
+ alarm = cc.alarms.create(**fields)
+ _display_alarm(alarm)
+
+
+@common_alarm_arguments(create=True)
@utils.arg('-m', '--meter-name', metavar='<METRIC>', required=True,
dest='threshold_rule/meter_name',
help='Metric to evaluate against.')
@@ -608,6 +702,58 @@ def do_alarm_threshold_update(cc, args={}):
@utils.arg('alarm_id', metavar='<ALARM_ID>', nargs='?',
action=NotEmptyAction, help='ID of the alarm to update.')
@common_alarm_arguments()
+@common_alarm_gnocchi_arguments('gnocchi_resources_threshold')
+@common_alarm_gnocchi_resources_arguments()
+@utils.arg('--remove-time-constraint', action='append',
+ metavar='<Constraint names>',
+ dest='remove_time_constraints',
+ help='Name or list of names of the time constraints to remove.')
+def do_alarm_gnocchi_resources_threshold_update(cc, args={}):
+ """Update an existing alarm based on computed statistics."""
+ fields = dict(filter(lambda x: not (x[1] is None), vars(args).items()))
+ fields = utils.args_array_to_list_of_dicts(fields, 'time_constraints')
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields.pop('alarm_id')
+ fields['type'] = 'gnocchi_resources_threshold'
+ 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 update.')
+@common_alarm_arguments()
+@common_alarm_gnocchi_arguments('gnocchi_metrics_threshold')
+@common_alarm_gnocchi_metrics_arguments()
+@utils.arg('--remove-time-constraint', action='append',
+ metavar='<Constraint names>',
+ dest='remove_time_constraints',
+ help='Name or list of names of the time constraints to remove.')
+def do_alarm_gnocchi_metrics_threshold_update(cc, args={}):
+ """Update an existing alarm based on computed statistics."""
+ fields = dict(filter(lambda x: not (x[1] is None), vars(args).items()))
+ fields = utils.args_array_to_list_of_dicts(fields, 'time_constraints')
+ fields = utils.key_with_slash_to_nested_dict(fields)
+ fields.pop('alarm_id')
+ fields['type'] = 'gnocchi_metrics_threshold'
+ 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 update.')
+@common_alarm_arguments()
@utils.arg('--remove-time-constraint', action='append',
metavar='<Constraint names>',
dest='remove_time_constraints',