From: Sandrine Avakian Date: Thu, 19 Jul 2012 14:45:57 +0000 (+0200) Subject: Added hardware_types in slab RSpec, as well as X-Git-Tag: sfa-2.1-24~3^2~117 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=387918d363490c56840f3c8a7e235065bda3824a;p=sfa.git Added hardware_types in slab RSpec, as well as connection information (login and ssh to the senslab info) upon slice/job creation. --- diff --git a/sfa/rspecs/elements/versions/slabv1Node.py b/sfa/rspecs/elements/versions/slabv1Node.py index 5eca79da..5734c0ac 100644 --- a/sfa/rspecs/elements/versions/slabv1Node.py +++ b/sfa/rspecs/elements/versions/slabv1Node.py @@ -7,7 +7,6 @@ from sfa.rspecs.elements.location import Location from sfa.rspecs.elements.hardware_type import HardwareType from sfa.rspecs.elements.interface import Interface - from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver from sfa.util.sfalogging import logger @@ -15,10 +14,30 @@ 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']) + +class SlabLocation(Location): + fields = list(Location.fields) + fields.extend (['hauteur']) + + class Slabv1Node: + + @staticmethod + def add_connection_information(xml, ldap_username): + #Add 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'])) + 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): #Add network item in the xml @@ -30,79 +49,82 @@ class Slabv1Node: network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn()) else: network_elem = xml - - logger.debug("slabv1Node \t add_nodes nodes %s"%(nodes)) + + logger.debug("slabv1Node \t add_nodes nodes %s \r\n "%(nodes)) 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'] node_elem = network_elem.add_instance('node', node, node_fields) node_elems.append(node_elem) + + #Set the attibutes of this node element + for attribute in node: # set component name - if node.get('component_id'): - component_name = xrn_to_hostname(node['component_id']) - node_elem.set('component_name', component_name) - # set hardware types - if node.get('hardware_types'): - for hardware_type in node.get('hardware_types', []): - fields = HardwareType.fields - fields.extend(['archi','radio']) - node_elem.add_instance('hardware_type', node, fields) + if attribute is 'component_id': + component_name = xrn_to_hostname(node['component_id']) + node_elem.set('component_name', component_name) + + # set hardware types, extend fields to add Senslab's architecture + #and radio type + + if attribute is 'hardware_types': + for hardware_type in node.get('hardware_types', []): + fields = HardwareType.fields + fields.extend(['archi','radio']) + node_elem.add_instance('hardware_types', node, fields) # set location - if node.get('location'): - node_elem.add_instance('location', node['location'], \ - Location.fields) + if attribute is 'location': + node_elem.add_instance('location', node['location'], \ + SlabLocation.fields) # add granularity of the reservation system - granularity = node.get('granularity') - if granularity: - node_elem.add_instance('granularity', granularity, granularity.fields) + #TODO put the granularity in network instead SA 18/07/12 + if attribute is 'granularity' : + granularity = node['granularity'] + if granularity: + node_elem.add_instance('granularity', \ + granularity, granularity.fields) - # set interfaces - #if node.get('interfaces'): - #for interface in node.get('interfaces', []): - #node_elem.add_instance('interface', interface, ['component_id', 'client_id']) + # set available element - if node.get('boot_state'): - if node.get('boot_state').lower() == 'alive': - available_elem = node_elem.add_element('available', \ + if attribute is 'boot_state': + if node.get('boot_state').lower() == 'alive': + available_elem = node_elem.add_element('available', \ now='true') - else: - available_elem = node_elem.add_element('available', \ + else: + available_elem = node_elem.add_element('available', \ now='false') - - #if node.get('archi'): - #archi_elem = node_elem.add_instance('archi',node.get('archi') , ['archi']) - - - #if node.get('radio'): - #radio_elem = node_elem.add_instance('radio', node.get('radio') , ['radio']) ## add services #PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers - slivers = node.get('slivers', []) - if not slivers: - # we must still advertise the available sliver types - slivers = Sliver({'type': 'slab-node'}) - # we must also advertise the available initscripts - #slivers['tags'] = [] - #if node.get('pl_initscripts'): - #for initscript in node.get('pl_initscripts', []): - #slivers['tags'].append({'name': 'initscript', \ - #'value': initscript['name']}) + if attribute is 'slivers': + slivers = node.get('slivers', []) + if not slivers: + # we must still advertise the available sliver types + slivers = Sliver({'type': 'slab-node'}) + # we must also advertise the available initscripts + #slivers['tags'] = [] + #if node.get('pl_initscripts'): + #for initscript in node.get('pl_initscripts', []): + #slivers['tags'].append({'name': 'initscript', \ + #'value': initscript['name']}) - Slabv1Sliver.add_slivers(node_elem, slivers) + Slabv1Sliver.add_slivers(node_elem, slivers) return node_elems + + @staticmethod def get_nodes(xml, filter={}): 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)) + #logger.debug("SLABV1NODE \tget_nodes \tnode_elems %s"%(node_elems)) return Slabv1Node.get_node_objs(node_elems) @staticmethod diff --git a/sfa/rspecs/versions/slabv1.py b/sfa/rspecs/versions/slabv1.py index 53d119a8..f02bad38 100644 --- a/sfa/rspecs/versions/slabv1.py +++ b/sfa/rspecs/versions/slabv1.py @@ -58,9 +58,12 @@ class Slabv1(RSpecVersion): def get_slice_timeslot(self ): return Slabv1Timeslot.get_slice_timeslot(self.xml) - + + def add_connection_information(self, ldap_username): + return Slabv1Node.add_connection_information(self.xml,ldap_username) + def add_nodes(self, nodes, check_for_dupes=False): - return Slabv1Node.add_nodes(self.xml, nodes) + return Slabv1Node.add_nodes(self.xml,nodes ) def merge_node(self, source_node_tag, network, no_dupes = False): logger.debug("SLABV1 merge_node") diff --git a/sfa/senslab/slabaggregate.py b/sfa/senslab/slabaggregate.py index c471b554..4bddc8d6 100644 --- a/sfa/senslab/slabaggregate.py +++ b/sfa/senslab/slabaggregate.py @@ -8,7 +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.location import Location +from sfa.rspecs.elements.versions.slabv1Node import SlabLocation +from sfa.storage.alchemy import dbsession +from sfa.storage.model import RegRecord +#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 @@ -196,9 +199,12 @@ class SlabAggregate: #site = sites_dict[node['site_id']] try: - if node['posx'] and node['posy']: - location = Location({'longitude':node['posx'], \ - 'latitude': node['posy']}) + if node['posx'] and node['posy'] and node['posz']: + location = SlabLocation() + location['longitude'] = node['posx'] + location['latitude'] = node['posy'] + location['hauteur'] = node['posz'] + rspec_node['location'] = location except KeyError: pass @@ -232,7 +238,7 @@ class SlabAggregate: #service = Services({'login': login}) #rspec_node['services'] = [service] rspec_nodes.append(rspec_node) - logger.debug("SLABAGGREGATE \t get_nodes rspec_nodes %s"%(rspec_nodes)) + #logger.debug("SLABAGGREGATE \t get_nodes rspec_nodes %s"%(rspec_nodes)) return (rspec_nodes) def get_leases(self, slice_record = None, options = {}): @@ -309,17 +315,31 @@ class SlabAggregate: #rspec.xml.set('expires', datetime_to_epoch(slice['expires'])) # add sliver defaults #nodes, links = self.get_nodes(slice, slivers) + logger.debug("\r\n \r\n SlabAggregate \tget_rspec ******* slice_xrn %s \r\n \r\n"\ + %(slice_xrn)) if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases': nodes = self.get_nodes(slices, slivers) + #In case creating a job slice _xrn is not set to None rspec.version.add_nodes(nodes) - logger.debug("SlabAggregate \tget_rspec ******* nodes %s \r\n"\ - %(nodes)) + if slice_xrn : + #Get user associated with this slice + #user = dbsession.query(RegRecord).filter_by(record_id = \ + #slices['record_id_user']).first() + + #ldap_username = (user.hrn).split('.')[1] + ldap_username = slices['slice_hrn'] + tmp = ldap_username.split('.') + ldap_username = tmp[1].split('_')[0] + logger.debug("SlabAggregate \tget_rspec **** \ + ldap_username %s \r\n" %(ldap_username)) + rspec.version.add_connection_information(ldap_username) + default_sliver = slivers.get(None, []) if default_sliver: default_sliver_attribs = default_sliver.get('tags', []) logger.debug("SlabAggregate \tget_rspec **** \ default_sliver_attribs %s \r\n" %(default_sliver_attribs)) - for attrib in default_sliver_attribs: + for attrib in default_dbsessionsliver_attribs: rspec.version.add_default_sliver_attribute(attrib['tagname'], \ diff --git a/sfa/senslab/slabdriver.py b/sfa/senslab/slabdriver.py index 01b8433b..e7add076 100644 --- a/sfa/senslab/slabdriver.py +++ b/sfa/senslab/slabdriver.py @@ -266,7 +266,6 @@ class SlabDriver(Driver): #return rspec #panos: passing user-defined options - logger.debug("SLABDRIVER \tlist_resources rspec " ) aggregate = SlabAggregate(self) origin_hrn = Credential(string=creds[0]).get_gid_caller().get_hrn() options.update({'origin_hrn':origin_hrn}) @@ -537,8 +536,8 @@ class SlabDriver(Driver): answer = self.oar.POSTRequestToOARRestAPI('DELETE_jobs_id', \ reqdict,username) - logger.debug("SLABDRIVER \tDeleteJobs jobid %s \r\n answer %s " \ - %(job_id,answer)) + logger.debug("SLABDRIVER \tDeleteJobs jobid %s \r\n answer %s username %s" \ + %(job_id,answer, username)) return answer