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.rspecs.elements.element import Element
from sfa.rspecs.elements.node import Node
from sfa.rspecs.elements.sliver import Sliver
from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag
from sfa.rspecs.elements.versions.pgv2Services import PGv2Services
+from sfa.planetlab.plxrn import xrn_to_hostname
+
class SFAv1Node:
@staticmethod
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
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)
PGv2Services.add_services(node_elem, node.get('services', []))
- for tag in node.get('tags', []):
- tag_elem = node_elem.add_element(tag['tagname'])
- tag_elem.set_text(tag['value'])
+ tags = node.get('tags', [])
+ if tags:
+ for tag in tags:
+ tag_elem = node_elem.add_element(tag['tagname'])
+ tag_elem.set_text(tag['value'])
SFAv1Sliver.add_slivers(node_elem, node.get('slivers', []))
@staticmethod
for hostname in hostnames:
nodes = SFAv1Node.get_nodes(xml, {'component_id': '*%s*' % hostname})
for node in nodes:
- slivers = SFAv1Slivers.get_slivers(node.element)
+ slivers = SFAv1Sliver.get_slivers(node.element)
for sliver in slivers:
node.element.remove(sliver.element)
# get slivers
node['slivers'] = SFAv1Sliver.get_slivers(node_elem)
# get tags
- node['tags'] = SFAv1PLTag.get_pl_tags(node_elem, ignore=Node.fields)
-
- parent = node_elem.getparent()
- if (parent != None) and (parent.tag=="network") and ("name" in parent.attrib):
- node['network_name'] = parent.attrib['name']
+ node['tags'] = SFAv1PLTag.get_pl_tags(node_elem, ignore=Node.fields+["hardware_type"])
+ # get hardware types
+ hardware_type_elems = node_elem.xpath('./default:hardware_type | ./hardware_type')
+ node['hardware_types'] = [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']:
+ hostname_elem = node_elem.find("hostname")
+ if hostname_elem != None:
+ node['component_name'] = hostname_elem.text
nodes.append(node)
return nodes