X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Felements%2Fversions%2Fsfav1Node.py;h=510769858d5b7f3e9edee53c9303e3e9084b0bf6;hb=ed21507f990ecf9c49887283fb44e9c92a8624f9;hp=753192dd704fcdadfaf7e40ac5ca676f98b60363;hpb=90ab94deecf2371c199d56cd35f0fd4fd20233e4;p=sfa.git diff --git a/sfa/rspecs/elements/versions/sfav1Node.py b/sfa/rspecs/elements/versions/sfav1Node.py index 753192dd..51076985 100644 --- a/sfa/rspecs/elements/versions/sfav1Node.py +++ b/sfa/rspecs/elements/versions/sfav1Node.py @@ -1,9 +1,9 @@ from sfa.util.sfalogging import logger from sfa.util.xml import XpathFilter -from sfa.util.plxrn import PlXrn, xrn_to_hostname -from sfa.util.xrn import Xrn +from sfa.util.xrn import Xrn, get_leaf + from sfa.rspecs.elements.element import Element -from sfa.rspecs.elements.node import Node +from sfa.rspecs.elements.node import NodeElement from sfa.rspecs.elements.sliver import Sliver from sfa.rspecs.elements.location import Location from sfa.rspecs.elements.hardware_type import HardwareType @@ -15,16 +15,17 @@ from sfa.rspecs.elements.versions.sfav1Sliver import SFAv1Sliver from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag from sfa.rspecs.elements.versions.pgv2Services import PGv2Services + class SFAv1Node: @staticmethod - def add_nodes(xml, nodes): + def add_nodes(xml, nodes, rspec_content_type=None): network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] elif len(nodes) > 0 and nodes[0].get('component_manager_id'): network_urn = nodes[0]['component_manager_id'] - network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn()) + network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn()) else: network_elem = xml @@ -41,7 +42,7 @@ class SFAv1Node: # set component_name attribute and hostname element if 'component_id' in node and node['component_id']: - component_name = xrn_to_hostname(node['component_id']) + component_name = Xrn.unescape(get_leaf(Xrn(node['component_id']).get_hrn())) node_elem.set('component_name', component_name) hostname_elem = node_elem.add_element('hostname') hostname_elem.set_text(component_name) @@ -55,8 +56,21 @@ class SFAv1Node: if location: node_elem.add_instance('location', location, Location.fields) - for interface in node.get('interfaces', []): - node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4']) + # add exclusive tag to distinguish between Reservable and Shared nodes + exclusive_elem = node_elem.add_element('exclusive') + if node.get('exclusive') and node.get('exclusive') == 'true': + exclusive_elem.set_text('TRUE') + # add granularity of the reservation system + granularity = node.get('granularity') + if granularity: + node_elem.add_instance('granularity', granularity, granularity.fields) + else: + exclusive_elem.set_text('FALSE') + + + if isinstance(node.get('interfaces'), list): + for interface in node.get('interfaces', []): + node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4']) #if 'bw_unallocated' in node and node['bw_unallocated']: # bw_unallocated = etree.SubElement(node_elem, 'bw_unallocated', units='kbps').text = str(int(node['bw_unallocated'])/1000) @@ -65,10 +79,24 @@ class SFAv1Node: tags = node.get('tags', []) if tags: for tag in tags: - tag_elem = node_elem.add_element(tag['tagname']) - tag_elem.set_text(tag['value']) + # backdoor for FITeagle + # Alexander Willner + if tag['tagname']=="fiteagle_settings": + tag_elem = node_elem.add_element(tag['tagname']) + for subtag in tag['value']: + subtag_elem = tag_elem.add_element('setting') + subtag_elem.set('name', str(subtag['tagname'])) + subtag_elem.set('description', str(subtag['description'])) + subtag_elem.set_text(subtag['value']) + else: + tag_elem = node_elem.add_element(tag['tagname']) + tag_elem.set_text(tag['value']) SFAv1Sliver.add_slivers(node_elem, node.get('slivers', [])) + # add sliver tag in Request Rspec + if rspec_content_type == "request": + node_elem.add_instance('sliver', '', []) + @staticmethod def add_slivers(xml, slivers): component_ids = [] @@ -113,12 +141,12 @@ class SFAv1Node: def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: - node = Node(node_elem.attrib, node_elem) + node = NodeElement(node_elem.attrib, node_elem) if 'site_id' in node_elem.attrib: node['authority_id'] = node_elem.attrib['site_id'] # get location location_elems = node_elem.xpath('./default:location | ./location') - locations = [loc_elem.get_instance(Location) for loc_elem in location_elems] + locations = [dict(loc_elem.get_instance(Location)) for loc_elem in location_elems] if len(locations) > 0: node['location'] = locations[0] # get bwlimit @@ -128,14 +156,17 @@ class SFAv1Node: node['bwlimit'] = bwlimits[0] # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') - ifaces = [iface_elem.get_instance(Interface) for iface_elem in iface_elems] + ifaces = [dict(iface_elem.get_instance(Interface)) for iface_elem in iface_elems] node['interfaces'] = ifaces # get services node['services'] = PGv2Services.get_services(node_elem) # get slivers node['slivers'] = SFAv1Sliver.get_slivers(node_elem) # get tags - node['tags'] = SFAv1PLTag.get_pl_tags(node_elem, ignore=Node.fields) + node['tags'] = SFAv1PLTag.get_pl_tags(node_elem, ignore=NodeElement.fields+["hardware_type"]) + # get hardware types + hardware_type_elems = node_elem.xpath('./default:hardware_type | ./hardware_type') + node['hardware_types'] = [dict(hw_type.get_instance(HardwareType)) for hw_type in hardware_type_elems] # temporary... play nice with old slice manager rspec if not node['component_name']: