-from sfa.planetlab.plxrn import xrn_to_hostname
+
from sfa.util.xrn import Xrn
from sfa.util.xml import XpathFilter
-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
-
+from sfa.rspecs.elements.element import Element
from sfa.rspecs.elements.interface import Interface
from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver
from sfa.util.sfalogging import logger
-class SlabNode(Node):
+class SlabNode(NodeElement):
#First get the fields already defined in the class Node
- fields = list(Node.fields)
+ fields = list(NodeElement.fields)
#Extend it with senslab's specific fields
- fields.extend (['archi', 'radio', 'mobile'])
+ fields.extend (['archi', 'radio', 'mobile','position'])
+class SlabPosition(Element):
+ fields = ['posx', 'posy','posz']
+
class SlabLocation(Location):
fields = list(Location.fields)
- fields.extend (['hauteur'])
+ fields.extend (['site'])
+
+
class Slabv1Node:
@staticmethod
- def add_connection_information(xml, ldap_username):
- #Add network item in the xml
+ def add_connection_information(xml, ldap_username, sites_set):
+ """ Adds login and ssh connection info in the network item in
+ the xml. Does not create the network element, therefore
+ should be used after add_nodes, which creates the network item.
+
+ """
+ logger.debug(" add_connection_information " )
+ #Get network item in the xml
network_elems = xml.xpath('//network')
if len(network_elems) > 0:
network_elem = network_elems[0]
slab_network_dict = {}
slab_network_dict['login'] = ldap_username
- slab_network_dict['vm'] = 'ssh ' + ldap_username + '@grenoble.senslab.info'
- network_elem.set('vm', unicode(slab_network_dict['vm']))
+
+ slab_network_dict['ssh'] = \
+ ['ssh ' + ldap_username + '@'+site+'.senslab.info' \
+ for site in sites_set]
+ network_elem.set('ssh', \
+ unicode(slab_network_dict['ssh']))
network_elem.set('login', unicode( slab_network_dict['login']))
- logger.debug("\r\n \r\n \r\n Slabv1Node add_connection_information hrn %s\r\n \r\n \r\n " %(ldap_username))
+
@staticmethod
def add_nodes(xml, nodes):
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
- logger.debug("slabv1Node \t add_nodes nodes %s \r\n "%(nodes))
+ logger.debug("slabv1Node \t add_nodes nodes %s \r\n "%(nodes[0]))
node_elems = []
#Then add nodes items to the network item in the xml
for node in nodes:
#Attach this node to the network element
node_fields = ['component_manager_id', 'component_id', 'exclusive',\
- 'boot_state', 'mobile']
+ 'boot_state', 'mobile']
node_elem = network_elem.add_instance('node', node, node_fields)
node_elems.append(node_elem)
for attribute in node:
# set component name
if attribute is 'component_id':
- component_name = xrn_to_hostname(node['component_id'])
+ component_name = node['component_name']
node_elem.set('component_name', component_name)
# set hardware types, extend fields to add Senslab's architecture
available_elem = node_elem.add_element('available', \
now='false')
-
+ #set position
+ if attribute is 'position':
+ node_elem.add_instance('position', node['position'], \
+ SlabPosition.fields)
## add services
#PGv2Services.add_services(node_elem, node.get('services', []))
# add slivers
xpath = '//node%s | //default:node%s' % (XpathFilter.xpath(filter), \
XpathFilter.xpath(filter))
node_elems = xml.xpath(xpath)
- #logger.debug("SLABV1NODE \tget_nodes \tnode_elems %s"%(node_elems))
return Slabv1Node.get_node_objs(node_elems)
@staticmethod
node_elems = xml.xpath(xpath)
logger.debug("SLABV1NODE \tget_nodes_with_slivers \
node_elems %s"%(node_elems))
- return Slabv1Node.get_node_objs(node_elems)
+ return Slabv1Node.get_node_objs(node_elems)
@staticmethod
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)
nodes.append(node)
if 'component_id' in node_elem.attrib:
node['authority_id'] = \
for location_elem in location_elems]
if len(locations) > 0:
node['location'] = locations[0]
-
+
+
# get interfaces
iface_elems = node_elem.xpath('./default:interface | ./interface')
node['interfaces'] = [iface_elem.get_instance(Interface) \
node['boot_state'] = 'boot'
else:
node['boot_state'] = 'disabled'
+
+ logger.debug("SLABV1NODE \tget_nodes_objs \
+ #nodes %s"%(nodes))
return nodes