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:
@@ -48,7 +48,7 @@ def schema_args(schema_getter, omit=[]):
|
|||||||
typemap = {
|
typemap = {
|
||||||
'string': str,
|
'string': str,
|
||||||
'integer': int,
|
'integer': int,
|
||||||
'boolean': string_to_bool,
|
'boolean': strutils.bool_from_string,
|
||||||
'array': list
|
'array': list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,10 +176,6 @@ def is_authentication_required(f):
|
|||||||
return getattr(f, 'require_authentication', True)
|
return getattr(f, 'require_authentication', True)
|
||||||
|
|
||||||
|
|
||||||
def string_to_bool(arg):
|
|
||||||
return arg.strip().lower() in ('t', 'true', 'yes', '1')
|
|
||||||
|
|
||||||
|
|
||||||
def env(*vars, **kwargs):
|
def env(*vars, **kwargs):
|
||||||
"""Search for the first defined of possibly many env vars
|
"""Search for the first defined of possibly many env vars
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ class ImageManager(base.Manager):
|
|||||||
|
|
||||||
for key in ['is_public', 'protected', 'deleted']:
|
for key in ['is_public', 'protected', 'deleted']:
|
||||||
if key in meta:
|
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)
|
return self._format_image_meta_for_user(meta)
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import sys
|
|||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from glanceclient.common import utils
|
from glanceclient.common import utils
|
||||||
|
from glanceclient.openstack.common import strutils
|
||||||
|
|
||||||
|
|
||||||
SUCCESS = 0
|
SUCCESS = 0
|
||||||
@@ -115,9 +116,9 @@ def do_add(gc, args):
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
|
|
||||||
image_meta = {
|
image_meta = {
|
||||||
'is_public': utils.string_to_bool(
|
'is_public': strutils.bool_from_string(
|
||||||
fields.pop('is_public', 'False')),
|
fields.pop('is_public', 'False')),
|
||||||
'protected': utils.string_to_bool(
|
'protected': strutils.bool_from_string(
|
||||||
fields.pop('protected', 'False')),
|
fields.pop('protected', 'False')),
|
||||||
'min_disk': fields.pop('min_disk', 0),
|
'min_disk': fields.pop('min_disk', 0),
|
||||||
'min_ram': fields.pop('min_ram', 0),
|
'min_ram': fields.pop('min_ram', 0),
|
||||||
@@ -208,9 +209,11 @@ def do_update(gc, args):
|
|||||||
|
|
||||||
# Have to handle "boolean" values specially...
|
# Have to handle "boolean" values specially...
|
||||||
if 'is_public' in fields:
|
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:
|
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
|
# Add custom attributes, which are all the arguments remaining
|
||||||
image_meta['properties'] = fields
|
image_meta['properties'] = fields
|
||||||
|
@@ -61,7 +61,8 @@ DISK_FORMATS = ('Acceptable formats: ami, ari, aki, vhd, vmdk, raw, '
|
|||||||
@utils.arg('--sort-dir', default='asc',
|
@utils.arg('--sort-dir', default='asc',
|
||||||
choices=glanceclient.v1.images.SORT_DIR_VALUES,
|
choices=glanceclient.v1.images.SORT_DIR_VALUES,
|
||||||
help='Sort image list in specified direction.')
|
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 '
|
help=('Allows the user to select a listing of public or non '
|
||||||
'public images.'))
|
'public images.'))
|
||||||
@utils.arg('--owner', default=None, metavar='<TENANT_ID>',
|
@utils.arg('--owner', default=None, metavar='<TENANT_ID>',
|
||||||
@@ -192,9 +193,11 @@ def do_image_download(gc, args):
|
|||||||
# to use --is-public
|
# to use --is-public
|
||||||
@utils.arg('--public', action='store_true', default=False,
|
@utils.arg('--public', action='store_true', default=False,
|
||||||
help=argparse.SUPPRESS)
|
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.')
|
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.')
|
help='Prevent image from being deleted.')
|
||||||
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
|
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
|
||||||
help=("Arbitrary property to associate with image. "
|
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'
|
help=('Similar to \'--location\' in usage, but this indicates that'
|
||||||
' the Glance server should immediately copy the data and'
|
' the Glance server should immediately copy the data and'
|
||||||
' store it in its configured image store.'))
|
' 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.')
|
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.')
|
help='Prevent image from being deleted.')
|
||||||
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
|
@utils.arg('--property', metavar="<key=value>", action='append', default=[],
|
||||||
help=("Arbitrary property to associate with image. "
|
help=("Arbitrary property to associate with image. "
|
||||||
|
Reference in New Issue
Block a user