From 6a951c77adf6d513a434bf65d46e3a0745b750f7 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 16 Feb 2012 00:13:41 -0800 Subject: The security_group name should be an XML attribute It is everywhere apart from in servers.py. We have to be backwards compatible, so we check the attribute first, and then check the element. Bug #933785 Change-Id: I66b96376043e665a026eff5c33aa0731a81730cc --- nova/api/openstack/compute/servers.py | 6 +++--- nova/api/openstack/wsgi.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 87e66b71f..26ed42f20 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -222,9 +222,9 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): security_groups = [] for sg_node in self.find_children_named(node, "security_group"): item = {} - name_node = self.find_first_child_named(sg_node, "name") - if name_node: - item["name"] = self.extract_text(name_node) + name = self.find_attribute_or_element(sg_node, 'name') + if name: + item["name"] = name security_groups.append(item) return security_groups else: diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index c86d86a5f..c887701a7 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -200,6 +200,17 @@ class XMLDeserializer(TextDeserializer): return child.nodeValue return "" + def find_attribute_or_element(self, parent, name): + """Get an attribute value; fallback to an element if not found""" + if parent.hasAttribute(name): + return parent.getAttribute(name) + + node = self.find_first_child_named(parent, name) + if node: + return self.extract_text(node) + + return None + def default(self, datastring): return {'body': self._from_xml(datastring)} -- cgit