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
#First get the fields already defined in the class Node
fields = list(Node.fields)
#Extend it with senslab's specific fields
- fields.extend (['archi', 'radio', 'mobile'])
+ fields.extend (['archi', 'radio', 'mobile','position'])
-class SlabLocation(Location):
- fields = list(Location.fields)
- fields.extend (['hauteur'])
+class SlabPosition(Element):
+ fields = ['posx', 'posy','posz']
+
class Slabv1Node:
@staticmethod
def add_connection_information(xml, ldap_username):
- #Add network item in the xml
+ """ 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.
+
+ """
+
+ #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'
+ slab_network_dict['vm'] = 'ssh ' + ldap_username + \
+ '@grenoble.senslab.info'
network_elem.set('vm', unicode(slab_network_dict['vm']))
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
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)
# set location
if attribute is 'location':
node_elem.add_instance('location', node['location'], \
- SlabLocation.fields)
+ Location.fields)
# add granularity of the reservation system
#TODO put the granularity in network instead SA 18/07/12
if attribute is 'granularity' :
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
from sfa.planetlab.plxrn import PlXrn, hostname_to_urn, slicename_to_hrn
from sfa.rspecs.rspec import RSpec
-from sfa.rspecs.elements.versions.slabv1Node import SlabLocation
+from sfa.rspecs.elements.versions.slabv1Node import SlabPosition
from sfa.storage.alchemy import dbsession
from sfa.storage.model import RegRecord
-#from sfa.rspecs.elements.location import Location
+from sfa.rspecs.elements.location import Location
from sfa.rspecs.elements.hardware_type import HardwareType
from sfa.rspecs.elements.node import Node
#from sfa.rspecs.elements.login import Login
# add site/interface info to nodes.
# assumes that sites, interfaces and tags have already been prepared.
#site = sites_dict[node['site_id']]
-
- try:
- if node['posx'] and node['posy'] and node['posz']:
- location = SlabLocation()
- location['longitude'] = node['posx']
- location['latitude'] = node['posy']
- location['hauteur'] = node['posz']
+ location = Location({'country':'France'})
+ rspec_node['location'] = location
+
+
+ position = SlabPosition()
+ for field in position :
+ try:
+ position[field] = node[field]
+ logger.debug("SLABAGGREGATE\t get_rspecposition field %s position[field] %s "%(field, position[field]))
+ except KeyError, error :
+ logger.log_exc("SLABAGGREGATE\t get_rspec position %s "%(error))
- rspec_node['location'] = location
- except KeyError:
- pass
+ rspec_node['position'] = position
#rspec_node['interfaces'] = []
#if_count=0
#for if_id in node['interface_ids']: