diff options
| author | Rick Harris <rconradharris@gmail.com> | 2013-05-14 15:23:55 +0000 |
|---|---|---|
| committer | Rick Harris <rconradharris@gmail.com> | 2013-05-17 21:31:37 +0000 |
| commit | 715435c816b51b6ec8d38453326eecd35c339fd9 (patch) | |
| tree | 9abb8681c1f9b37af56d63214df34301c6d7f027 /nova/compute | |
| parent | 55ccdbc3bc62dc32161112a77c0fed39e73ee7b4 (diff) | |
Use strict=True instead of `is_valid_boolstr`
Oslo's `bool_from_string` learned the `strict` keyword which allows
callers to detect invalid boolean values, so we can use that instead
of having a new Nova-specific function.
Change-Id: I61bfa4029897c7304bd54d6cdae9f9a9bc4c1f78
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/api.py | 33 | ||||
| -rw-r--r-- | nova/compute/flavors.py | 9 |
2 files changed, 27 insertions, 15 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index f47121c36..56100d962 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -476,6 +476,26 @@ class API(base.Base): instance['uuid'], updates) return instance + def _check_config_drive(self, context, config_drive): + bool_like = True + try: + strutils.bool_from_string(config_drive, strict=True) + except ValueError: + bool_like = False + + if config_drive is None: + return None, None + elif bool_like and config_drive not in (0, 1, '0', '1'): + # NOTE(sirp): '0' and '1' could be a bool value or an ID. Since + # there are many other ways to specify bools (e.g. 't', 'f'), it's + # better to treat as an ID. + return None, config_drive + else: + cd_image_service, config_drive_id = \ + glance.get_remote_image_service(context, config_drive) + cd_image_service.show(context, config_drive_id) + return config_drive_id, None + def _validate_and_provision_instance(self, context, instance_type, image_href, kernel_id, ramdisk_id, min_count, max_count, @@ -557,17 +577,8 @@ class API(base.Base): kernel_id, ramdisk_id = self._handle_kernel_and_ramdisk( context, kernel_id, ramdisk_id, image) - # Handle config_drive - config_drive_id = None - if config_drive and not utils.is_valid_boolstr(config_drive): - # config_drive is volume id - config_drive_id = config_drive - config_drive = None - - # Ensure config_drive image exists - cd_image_service, config_drive_id = \ - glance.get_remote_image_service(context, config_drive_id) - cd_image_service.show(context, config_drive_id) + config_drive_id, config_drive = self._check_config_drive( + context, config_drive) if key_data is None and key_name: key_pair = self.db.key_pair_get(context, context.user_id, diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 2958769e1..58dcd3fa5 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -123,10 +123,11 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, kwargs['flavorid'] = unicode(flavorid) # ensure is_public attribute is boolean - if not utils.is_valid_boolstr(is_public): - msg = _("is_public must be a boolean") - raise exception.InvalidInput(reason=msg) - kwargs['is_public'] = strutils.bool_from_string(is_public) + try: + kwargs['is_public'] = strutils.bool_from_string( + is_public, strict=True) + except ValueError: + raise exception.InvalidInput(reason=_("is_public must be a boolean")) try: return db.instance_type_create(context.get_admin_context(), kwargs) |
