diff options
-rw-r--r-- | ceilometerclient/exc.py | 14 | ||||
-rw-r--r-- | ceilometerclient/tests/unit/test_exc.py | 16 | ||||
-rw-r--r-- | ceilometerclient/v2/shell.py | 23 | ||||
-rw-r--r-- | releasenotes/notes/alarm_deprecated-74363d70d48a20e2.yaml | 3 |
4 files changed, 53 insertions, 3 deletions
diff --git a/ceilometerclient/exc.py b/ceilometerclient/exc.py index c7e550b..3db1c0c 100644 --- a/ceilometerclient/exc.py +++ b/ceilometerclient/exc.py @@ -118,6 +118,16 @@ for obj_name in dir(sys.modules[__name__]): def from_response(response, details=None): - """Return an instance of an HTTPException based on httplib response.""" - cls = _code_map.get(response.status, HTTPException) + """Return an instance of an HTTPException based on http response.""" + if hasattr(response, "status"): + # it is response from HTTPClient (httplib) + code = response.status + elif hasattr(response, "status_code"): + # it is response from SessionClient (requests) + code = response.status_code + else: + # it is something unexpected + raise TypeError("Function 'from_response' expects only response object" + " from httplib or requests libraries.") + cls = _code_map.get(code, HTTPException) return cls(details) diff --git a/ceilometerclient/tests/unit/test_exc.py b/ceilometerclient/tests/unit/test_exc.py index db8df32..b0fd1b1 100644 --- a/ceilometerclient/tests/unit/test_exc.py +++ b/ceilometerclient/tests/unit/test_exc.py @@ -69,3 +69,19 @@ class HTTPExceptionsTest(utils.BaseTestCase): {"error_message": {"faultstring": "oops"}})) ret_str = k + " (HTTP " + str(exception.code) + ") ERROR oops" self.assertEqual(ret_str, str(exception)) + + def test_from_response(self): + class HTTPLibLikeResponse(object): + status = 400 + + class RequestsLikeResponse(object): + status_code = 401 + + class UnexpectedResponse(object): + code = 200 + + self.assertEqual(HTTPLibLikeResponse.status, + exc.from_response(HTTPLibLikeResponse).code) + self.assertEqual(RequestsLikeResponse.status_code, + exc.from_response(RequestsLikeResponse).code) + self.assertRaises(TypeError, exc.from_response, UnexpectedResponse) diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 8b4c65d..ca9e264 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -1,5 +1,5 @@ # -# Copyright 2013 Red Hat, Inc +# Copyright 2013-2016 Red Hat, Inc # Copyright Ericsson AB 2014. All rights reserved # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -17,6 +17,7 @@ import argparse import functools import json +import warnings from oslo_serialization import jsonutils from oslo_utils import strutils @@ -396,6 +397,7 @@ def alarm_change_detail_formatter(change): 'but if supplied must be string, integer, float, or boolean.') def do_alarm_list(cc, args={}): """List the user's alarms.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") alarms = cc.alarms.list(q=options.cli_to_array(args.query)) _display_alarm_list(alarms, sortby=0) @@ -440,6 +442,7 @@ def _display_alarm(alarm): action=NotEmptyAction, help='ID of the alarm to show.') def do_alarm_show(cc, args={}): """Show an alarm.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") alarm = cc.alarms.get(args.alarm_id) # alarm.get actually catches the HTTPNotFound exception and turns the # result into None if the alarm wasn't found. @@ -633,6 +636,7 @@ def common_alarm_event_arguments(): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_create(cc, args={}): """Create a new alarm (Deprecated). Use alarm-threshold-create instead.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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.args_array_to_dict(fields, "matching_metadata") @@ -648,6 +652,7 @@ def do_alarm_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_resources_threshold_create(cc, args={}): """Create a new alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -664,6 +669,7 @@ def do_alarm_gnocchi_resources_threshold_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_aggregation_by_metrics_threshold_create(cc, args={}): """Create a new alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -680,6 +686,7 @@ def do_alarm_gnocchi_aggregation_by_metrics_threshold_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_aggregation_by_resources_threshold_create(cc, args={}): """Create a new alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -716,6 +723,7 @@ def do_alarm_gnocchi_aggregation_by_resources_threshold_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_threshold_create(cc, args={}): """Create a new alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -739,6 +747,7 @@ def do_alarm_threshold_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_combination_create(cc, args={}): """Create a new alarm based on state of other alarms.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -753,6 +762,7 @@ def do_alarm_combination_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_event_create(cc, args={}): """Create a new alarm based on events.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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' @@ -795,6 +805,7 @@ def do_alarm_event_create(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_update(cc, args={}): """Update an existing alarm (Deprecated).""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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.args_array_to_dict(fields, "matching_metadata") @@ -844,6 +855,7 @@ def do_alarm_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_threshold_update(cc, args={}): """Update an existing alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -875,6 +887,7 @@ def do_alarm_threshold_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_resources_threshold_update(cc, args={}): """Update an existing alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -904,6 +917,7 @@ def do_alarm_gnocchi_resources_threshold_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_aggregation_by_metrics_threshold_update(cc, args={}): """Update an existing alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -933,6 +947,7 @@ def do_alarm_gnocchi_aggregation_by_metrics_threshold_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_gnocchi_aggregation_by_resources_threshold_update(cc, args={}): """Update an existing alarm based on computed statistics.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -966,6 +981,7 @@ def do_alarm_gnocchi_aggregation_by_resources_threshold_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_combination_update(cc, args={}): """Update an existing alarm based on state of other alarms.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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) @@ -989,6 +1005,7 @@ def do_alarm_combination_update(cc, args={}): @_restore_shadowed_arg('user_id', 'alarm_user_id') def do_alarm_event_update(cc, args={}): """Update an existing alarm based on events.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") 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') @@ -1010,6 +1027,7 @@ def do_alarm_event_update(cc, args={}): action=NotEmptyAction, help='ID of the alarm to delete.') def do_alarm_delete(cc, args={}): """Delete an alarm.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") try: cc.alarms.delete(args.alarm_id) except exc.HTTPNotFound: @@ -1026,6 +1044,7 @@ def do_alarm_delete(cc, args={}): '.') def do_alarm_state_set(cc, args={}): """Set the state of an alarm.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") try: state = cc.alarms.set_state(args.alarm_id, args.state) except exc.HTTPNotFound: @@ -1040,6 +1059,7 @@ def do_alarm_state_set(cc, args={}): action=NotEmptyAction, help='ID of the alarm state to show.') def do_alarm_state_get(cc, args={}): """Get the state of an alarm.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") try: state = cc.alarms.get_state(args.alarm_id) except exc.HTTPNotFound: @@ -1057,6 +1077,7 @@ def do_alarm_state_get(cc, args={}): 'but if supplied must be string, integer, float, or boolean.') def do_alarm_history(cc, args={}): """Display the change history of an alarm.""" + warnings.warn("Alarm commands are deprecated, please use aodhclient") kwargs = dict(alarm_id=args.alarm_id, q=options.cli_to_array(args.query)) try: diff --git a/releasenotes/notes/alarm_deprecated-74363d70d48a20e2.yaml b/releasenotes/notes/alarm_deprecated-74363d70d48a20e2.yaml new file mode 100644 index 0000000..f50901b --- /dev/null +++ b/releasenotes/notes/alarm_deprecated-74363d70d48a20e2.yaml @@ -0,0 +1,3 @@ +--- +deprecations: + - Alarm commands are deprecated in favor of aodhclient. |