diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 4aec25de..9d106c6d 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -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 diff --git a/glanceclient/v1/images.py b/glanceclient/v1/images.py index 51caa010..374eacd3 100644 --- a/glanceclient/v1/images.py +++ b/glanceclient/v1/images.py @@ -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) diff --git a/glanceclient/v1/legacy_shell.py b/glanceclient/v1/legacy_shell.py index 77e43721..c7121d53 100644 --- a/glanceclient/v1/legacy_shell.py +++ b/glanceclient/v1/legacy_shell.py @@ -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 diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index 00422c50..0c685f84 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -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='', @@ -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="", 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="", action='append', default=[], help=("Arbitrary property to associate with image. "