From 08eca91c65733edbfa4b76eadebbedaac1cb1573 Mon Sep 17 00:00:00 2001 From: llg8212 Date: Wed, 22 Jan 2014 11:22:24 +0800 Subject: [PATCH] Using common method 'bool_from_string' from oslo strutils Using common method 'bool_from_string' from oslo strutils to replace utils.string_to_bool. partially implements blueprint common-client-library-2 Change-Id: I101eb89174ac229aa1025bc4aea8b1c0c5594705 --- ceilometerclient/common/utils.py | 4 ---- ceilometerclient/v2/shell.py | 15 ++++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ceilometerclient/common/utils.py b/ceilometerclient/common/utils.py index 4f532e5e..3d7b0cd5 100644 --- a/ceilometerclient/common/utils.py +++ b/ceilometerclient/common/utils.py @@ -133,10 +133,6 @@ def find_resource(manager, name_or_id): raise exc.CommandError(msg) -def string_to_bool(arg): - return arg.strip().lower() in ('t', 'true', 'yes', '1') - - def env(*vars, **kwargs): """Search for the first defined of possibly many env vars diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 6d861aae..858c3d1b 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -22,6 +22,7 @@ import six from ceilometerclient.common import utils from ceilometerclient import exc +from ceilometerclient.openstack.common import strutils from ceilometerclient.v2 import options @@ -257,7 +258,7 @@ def common_alarm_arguments(create=False): help='Free text description of the alarm') @utils.arg('--state', metavar='', help='State of the alarm, one of: ' + str(ALARM_STATES)) - @utils.arg('--enabled', type=utils.string_to_bool, + @utils.arg('--enabled', type=strutils.bool_from_string, metavar='{True|False}', help='True if alarm evaluation/actioning is enabled') @utils.arg('--alarm-action', dest='alarm_actions', @@ -298,7 +299,7 @@ def common_alarm_arguments(create=False): 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=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, default=False, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) @@ -333,7 +334,7 @@ def do_alarm_create(cc, args={}): 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=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, default=False, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) @@ -358,7 +359,7 @@ def do_alarm_threshold_create(cc, args={}): help='Operator to compare with, one of: ' + str( ALARM_COMBINATION_OPERATORS)) @utils.arg('--repeat-actions', dest='repeat_actions', - metavar='{True|False}', type=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, default=False, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) @@ -391,7 +392,7 @@ def do_alarm_combination_create(cc, args={}): 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=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) def do_alarm_update(cc, args={}): @@ -431,7 +432,7 @@ def do_alarm_update(cc, args={}): 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=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) def do_alarm_threshold_update(cc, args={}): @@ -461,7 +462,7 @@ def do_alarm_threshold_update(cc, args={}): help='Operator to compare with, one of: ' + str( ALARM_COMBINATION_OPERATORS)) @utils.arg('--repeat-actions', dest='repeat_actions', - metavar='{True|False}', type=utils.string_to_bool, + metavar='{True|False}', type=strutils.bool_from_string, help=('True if actions should be repeatedly notified ' 'while alarm remains in target state')) def do_alarm_combination_update(cc, args={}):