From 715435c816b51b6ec8d38453326eecd35c339fd9 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 14 May 2013 15:23:55 +0000 Subject: 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 --- nova/api/openstack/compute/contrib/volumes.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'nova/api') 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} -- cgit