From 81e76480af6ad17943cd2385a045d24217b07a7b Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Thu, 13 Sep 2012 01:59:43 -0400 Subject: Include Schedule Hints deserialization to XML API So far the xml format to schedule hints were not defined. Once defined (in ML), this patch add support to its deserialization. This patch also includes a xml deserialization method to get the Elements between the childs of a node. Partially fixes bug 1050997 Change-Id: I2a34dbbd6200755818d7eaa7330a96d61a043614 --- nova/api/openstack/compute/servers.py | 15 +++++++++++++++ nova/api/openstack/wsgi.py | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index f448d3fb9..33e4d0689 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -163,6 +163,10 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): if server_node.getAttribute(attr): server[attr] = server_node.getAttribute(attr) + scheduler_hints = self._extract_scheduler_hints(server_node) + if scheduler_hints: + server['os:scheduler_hints'] = scheduler_hints + metadata_node = self.find_first_child_named(server_node, "metadata") if metadata_node is not None: server["metadata"] = self.extract_metadata(metadata_node) @@ -185,6 +189,17 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): return server + def _extract_scheduler_hints(self, server_node): + """Marshal the scheduler hints attribute of a parsed request""" + node = self.find_first_child_named(server_node, "scheduler_hints") + if node: + scheduler_hints = {} + for child in self.extract_elements(node): + scheduler_hints[child.nodeName] = self.extract_text(child) + return scheduler_hints + else: + return None + def _extract_networks(self, server_node): """Marshal the networks attribute of a parsed request.""" node = self.find_first_child_named(server_node, "networks") diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index a9fa3847a..c3f631962 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -265,6 +265,14 @@ class XMLDeserializer(TextDeserializer): return child.nodeValue return "" + def extract_elements(self, node): + """Get only Element type childs from node""" + elements = [] + for child in node.childNodes: + if child.nodeType == child.ELEMENT_NODE: + elements.append(child) + return elements + def find_attribute_or_element(self, parent, name): """Get an attribute value; fallback to an element if not found""" if parent.hasAttribute(name): -- cgit