summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2013-05-09 22:39:20 +0000
committerRick Harris <rconradharris@gmail.com>2013-05-14 17:24:35 +0000
commit1b9489fb0d556a2661c299cf67ed3d26ffcb2dce (patch)
tree3a1f33a31e591daea039fb23380959db5ad8c400 /nova/api
parentda1d7390fea6ba8ac9eefd1a25e5c1412e624ee3 (diff)
downloadnova-1b9489fb0d556a2661c299cf67ed3d26ffcb2dce.tar.gz
nova-1b9489fb0d556a2661c299cf67ed3d26ffcb2dce.tar.xz
nova-1b9489fb0d556a2661c299cf67ed3d26ffcb2dce.zip
Use Oslo's `bool_from_string`
Oslo provides an equivalent implmentation of `bool_from_str` so we should switch the code to use that instead. Change-Id: I382f23af2468e276ae4342dff18cf06e1c24b755
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/disk_config.py4
-rw-r--r--nova/api/openstack/compute/contrib/evacuate.py3
-rw-r--r--nova/api/openstack/compute/contrib/volumes.py3
-rw-r--r--nova/api/openstack/compute/flavors.py23
-rw-r--r--nova/api/openstack/compute/servers.py10
5 files changed, 22 insertions, 21 deletions
diff --git a/nova/api/openstack/compute/contrib/disk_config.py b/nova/api/openstack/compute/contrib/disk_config.py
index 2c4d24332..f2b906144 100644
--- a/nova/api/openstack/compute/contrib/disk_config.py
+++ b/nova/api/openstack/compute/contrib/disk_config.py
@@ -21,7 +21,7 @@ from webob import exc
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
-from nova import utils
+from nova.openstack.common import strutils
ALIAS = 'OS-DCF'
XMLNS_DCF = "http://docs.openstack.org/compute/ext/disk_config/api/v1.1"
@@ -65,7 +65,7 @@ class ImageDiskConfigController(wsgi.Controller):
metadata = image['metadata']
if INTERNAL_DISK_CONFIG in metadata:
raw_value = metadata[INTERNAL_DISK_CONFIG]
- value = utils.bool_from_str(raw_value)
+ value = strutils.bool_from_string(raw_value)
image[API_DISK_CONFIG] = disk_config_to_api(value)
@wsgi.extends
diff --git a/nova/api/openstack/compute/contrib/evacuate.py b/nova/api/openstack/compute/contrib/evacuate.py
index 587e231d1..7eee99ed1 100644
--- a/nova/api/openstack/compute/contrib/evacuate.py
+++ b/nova/api/openstack/compute/contrib/evacuate.py
@@ -21,6 +21,7 @@ from nova.api.openstack import wsgi
from nova import compute
from nova import exception
from nova.openstack.common import log as logging
+from nova.openstack.common import strutils
from nova import utils
LOG = logging.getLogger(__name__)
@@ -47,7 +48,7 @@ class Controller(wsgi.Controller):
evacuate_body = body["evacuate"]
host = evacuate_body["host"]
- on_shared_storage = utils.bool_from_str(
+ on_shared_storage = strutils.bool_from_string(
evacuate_body["onSharedStorage"])
password = None
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py
index 640ac0c76..5a8614f39 100644
--- a/nova/api/openstack/compute/contrib/volumes.py
+++ b/nova/api/openstack/compute/contrib/volumes.py
@@ -25,6 +25,7 @@ from nova.api.openstack import xmlutil
from nova import compute
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
@@ -620,7 +621,7 @@ class SnapshotController(wsgi.Controller):
msg = _("Invalid value '%s' for force.") % force
raise exception.InvalidParameterValue(err=msg)
- if utils.bool_from_str(force):
+ if strutils.bool_from_string(force):
new_snapshot = self.volume_api.create_snapshot_force(context,
vol,
snapshot.get('display_name'),
diff --git a/nova/api/openstack/compute/flavors.py b/nova/api/openstack/compute/flavors.py
index 42b627cf4..744fe5e93 100644
--- a/nova/api/openstack/compute/flavors.py
+++ b/nova/api/openstack/compute/flavors.py
@@ -23,6 +23,7 @@ from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova.compute import flavors
from nova import exception
+from nova.openstack.common import strutils
def make_flavor(elem, detailed=False):
@@ -91,25 +92,20 @@ class Controller(wsgi.Controller):
return self._view_builder.show(req, flavor)
- def _get_is_public(self, req):
+ def _parse_is_public(self, is_public):
"""Parse is_public into something usable."""
- is_public = req.params.get('is_public', None)
if is_public is None:
# preserve default value of showing only public flavors
return True
- elif is_public is True or \
- is_public.lower() in ['t', 'true', 'yes', '1']:
- return True
- elif is_public is False or \
- is_public.lower() in ['f', 'false', 'no', '0']:
- return False
- elif is_public.lower() == 'none':
- # value to match all flavors, ignore is_public
+ elif is_public == 'none':
return None
else:
- msg = _('Invalid is_public filter [%s]') % req.params['is_public']
- raise webob.exc.HTTPBadRequest(explanation=msg)
+ try:
+ return strutils.bool_from_string(is_public, strict=True)
+ except ValueError:
+ msg = _('Invalid is_public filter [%s]') % is_public
+ raise webob.exc.HTTPBadRequest(explanation=msg)
def _get_flavors(self, req):
"""Helper function that returns a list of flavor dicts."""
@@ -118,7 +114,8 @@ class Controller(wsgi.Controller):
context = req.environ['nova.context']
if context.is_admin:
# Only admin has query access to all flavor types
- filters['is_public'] = self._get_is_public(req)
+ filters['is_public'] = self._parse_is_public(
+ req.params.get('is_public', None))
else:
filters['is_public'] = True
filters['disabled'] = False
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 30f8e6fe8..cb3f7ad49 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -33,6 +33,7 @@ from nova import exception
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.openstack.common.rpc import common as rpc_common
+from nova.openstack.common import strutils
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
from nova import utils
@@ -185,7 +186,8 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer):
res_id = server_node.getAttribute('return_reservation_id')
if res_id:
- server['return_reservation_id'] = utils.bool_from_str(res_id)
+ server['return_reservation_id'] = \
+ strutils.bool_from_string(res_id)
scheduler_hints = self._extract_scheduler_hints(server_node)
if scheduler_hints:
@@ -253,7 +255,7 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer):
for attr in attributes:
value = child.getAttribute(attr)
if value:
- mapping[attr] = utils.bool_from_str(value)
+ mapping[attr] = strutils.bool_from_string(value)
block_device_mapping.append(mapping)
return block_device_mapping
else:
@@ -826,7 +828,7 @@ class Controller(wsgi.Controller):
for bdm in block_device_mapping:
self._validate_device_name(bdm["device_name"])
if 'delete_on_termination' in bdm:
- bdm['delete_on_termination'] = utils.bool_from_str(
+ bdm['delete_on_termination'] = strutils.bool_from_string(
bdm['delete_on_termination'])
ret_resv_id = False
@@ -991,7 +993,7 @@ class Controller(wsgi.Controller):
update_dict['access_ip_v6'] = access_ipv6.strip()
if 'auto_disk_config' in body['server']:
- auto_disk_config = utils.bool_from_str(
+ auto_disk_config = strutils.bool_from_string(
body['server']['auto_disk_config'])
update_dict['auto_disk_config'] = auto_disk_config