X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Fversions%2Fsfav1.py;h=964da059d319c8530a9bbd4631080b7186a0e8df;hb=fa77e36e57e78fb3f589818782cbdf327414fee5;hp=affab84fb42cf17d65f424a248d5efce73154e8c;hpb=90ab94deecf2371c199d56cd35f0fd4fd20233e4;p=sfa.git diff --git a/sfa/rspecs/versions/sfav1.py b/sfa/rspecs/versions/sfav1.py index affab84f..964da059 100644 --- a/sfa/rspecs/versions/sfav1.py +++ b/sfa/rspecs/versions/sfav1.py @@ -3,14 +3,13 @@ from lxml import etree from sfa.util.sfalogging import logger from sfa.util.xrn import hrn_to_urn, urn_to_hrn -from sfa.util.plxrn import PlXrn -from sfa.rspecs.baseversion import BaseVersion +from sfa.rspecs.version import RSpecVersion from sfa.rspecs.elements.element import Element from sfa.rspecs.elements.versions.pgv2Link import PGv2Link from sfa.rspecs.elements.versions.sfav1Node import SFAv1Node from sfa.rspecs.elements.versions.sfav1Sliver import SFAv1Sliver -class SFAv1(BaseVersion): +class SFAv1(RSpecVersion): enabled = True type = 'SFA' content_type = '*' @@ -93,6 +92,7 @@ class SFAv1(BaseVersion): attributes = [] nodes_with_slivers = self.get_nodes_with_slivers() for default_attribute in self.get_default_sliver_attributes(network): + attribute = default_attribute.copy() attribute['node_id'] = None attributes.append(attribute) for node in nodes_with_slivers: @@ -100,21 +100,24 @@ class SFAv1(BaseVersion): sliver_attributes = self.get_sliver_attributes(nodename, network) for sliver_attribute in sliver_attributes: sliver_attribute['node_id'] = nodename - attributes.append(attribute) + attributes.append(sliver_attribute) 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? + logger.error("WARNING: failed to find component_id %s" % 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,19 +127,24 @@ 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: defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network) else: - defaults = self.xml.xpath("//sliver_defaults" % network) - if not defaults : - network_tag = self.xml.xpath("//network[@name='%s']" % network) + defaults = self.xml.xpath("//sliver_defaults") + if not defaults: + if network: + network_tag = self.xml.xpath("//network[@name='%s']" % network) + else: + network_tag = self.xml.xpath("//network") if isinstance(network_tag, list): network_tag = network_tag[0] defaults = network_tag.add_element('sliver_defaults') @@ -153,14 +161,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 @@ -188,6 +194,9 @@ class SFAv1(BaseVersion): Merge contents for specified rspec with current rspec """ + if not in_rspec: + return + from sfa.rspecs.rspec import RSpec if isinstance(in_rspec, RSpec): rspec = in_rspec