From: Sandrine Avakian Date: Mon, 23 Jul 2012 09:16:16 +0000 (+0200) Subject: Added field position in Slab RSpec , which include posx , posy X-Git-Tag: sfa-2.1-24~3^2~115 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e71c5ab5bf1aaa5428df793d5c5e8e602994be5d;p=sfa.git Added field position in Slab RSpec , which include posx , posy and posz for each node. Location field is supposed to hold the position of the senslab's site (Grenoble, Strasbourg...). --- diff --git a/sfa/rspecs/elements/versions/slabv1Node.py b/sfa/rspecs/elements/versions/slabv1Node.py index 5734c0ac..d32ab1ec 100644 --- a/sfa/rspecs/elements/versions/slabv1Node.py +++ b/sfa/rspecs/elements/versions/slabv1Node.py @@ -5,7 +5,7 @@ from sfa.rspecs.elements.node import Node 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 @@ -14,29 +14,36 @@ class SlabNode(Node): #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): @@ -46,7 +53,8 @@ class Slabv1Node: 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 @@ -56,7 +64,7 @@ class Slabv1Node: 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) @@ -79,7 +87,7 @@ class Slabv1Node: # 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' : @@ -98,7 +106,10 @@ class Slabv1Node: 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 @@ -124,7 +135,6 @@ class Slabv1Node: 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 diff --git a/sfa/senslab/slabaggregate.py b/sfa/senslab/slabaggregate.py index 4bddc8d6..e767ab60 100644 --- a/sfa/senslab/slabaggregate.py +++ b/sfa/senslab/slabaggregate.py @@ -8,10 +8,10 @@ from sfa.util.xrn import hrn_to_urn, urn_to_hrn, urn_to_sliver_id 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 @@ -197,17 +197,19 @@ class SlabAggregate: # 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']: