Merge "Replace some utils.bool_from_str with strutils"

This commit is contained in:
Jenkins 2014-01-03 11:47:28 +00:00 committed by Gerrit Code Review
commit ab32e406c8
5 changed files with 20 additions and 27 deletions

View File

@ -145,7 +145,8 @@ class SecretsHelper(object):
def password(self): def password(self):
if self._validate_string(self.args.os_password): if self._validate_string(self.args.os_password):
return 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) return self._prompt_password(verify_pass)
@property @property
@ -242,7 +243,8 @@ class OpenStackComputeShell(object):
help="Print debugging output") help="Print debugging output")
parser.add_argument('--os-cache', 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', action='store_true',
help="Use the auth token cache. Defaults to False if env[OS_CACHE]" help="Use the auth token cache. Defaults to False if env[OS_CACHE]"
" is not set.") " is not set.")

View File

@ -60,21 +60,6 @@ def add_arg(f, *args, **kwargs):
f.arguments.insert(0, (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): def add_resource_manager_extra_kwargs_hook(f, hook):
"""Add hook to bind CLI arguments to ResourceManager calls. """Add hook to bind CLI arguments to ResourceManager calls.

View File

@ -18,7 +18,7 @@ Flavor interface.
from novaclient import base from novaclient import base
from novaclient import exceptions from novaclient import exceptions
from novaclient.openstack.common.py3kcompat import urlutils from novaclient.openstack.common.py3kcompat import urlutils
from novaclient import utils from novaclient.openstack.common import strutils
class Flavor(base.Resource): class Flavor(base.Resource):
@ -195,7 +195,7 @@ class FlavorManager(base.ManagerWithFind):
raise exceptions.CommandError("rxtx_factor must be a float.") raise exceptions.CommandError("rxtx_factor must be a float.")
try: try:
is_public = utils.bool_from_str(is_public) is_public = strutils.bool_from_string(is_public, True)
except Exception: except Exception:
raise exceptions.CommandError("is_public must be a boolean.") raise exceptions.CommandError("is_public must be a boolean.")

View File

@ -652,7 +652,7 @@ def do_flavor_show(cs, args):
@utils.arg('--is-public', @utils.arg('--is-public',
metavar='<is-public>', metavar='<is-public>',
help="Make flavor accessible to the public (default true)", 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) default=True)
def do_flavor_create(cs, args): def do_flavor_create(cs, args):
"""Create a new flavor""" """Create a new flavor"""
@ -1076,7 +1076,8 @@ def do_image_delete(cs, args):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',
@ -1617,7 +1618,8 @@ def _translate_availability_zone_keys(collection):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',
@ -2239,7 +2241,8 @@ def do_secgroup_delete(cs, args):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',

View File

@ -512,7 +512,7 @@ def do_flavor_show(cs, args):
@utils.arg('--is-public', @utils.arg('--is-public',
metavar='<is-public>', metavar='<is-public>',
help="Make flavor accessible to the public (default true)", 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) default=True)
def do_flavor_create(cs, args): def do_flavor_create(cs, args):
"""Create a new flavor""" """Create a new flavor"""
@ -935,7 +935,8 @@ def do_image_delete(cs, args):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',
@ -1441,7 +1442,8 @@ def _translate_availability_zone_keys(collection):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',
@ -2036,7 +2038,8 @@ def do_secgroup_delete(cs, args):
nargs='?', nargs='?',
type=int, type=int,
const=1, 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).') help='Display information from all tenants (Admin only).')
@utils.arg('--all_tenants', @utils.arg('--all_tenants',
nargs='?', nargs='?',