summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/create_instance_helper.py24
-rw-r--r--nova/api/openstack/servers.py41
2 files changed, 27 insertions, 38 deletions
diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py
index eea973a56..e46bc9d98 100644
--- a/nova/api/openstack/create_instance_helper.py
+++ b/nova/api/openstack/create_instance_helper.py
@@ -320,12 +320,10 @@ class ServerXMLDeserializer(wsgi.XMLDeserializer):
image = {}
image_id = image_node.getAttribute('id')
- if image_id:
+ if image_id is not None:
image['id'] = image_id
- image_links = self._extract_links_from_node(image_node)
- if len(image_links) > 0:
- image['links'] = image_links
+ image['links'] = self._extract_links_from_node(image_node)
return image
@@ -340,9 +338,7 @@ class ServerXMLDeserializer(wsgi.XMLDeserializer):
if flavor_id:
flavor['id'] = flavor_id
- flavor_links = self._extract_links_from_node(flavor_node)
- if len(flavor_links) > 0:
- flavor['links'] = flavor_links
+ flavor['links'] = self._extract_links_from_node(flavor_node)
return flavor
@@ -351,14 +347,12 @@ class ServerXMLDeserializer(wsgi.XMLDeserializer):
links = []
for link_node in self._find_children_named(parent_node, 'atom:link'):
- link = {}
- link_rel = link_node.getAttribute('rel')
- if link_rel is not None:
- link['rel'] = link_rel
- link_href = link_node.getAttribute('href')
- if link_href is not None:
- link['href'] = link_href
- links.append(link)
+ link = {
+ 'rel': link_node.getAttribute('rel'),
+ 'href': link_node.getAttribute('href'),
+ }
+ if link['rel'] is not None and link['href'] is not None:
+ links.append(link)
return links
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index f239044ff..1e8749f56 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -491,10 +491,21 @@ class ControllerV11(Controller):
except exception.NotFound:
return faults.Fault(exc.HTTPNotFound())
+ def _href_from_bookmark_links(self, links)
+ for link in links:
+ try:
+ if link.get('rel') == 'bookmark':
+ href = link.get('href')
+ if href is not None:
+ return href
+ except AttributeError:
+ msg = _("Malformed link entity")
+ raise exc.HTTPBadRequest(explanation=msg)
+
def _image_ref_from_req_data(self, data):
try:
image = data['server']['image']
- except (AttributeError, KeyError):
+ except (TypeError, KeyError):
msg = _("Missing image entity")
raise exc.HTTPBadRequest(explanation=msg)
@@ -504,29 +515,21 @@ class ControllerV11(Controller):
msg = _("Malformed image entity")
raise exc.HTTPBadRequest(explanation=msg)
- image_ref = None
- for link in links:
- try:
- if link.get('rel') == 'bookmark':
- image_ref = link.get('href')
- break
- except AttributeError:
- msg = _("Malformed image link")
- raise exc.HTTPBadRequest(explanation=msg)
+ image_ref = self._href_from_bookmark_links(links)
if image_ref is None:
try:
- image_ref = image['id']
+ return image['id']
except KeyError:
msg = _("Missing id attribute on image entity")
raise exc.HTTPBadRequest(explanation=msg)
-
- return image_ref
+ else:
+ return image_ref
def _flavor_id_from_req_data(self, data):
try:
flavor = data['server']['flavor']
- except (AttributeError, KeyError):
+ except (TypeError, KeyError):
msg = _("Missing flavor entity")
raise exc.HTTPBadRequest(explanation=msg)
@@ -536,15 +539,7 @@ class ControllerV11(Controller):
msg = _("Malformed flavor entity")
raise exc.HTTPBadRequest(explanation=msg)
- flavor_ref = None
- for link in links:
- try:
- if link.get('rel') == 'bookmark':
- flavor_ref = link.get('href')
- break
- except AttributeError:
- msg = _("Malformed flavor link")
- raise exc.HTTPBadRequest(explanation=msg)
+ flavor_ref = self._href_from_bookmark_links(links)
if flavor_ref is None:
try: