From 8d43c3fba1a5e07703cae6f7b631d0787c4f41bb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 18 Sep 2012 12:02:50 -0700 Subject: 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 --- .../openstack/compute/contrib/scheduler_hints.py | 14 ++++++------ nova/api/openstack/compute/servers.py | 25 +++++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'nova/api') 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: -- cgit