Replace some utils.bool_from_str with strutils

Instead of using novaclient.utils' bool_from_str, use bool_from_string
from the oslo incubating strutils

Notes:
 0. utils.bool_from_str was strict, only accepted a small set of
    values, while strutils.bool_from_string is not strict by default,
    anything not true is false
 1. bool_from_string accepts on/off, which bool_from_str did not

Change-Id: I04744844b55697819289def081d3c9117ed0713f
This commit is contained in:
Matthew Farrellee 2013-12-22 08:01:36 -05:00
parent 708af32f03
commit 669cdc4ffd
5 changed files with 20 additions and 27 deletions

View File

@ -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.")

View File

@ -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.

View File

@ -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.")

View File

@ -652,7 +652,7 @@ def do_flavor_show(cs, args):
@utils.arg('--is-public',
metavar='<is-public>',
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='?',
@ -1612,7 +1613,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='?',
@ -2234,7 +2236,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='?',

View File

@ -512,7 +512,7 @@ def do_flavor_show(cs, args):
@utils.arg('--is-public',
metavar='<is-public>',
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='?',