diff --git a/novaclient/shell.py b/novaclient/shell.py index a7615b48c..c4a0c9ec3 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -145,7 +145,8 @@ class SecretsHelper(object): def password(self): if self._validate_string(self.args.os_password): return self.args.os_password - verify_pass = utils.bool_from_str(utils.env("OS_VERIFY_PASSWORD")) + verify_pass = strutils.bool_from_string( + utils.env("OS_VERIFY_PASSWORD", default=False), True) return self._prompt_password(verify_pass) @property @@ -242,7 +243,8 @@ class OpenStackComputeShell(object): help="Print debugging output") parser.add_argument('--os-cache', - default=utils.bool_from_str(utils.env('OS_CACHE', default=False)), + default=strutils.bool_from_string( + utils.env('OS_CACHE', default=False), True), action='store_true', help="Use the auth token cache. Defaults to False if env[OS_CACHE]" " is not set.") diff --git a/novaclient/utils.py b/novaclient/utils.py index be64f0290..e7e848173 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -60,21 +60,6 @@ def add_arg(f, *args, **kwargs): f.arguments.insert(0, (args, kwargs)) -def bool_from_str(val): - """Convert a string representation of a bool into a bool value.""" - - if not val: - return False - try: - return bool(int(val)) - except ValueError: - if val.lower() in ['true', 'yes', 'y']: - return True - if val.lower() in ['false', 'no', 'n']: - return False - raise - - def add_resource_manager_extra_kwargs_hook(f, hook): """Add hook to bind CLI arguments to ResourceManager calls. diff --git a/novaclient/v1_1/flavors.py b/novaclient/v1_1/flavors.py index dfafdab3e..cfb06d1ed 100644 --- a/novaclient/v1_1/flavors.py +++ b/novaclient/v1_1/flavors.py @@ -18,7 +18,7 @@ Flavor interface. from novaclient import base from novaclient import exceptions from novaclient.openstack.common.py3kcompat import urlutils -from novaclient import utils +from novaclient.openstack.common import strutils class Flavor(base.Resource): @@ -195,7 +195,7 @@ class FlavorManager(base.ManagerWithFind): raise exceptions.CommandError("rxtx_factor must be a float.") try: - is_public = utils.bool_from_str(is_public) + is_public = strutils.bool_from_string(is_public, True) except Exception: raise exceptions.CommandError("is_public must be a boolean.") diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 05ecfca4e..4a31bb538 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -652,7 +652,7 @@ def do_flavor_show(cs, args): @utils.arg('--is-public', metavar='', help="Make flavor accessible to the public (default true)", - type=utils.bool_from_str, + type=lambda v: strutils.bool_from_string(v, True), default=True) def do_flavor_create(cs, args): """Create a new flavor""" @@ -1076,7 +1076,8 @@ def do_image_delete(cs, args): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?', @@ -1617,7 +1618,8 @@ def _translate_availability_zone_keys(collection): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?', @@ -2239,7 +2241,8 @@ def do_secgroup_delete(cs, args): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?', diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 21364fba2..0750b45f7 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -512,7 +512,7 @@ def do_flavor_show(cs, args): @utils.arg('--is-public', metavar='', help="Make flavor accessible to the public (default true)", - type=utils.bool_from_str, + type=lambda v: strutils.bool_from_string(v, True), default=True) def do_flavor_create(cs, args): """Create a new flavor""" @@ -935,7 +935,8 @@ def do_image_delete(cs, args): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?', @@ -1441,7 +1442,8 @@ def _translate_availability_zone_keys(collection): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?', @@ -2036,7 +2038,8 @@ def do_secgroup_delete(cs, args): nargs='?', type=int, const=1, - default=int(utils.bool_from_str(os.environ.get("ALL_TENANTS", 'false'))), + default=int(strutils.bool_from_string( + os.environ.get("ALL_TENANTS", 'false'), True)), help='Display information from all tenants (Admin only).') @utils.arg('--all_tenants', nargs='?',