First draft,
authorSandrine Avakian <sandrine.avakian@inria.fr>
Tue, 17 Jul 2012 14:11:50 +0000 (16:11 +0200)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Tue, 17 Jul 2012 14:11:50 +0000 (16:11 +0200)
Added specific senslab options in RSpec : mobile, radio and archi.
mobile is at the same level as the node hostname and component_id.
Radio and archi are inside hardware_type.
Done by using new class SlabNode along with new fields,
heriting from the Node class.

sfa/rspecs/elements/versions/slabv1Node.py
sfa/rspecs/versions/slabv1.py
sfa/senslab/slabaggregate.py

index cf567b3..5eca79d 100644 (file)
@@ -11,7 +11,13 @@ from sfa.rspecs.elements.interface import Interface
 from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver
 from sfa.util.sfalogging import logger
 
-
+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'])
+    
+    
 class Slabv1Node:
     @staticmethod
     def add_nodes(xml, nodes):
@@ -25,12 +31,12 @@ class Slabv1Node:
         else:
             network_elem = xml
             
-        logger.debug("slabv1Node \t add_nodes")
+        logger.debug("slabv1Node \t add_nodes nodes %s"%(nodes))
         node_elems = []
         #Then add nodes items to the network item in the xml
         for node in nodes:
-            node_fields = ['component_manager_id', 'component_id', \
-                        'client_id', 'sliver_id', 'exclusive','boot_state']
+            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 component name
@@ -40,8 +46,10 @@ class Slabv1Node:
             # set hardware types
             if node.get('hardware_types'):
                 for hardware_type in node.get('hardware_types', []): 
-                    node_elem.add_instance('hardware_type', hardware_type, \
-                                                    HardwareType.fields)
+                    fields = HardwareType.fields
+                    fields.extend(['archi','radio'])
+                    node_elem.add_instance('hardware_type', node, fields)
+
             # set location
             if node.get('location'):
                 node_elem.add_instance('location', node['location'], \
@@ -63,7 +71,15 @@ class Slabv1Node:
                 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
@@ -72,11 +88,11 @@ class Slabv1Node:
                 # 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']})
+                #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)
         return node_elems
index 035f7d9..53d119a 100644 (file)
@@ -30,11 +30,12 @@ class Slabv1(RSpecVersion):
     
     # Network 
     def get_networks(self):
+        #WARNING Added //default:network to the xpath 
+        #otherwise network element not detected 16/07/12 SA
+        
         network_elems = self.xml.xpath('//network | //default:network') 
-        logger.debug(" slabv1 \tget_networks network_elems %s  "%(network_elems) )
         networks = [network_elem.get_instance(fields=['name', 'slice']) for \
                     network_elem in network_elems]
-        logger.debug(" slabv1 \tget_networks  %s"%(networks))
         return networks    
 
 
@@ -218,13 +219,10 @@ class Slabv1(RSpecVersion):
             from sfa.rspecs.rspec_converter import RSpecConverter
             in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml())
             rspec = RSpec(in_rspec)
-        logger.debug(" SLABV1 \tmerge rspec %s " %(rspec.toxml()) )
         # just copy over all networks
         #Attention special get_networks using //default:network xpath
         current_networks = self.get_networks() 
-        logger.debug(" SLABV1\tmerge rspec version %s" %(rspec.version))
         networks = rspec.version.get_networks()
-        logger.debug("SLABV1 \tmerge current_networks %s networks  %s " %(current_networks, networks) ) 
         for network in networks:
             current_network = network.get('name')
             if current_network and current_network not in current_networks:
index bd277ab..c471b55 100644 (file)
@@ -20,7 +20,7 @@ from sfa.rspecs.version_manager import VersionManager
 
 #from sfa.util.sfatime import datetime_to_epoch
 
-
+from sfa.rspecs.elements.versions.slabv1Node import SlabNode
 from sfa.util.sfalogging import logger
 
 
@@ -158,10 +158,14 @@ class SlabAggregate:
             #if node['slice_ids_whitelist']:
                 #if not slice or slice['slice_id'] not in node['slice_ids_whitelist']:
                     #continue
-            rspec_node = Node()
+            #rspec_node = Node()
+            rspec_node = SlabNode()
             # xxx how to retrieve site['login_base']
             #site_id=node['site_id']
             #site=sites_dict[site_id]
+            rspec_node['mobile'] = node['mobile']
+            rspec_node['archi'] = node['archi']
+            rspec_node['radio'] = node['radio']
             rspec_node['component_id'] = \
                                         hostname_to_urn(self.driver.root_auth, \
                                         node['site'], node['hostname'])
@@ -228,7 +232,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))
         return (rspec_nodes)       
 
     def get_leases(self, slice_record = None, options = {}):
@@ -254,7 +258,8 @@ class SlabAggregate:
                                         site, node['hostname'])
                 rspec_lease['slice_id'] = lease['slice_id']
                 rspec_lease['start_time'] = lease['t_from']
-                rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) / grain   
+                rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) \
+                                                                    / grain   
                 rspec_leases.append(rspec_lease)
         return rspec_leases    
         
@@ -295,7 +300,8 @@ class SlabAggregate:
                                                 version.version, 'manifest')
            
         slices, slivers = self.get_slice_and_slivers(slice_xrn)
-        #at this point sliver may be empty if no senslab job is running for this user/slice.
+        #at this point sliver may be empty if no senslab job 
+        #is running for this user/slice.
         rspec = RSpec(version=rspec_version, user_options=options)
 
         
@@ -306,7 +312,8 @@ class SlabAggregate:
         if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases':
             nodes = self.get_nodes(slices, slivers) 
             rspec.version.add_nodes(nodes)
-
+            logger.debug("SlabAggregate \tget_rspec ******* nodes %s \r\n"\
+                                            %(nodes)) 
             default_sliver = slivers.get(None, [])
             if default_sliver:
                 default_sliver_attribs = default_sliver.get('tags', [])