from sfa.util.sfalogging import logger
from sfa.util.xml import XpathFilter
-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 NodeElement
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
- 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]
# 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)
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 = []
node.element.remove(sliver.element)
@staticmethod
- def get_nodes(xml, filter={}):
+ def get_nodes(xml, filter=None):
+ if filter is None: filter={}
xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter))
node_elems = xml.xpath(xpath)
return SFAv1Node.get_node_objs(node_elems)
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
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)
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'] = [hw_type.get_instance(HardwareType) for hw_type in hardware_type_elems]
+ 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']: