diff options
-rw-r--r-- | ceilometerclient/client.py | 2 | ||||
-rw-r--r-- | ceilometerclient/shell.py | 4 | ||||
-rw-r--r-- | ceilometerclient/tests/test_shell.py | 5 | ||||
-rw-r--r-- | ceilometerclient/v2/shell.py | 97 | ||||
-rw-r--r-- | doc/ext/gen_ref.py | 5 | ||||
-rw-r--r-- | doc/source/index.rst | 1 |
6 files changed, 92 insertions, 22 deletions
diff --git a/ceilometerclient/client.py b/ceilometerclient/client.py index c0a8be5..46cd66f 100644 --- a/ceilometerclient/client.py +++ b/ceilometerclient/client.py @@ -256,7 +256,9 @@ def get_client(version, **kwargs): * ceilometer_url: (DEPRECATED) Ceilometer API endpoint, use os_endpoint instead * os_endpoint: Ceilometer API endpoint + or: + * os_username: name of user * os_password: user's password * os_user_id: user's id diff --git a/ceilometerclient/shell.py b/ceilometerclient/shell.py index 8057933..10a43d5 100644 --- a/ceilometerclient/shell.py +++ b/ceilometerclient/shell.py @@ -46,6 +46,9 @@ def _positive_non_zero_int(argument_value): class CeilometerShell(object): + def __init__(self): + self.auth_plugin = ceiloclient.AuthPlugin() + def get_base_parser(self): parser = argparse.ArgumentParser( prog='ceilometer', @@ -158,7 +161,6 @@ class CeilometerShell(object): def parse_args(self, argv): # Parse args once to find version - self.auth_plugin = ceiloclient.AuthPlugin() parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self.auth_plugin.parse_opts(options) diff --git a/ceilometerclient/tests/test_shell.py b/ceilometerclient/tests/test_shell.py index 6d6403b..c3a138e 100644 --- a/ceilometerclient/tests/test_shell.py +++ b/ceilometerclient/tests/test_shell.py @@ -92,6 +92,11 @@ class ShellHelpTest(ShellTestBase): self.assertThat(help_text, matchers.MatchesRegex(r, self.RE_OPTIONS)) + def test_get_base_parser(self): + standalone_shell = ceilometer_shell.CeilometerShell() + parser = standalone_shell.get_base_parser() + self.assertEqual(600, parser.get_default('timeout')) + class ShellKeystoneV2Test(ShellTestBase): diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 67a7646..f1ecf02 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -477,10 +477,11 @@ def common_alarm_gnocchi_arguments(rule_namespace, create=False): return _wrapper -def common_alarm_gnocchi_metrics_arguments(create=False): +def common_alarm_gnocchi_aggregation_by_metrics_arguments(create=False): def _wrapper(func): @utils.arg('-m', '--metrics', metavar='<METRICS>', - dest='gnocchi_metrics_threshold_rule/meter_name', + dest=('gnocchi_aggregation_by_metrics_threshold_rule/' + 'meter_name'), action='append', required=create, help='Metric to evaluate against.') @functools.wraps(func) @@ -490,6 +491,30 @@ def common_alarm_gnocchi_metrics_arguments(create=False): return _wrapper +def common_alarm_gnocchi_aggregation_by_resources_arguments(create=False): + def _wrapper(func): + @utils.arg('-m', '--metric', metavar='<METRIC>', + dest=('gnocchi_aggregation_by_resources_threshold_rule/' + 'metric'), + required=create, + help='Metric to evaluate against.') + @utils.arg('--resource-type', metavar='<RESOURCE_TYPE>', + dest=('gnocchi_aggregation_by_resources_threshold_rule/' + 'resource_type'), + required=create, + help='Resource_type to evaluate against.') + @utils.arg('--query', metavar='<QUERY>', + dest=('gnocchi_aggregation_by_resources_threshold_rule/' + 'query'), + required=create, + help=('Gnocchi resources search query filter')) + @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>', @@ -500,11 +525,10 @@ def common_alarm_gnocchi_resources_arguments(create=False): 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', + @utils.arg('--resource-id', metavar='<RESOURCE_ID>', + dest='gnocchi_resources_threshold_rule/resource_id', required=create, - help=('Resources to evaluate against or a expression ' - 'to select multiple resources.')) + help=('Resource id to evaluate against')) @functools.wraps(func) def _wrapped(*args, **kwargs): return func(*args, **kwargs) @@ -559,14 +583,29 @@ def do_alarm_gnocchi_resources_threshold_create(cc, args={}): @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={}): +@common_alarm_gnocchi_arguments( + 'gnocchi_aggregation_by_metrics_threshold_rule', create=True) +@common_alarm_gnocchi_aggregation_by_metrics_arguments(create=True) +def do_alarm_gnocchi_aggregation_by_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_aggregation_by_metrics_threshold' + alarm = cc.alarms.create(**fields) + _display_alarm(alarm) + + +@common_alarm_arguments(create=True) +@common_alarm_gnocchi_arguments( + 'gnocchi_aggregation_by_resources_threshold_rule', create=True) +@common_alarm_gnocchi_aggregation_by_resources_arguments(create=True) +def do_alarm_gnocchi_aggregation_by_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_metrics_threshold' + fields['type'] = 'gnocchi_aggregation_by_resources_threshold' alarm = cc.alarms.create(**fields) _display_alarm(alarm) @@ -741,7 +780,7 @@ 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_arguments('gnocchi_resources_threshold_rule') @common_alarm_gnocchi_resources_arguments() @utils.arg('--remove-time-constraint', action='append', metavar='<Constraint names>', @@ -767,19 +806,47 @@ def do_alarm_gnocchi_resources_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_metrics_threshold') -@common_alarm_gnocchi_metrics_arguments() +@common_alarm_gnocchi_arguments( + 'gnocchi_aggregation_by_metrics_threshold_rule') +@common_alarm_gnocchi_aggregation_by_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_aggregation_by_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_aggregation_by_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() +@common_alarm_gnocchi_arguments( + 'gnocchi_aggregation_by_resources_threshold_rule') +@common_alarm_gnocchi_aggregation_by_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_metrics_threshold_update(cc, args={}): +def do_alarm_gnocchi_aggregation_by_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_metrics_threshold' + fields['type'] = 'gnocchi_aggregation_by_resources_threshold' try: alarm = cc.alarms.update(args.alarm_id, **fields) except exc.HTTPNotFound: diff --git a/doc/ext/gen_ref.py b/doc/ext/gen_ref.py index f3ea677..f8560b3 100644 --- a/doc/ext/gen_ref.py +++ b/doc/ext/gen_ref.py @@ -52,8 +52,3 @@ def gen_ref(ver, title, names): % {"title": name.capitalize(), "signs": "=" * len(name), "pkg": pkg, "name": name}) - -gen_ref("", "Client Reference", ["client", "exc"]) -gen_ref("v1", "Version 1 API Reference", - ["stacks", "resources", "events", "actions", - "software_configs", "software_deployments"]) diff --git a/doc/source/index.rst b/doc/source/index.rst index 56f671a..cec3b5c 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -24,7 +24,6 @@ Contents: ref/index ref/v1/index ref/v2/index - releases Contributing ============ |