From: smbaker Date: Mon, 5 Dec 2011 06:45:23 +0000 (-0800) Subject: fix bugs when adding and removing sliver attributes X-Git-Tag: sfa-2.0-2~1^2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e80760cd31b6b247f2841ba86a4828fa3be13e56;hp=07132527206726486e5df8c2df5806de53647272;p=sfa.git fix bugs when adding and removing sliver attributes --- diff --git a/sfa/rspecs/elements/versions/sfav1Sliver.py b/sfa/rspecs/elements/versions/sfav1Sliver.py index 8a113f34..f0375336 100644 --- a/sfa/rspecs/elements/versions/sfav1Sliver.py +++ b/sfa/rspecs/elements/versions/sfav1Sliver.py @@ -34,7 +34,7 @@ class SFAv1Sliver: for elem in xml.iterchildren(): if elem.tag not in Sliver.fields: xml_element = XmlElement(elem, xml.namespaces) - instance = Element(xml_element) + instance = Element(fields=xml_element, element=elem) instance['name'] = elem.tag instance['value'] = elem.text attribs.append(instance) diff --git a/sfa/rspecs/versions/sfav1.py b/sfa/rspecs/versions/sfav1.py index affab84f..8f172bd8 100644 --- a/sfa/rspecs/versions/sfav1.py +++ b/sfa/rspecs/versions/sfav1.py @@ -104,17 +104,20 @@ class SFAv1(BaseVersion): return attributes - def add_sliver_attribute(self, hostname, name, value, network=None): - nodes = self.get_nodes({'component_id': '*%s*' % hostname}) - if not nodes: + def add_sliver_attribute(self, component_id, name, value, network=None): + nodes = self.get_nodes({'component_id': '*%s*' % component_id}) + if nodes is not None and isinstance(nodes, list) and len(nodes) > 0: node = nodes[0] slivers = SFAv1Sliver.get_slivers(node) if slivers: sliver = slivers[0] - SFAv1Sliver.add_attribute(sliver, name, value) + SFAv1Sliver.add_sliver_attribute(sliver, name, value) + else: + # should this be an assert / raise an exception? + print "WARNING: failed to find component_id", component_id - def get_sliver_attributes(self, hostname, network=None): - nodes = self.get_nodes({'component_id': '*%s*' %hostname}) + def get_sliver_attributes(self, component_id, network=None): + nodes = self.get_nodes({'component_id': '*%s*' % component_id}) attribs = [] if nodes is not None and isinstance(nodes, list) and len(nodes) > 0: node = nodes[0] @@ -124,11 +127,13 @@ class SFAv1(BaseVersion): attribs = SFAv1Sliver.get_sliver_attributes(sliver.element) return attribs - def remove_sliver_attribute(self, hostname, name, value, network=None): - attribs = self.get_sliver_attributes(hostname) + def remove_sliver_attribute(self, component_id, name, value, network=None): + attribs = self.get_sliver_attributes(component_id) for attrib in attribs: if attrib['name'] == name and attrib['value'] == value: - attrib.element.delete() + #attrib.element.delete() + parent = attrib.element.getparent() + parent.remove(attrib.element) def add_default_sliver_attribute(self, name, value, network=None): if network: @@ -153,14 +158,12 @@ class SFAv1(BaseVersion): return SFAv1Sliver.get_sliver_attributes(defaults[0]) def remove_default_sliver_attribute(self, name, value, network=None): - if network: - defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network) - else: - defaults = self.xml.xpath("//sliver_defaults" % network) - attribs = SFAv1Sliver.get_sliver_attributes(defaults) + attribs = self.get_default_sliver_attributes(network) for attrib in attribs: if attrib['name'] == name and attrib['value'] == value: - attrib.element.delete() + #attrib.element.delete() + parent = attrib.element.getparent() + parent.remove(attrib.element) # Links