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: I23924db3000feadcfe823c6cc979ea9752a13fa9
This commit is contained in:
llg8212 2014-01-22 11:45:42 +08:00
parent e4d1961c92
commit e5f6dee95d
4 changed files with 19 additions and 15 deletions

View File

@ -48,7 +48,7 @@ def schema_args(schema_getter, omit=[]):
typemap = {
'string': str,
'integer': int,
'boolean': string_to_bool,
'boolean': strutils.bool_from_string,
'array': list
}
@ -176,10 +176,6 @@ def is_authentication_required(f):
return getattr(f, 'require_authentication', True)
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

View File

@ -70,7 +70,7 @@ class ImageManager(base.Manager):
for key in ['is_public', 'protected', 'deleted']:
if key in meta:
meta[key] = utils.string_to_bool(meta[key])
meta[key] = strutils.bool_from_string(meta[key])
return self._format_image_meta_for_user(meta)

View File

@ -25,6 +25,7 @@ import sys
import urlparse
from glanceclient.common import utils
from glanceclient.openstack.common import strutils
SUCCESS = 0
@ -115,9 +116,9 @@ def do_add(gc, args):
return FAILURE
image_meta = {
'is_public': utils.string_to_bool(
'is_public': strutils.bool_from_string(
fields.pop('is_public', 'False')),
'protected': utils.string_to_bool(
'protected': strutils.bool_from_string(
fields.pop('protected', 'False')),
'min_disk': fields.pop('min_disk', 0),
'min_ram': fields.pop('min_ram', 0),
@ -208,9 +209,11 @@ def do_update(gc, args):
# Have to handle "boolean" values specially...
if 'is_public' in fields:
image_meta['is_public'] = utils.string_to_bool(fields.pop('is_public'))
image_meta['is_public'] = strutils.\
bool_from_string(fields.pop('is_public'))
if 'protected' in fields:
image_meta['protected'] = utils.string_to_bool(fields.pop('protected'))
image_meta['protected'] = strutils.\
bool_from_string(fields.pop('protected'))
# Add custom attributes, which are all the arguments remaining
image_meta['properties'] = fields

View File

@ -61,7 +61,8 @@ DISK_FORMATS = ('Acceptable formats: ami, ari, aki, vhd, vmdk, raw, '
@utils.arg('--sort-dir', default='asc',
choices=glanceclient.v1.images.SORT_DIR_VALUES,
help='Sort image list in specified direction.')
@utils.arg('--is-public', type=utils.string_to_bool, metavar='{True,False}',
@utils.arg('--is-public',
type=strutils.bool_from_string, metavar='{True,False}',
help=('Allows the user to select a listing of public or non '
'public images.'))
@utils.arg('--owner', default=None, metavar='<TENANT_ID>',
@ -192,9 +193,11 @@ def do_image_download(gc, args):
# to use --is-public
@utils.arg('--public', action='store_true', default=False,
help=argparse.SUPPRESS)
@utils.arg('--is-public', type=utils.string_to_bool, metavar='{True,False}',
@utils.arg('--is-public',
type=strutils.bool_from_string, metavar='{True,False}',
help='Make image accessible to the public.')
@utils.arg('--is-protected', type=utils.string_to_bool, metavar='{True,False}',
@utils.arg('--is-protected',
type=strutils.bool_from_string, metavar='{True,False}',
help='Prevent image from being deleted.')
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
help=("Arbitrary property to associate with image. "
@ -264,9 +267,11 @@ def do_image_create(gc, args):
help=('Similar to \'--location\' in usage, but this indicates that'
' the Glance server should immediately copy the data and'
' store it in its configured image store.'))
@utils.arg('--is-public', type=utils.string_to_bool, metavar='{True,False}',
@utils.arg('--is-public',
type=strutils.bool_from_string, metavar='{True,False}',
help='Make image accessible to the public.')
@utils.arg('--is-protected', type=utils.string_to_bool, metavar='{True,False}',
@utils.arg('--is-protected',
type=strutils.bool_from_string, metavar='{True,False}',
help='Prevent image from being deleted.')
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
help=("Arbitrary property to associate with image. "