summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2012-09-18 12:02:50 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2012-09-18 12:46:52 -0700
commit8d43c3fba1a5e07703cae6f7b631d0787c4f41bb (patch)
tree5b1bd05247e67285aedcf884a6e33335b9b3583d /nova/api
parent71c9677d803a722f5c9eb5b2d0719f1e713d1b7b (diff)
Makes scheduler hints and disk config xml correct
The scheduler hints and disk config extensions were not using proper prefixes when deserializing xml. This patch modifes them to deserialize properly. It leaves the old deserialization in place as well so anyone using the broken implementation will continue to work. It also updates the api samples to use the new format. Note that the proper fix required changing the alias for the scheduler hints extension, since the alias is used for xml, so the samples had to be moved. Finally it fixes an issue with deserialization, allowing it to support multiple hints with the same name. Part of bug 1050997 Change-Id: I9969582d65d44de25388f07b6d2013fb7d093fb2
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/scheduler_hints.py14
-rw-r--r--nova/api/openstack/compute/servers.py25
2 files changed, 27 insertions, 12 deletions
diff --git a/nova/api/openstack/compute/contrib/scheduler_hints.py b/nova/api/openstack/compute/contrib/scheduler_hints.py
index e8d65a741..f5c10fea1 100644
--- a/nova/api/openstack/compute/contrib/scheduler_hints.py
+++ b/nova/api/openstack/compute/contrib/scheduler_hints.py
@@ -29,13 +29,13 @@ class SchedulerHintsController(wsgi.Controller):
def _extract_scheduler_hints(body):
hints = {}
+ attr = '%s:scheduler_hints' % Scheduler_hints.alias
try:
- hints.update(body['os:scheduler_hints'])
-
- # Ignore if data is not present
- except KeyError:
- pass
-
+ if 'os:scheduler_hints' in body:
+ # NOTE(vish): This is for legacy support
+ hints.update(body['os:scheduler_hints'])
+ elif attr in body:
+ hints.update(body[attr])
# Fail if non-dict provided
except ValueError:
msg = _("Malformed scheduler_hints attribute")
@@ -56,7 +56,7 @@ class Scheduler_hints(extensions.ExtensionDescriptor):
"""Pass arbitrary key/value pairs to the scheduler"""
name = "SchedulerHints"
- alias = "os-scheduler-hints"
+ alias = "OS-SCH-HNT"
namespace = ("http://docs.openstack.org/compute/ext/"
"scheduler-hints/api/v2")
updated = "2011-07-19T00:00:00+00:00"
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 5cb7369c0..c9bc4430e 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -171,7 +171,7 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer):
scheduler_hints = self._extract_scheduler_hints(server_node)
if scheduler_hints:
- server['os:scheduler_hints'] = scheduler_hints
+ server['OS-SCH-HNT:scheduler_hints'] = scheduler_hints
metadata_node = self.find_first_child_named(server_node, "metadata")
if metadata_node is not None:
@@ -193,19 +193,34 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer):
if security_groups is not None:
server["security_groups"] = security_groups
+ # NOTE(vish): Support this incorrect version because it was in the code
+ # base for a while and we don't want to accidentally break
+ # anyone that might be using it.
auto_disk_config = server_node.getAttribute('auto_disk_config')
if auto_disk_config:
- server['auto_disk_config'] = utils.bool_from_str(auto_disk_config)
+ server['OS-DCF:diskConfig'] = utils.bool_from_str(auto_disk_config)
+
+ auto_disk_config = server_node.getAttribute('OS-DCF:diskConfig')
+ if auto_disk_config:
+ server['OS-DCF:diskConfig'] = utils.bool_from_str(auto_disk_config)
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")
+ node = self.find_first_child_named(server_node,
+ "OS-SCH-HNT:scheduler_hints")
+ # NOTE(vish): Support the os: prefix because it is what we use
+ # for json, even though OS-SCH-HNT: is more correct
+ if not node:
+ node = self.find_first_child_named(server_node,
+ "os:scheduler_hints")
if node:
scheduler_hints = {}
for child in self.extract_elements(node):
- scheduler_hints[child.nodeName] = self.extract_text(child)
+ scheduler_hints.setdefault(child.nodeName, [])
+ value = self.extract_text(child).strip()
+ scheduler_hints[child.nodeName].append(value)
return scheduler_hints
else:
return None
@@ -774,7 +789,7 @@ class Controller(wsgi.Controller):
auto_disk_config = server_dict.get('auto_disk_config')
scheduler_hints = {}
- if self.ext_mgr.is_loaded('os-scheduler-hints'):
+ if self.ext_mgr.is_loaded('OS-SCH-HNT'):
scheduler_hints = server_dict.get('scheduler_hints', {})
try: