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/api | |
| parent | 55ccdbc3bc62dc32161112a77c0fed39e73ee7b4 (diff) | |
| download | nova-715435c816b51b6ec8d38453326eecd35c339fd9.tar.gz nova-715435c816b51b6ec8d38453326eecd35c339fd9.tar.xz nova-715435c816b51b6ec8d38453326eecd35c339fd9.zip | |
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/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/volumes.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index 7410543d5..3ede9e4a4 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -27,7 +27,6 @@ from nova import exception from nova.openstack.common import log as logging from nova.openstack.common import strutils from nova.openstack.common import uuidutils -from nova import utils from nova import volume LOG = logging.getLogger(__name__) @@ -617,27 +616,26 @@ class SnapshotController(wsgi.Controller): snapshot = body['snapshot'] volume_id = snapshot['volume_id'] - force = snapshot.get('force', False) LOG.audit(_("Create snapshot from volume %s"), volume_id, - context=context) + context=context) - if not utils.is_valid_boolstr(force): + force = snapshot.get('force', False) + try: + force = strutils.bool_from_string(force, strict=True) + except ValueError: msg = _("Invalid value '%s' for force.") % force raise exception.InvalidParameterValue(err=msg) - if strutils.bool_from_string(force): - new_snapshot = self.volume_api.create_snapshot_force(context, - volume_id, - snapshot.get('display_name'), - snapshot.get('display_description')) + if force: + create_func = self.volume_api.create_snapshot_force else: - new_snapshot = self.volume_api.create_snapshot(context, - volume_id, - snapshot.get('display_name'), - snapshot.get('display_description')) + create_func = self.volume_api.create_snapshot - retval = _translate_snapshot_detail_view(context, new_snapshot) + new_snapshot = create_func(context, volume_id, + snapshot.get('display_name'), + snapshot.get('display_description')) + retval = _translate_snapshot_detail_view(context, new_snapshot) return {'snapshot': retval} |
