Merge branch 'geni-v3' of ssh://git.onelab.eu/git/sfa into geni-v3
[sfa.git] / sfa / iotlab / iotlabshell.py
index d885116..e546943 100644 (file)
@@ -20,7 +20,7 @@ from sfa.trust.certificate import Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 from sfa.trust.hierarchy import Hierarchy
 
-from sfa.iotlab.iotlabaggregate import iotlab_xrn_object
+from sfa.iotlab.iotlabxrn import xrn_object
 
 class IotlabShell():
     """ Class enabled to use LDAP and OAR api calls. """
@@ -36,8 +36,8 @@ class IotlabShell():
         :param config: configuration object from sfa.util.config
         :type config: Config object
         """
-        self.api=api
-        config=api.config
+        self.api = api
+        config = api.config
         self.leases_db = TestbedAdditionalSfaDB(config)
         self.oar = OARrestapi()
         self.ldap = LDAPapi()
@@ -814,6 +814,7 @@ class IotlabShell():
         :type slice_record: dict
         :type lease_start_time: integer
         :type lease_duration: integer
+        :returns: job_id, can be None if the job request failed.
 
         """
         logger.debug("IOTLAB_API \r\n \r\n \t AddLeases hostname_list %s  \
@@ -828,31 +829,32 @@ class IotlabShell():
                                     slice_record['hrn'], \
                                     lease_start_time, lease_duration, \
                                     username)
-        start_time = \
-                datetime.fromtimestamp(int(lease_start_time)).\
-                strftime(self.time_format)
-        end_time = lease_start_time + lease_duration
+        if job_id is not None:
+            start_time = \
+                    datetime.fromtimestamp(int(lease_start_time)).\
+                    strftime(self.time_format)
+            end_time = lease_start_time + lease_duration
 
 
-        logger.debug("IOTLAB_API \r\n \r\n \t AddLeases TURN ON LOGGING SQL \
-                        %s %s %s "%(slice_record['hrn'], job_id, end_time))
+            logger.debug("IOTLAB_API \r\n \r\n \t AddLeases TURN ON LOGGING SQL \
+                            %s %s %s "%(slice_record['hrn'], job_id, end_time))
 
 
-        logger.debug("IOTLAB_API \r\n \r\n \t AddLeases %s %s %s " \
-                %(type(slice_record['hrn']), type(job_id), type(end_time)))
+            logger.debug("IOTLAB_API \r\n \r\n \t AddLeases %s %s %s " \
+                    %(type(slice_record['hrn']), type(job_id), type(end_time)))
 
-        iotlab_ex_row = LeaseTableXP(slice_hrn = slice_record['hrn'], experiment_id=job_id,
-                                 end_time= end_time)
+            iotlab_ex_row = LeaseTableXP(slice_hrn = slice_record['hrn'], experiment_id=job_id,
+                                     end_time= end_time)
 
-        logger.debug("IOTLAB_API \r\n \r\n \t AddLeases iotlab_ex_row %s" \
-                %(iotlab_ex_row))
-        self.leases_db.testbed_session.add(iotlab_ex_row)
-        self.leases_db.testbed_session.commit()
+            logger.debug("IOTLAB_API \r\n \r\n \t AddLeases iotlab_ex_row %s" \
+                    %(iotlab_ex_row))
+            self.leases_db.testbed_session.add(iotlab_ex_row)
+            self.leases_db.testbed_session.commit()
 
-        logger.debug("IOTLAB_API \t AddLeases hostname_list start_time %s " \
-                %(start_time))
+            logger.debug("IOTLAB_API \t AddLeases hostname_list start_time %s " \
+                    %(start_time))
 
-        return
+        return job_id
 
 
     #Delete the jobs from job_iotlab table
@@ -985,7 +987,7 @@ class IotlabShell():
             #Transform the hostnames into urns (component ids)
             for node in resa['reserved_nodes']:
 
-                iotlab_xrn = iotlab_xrn_object(self.root_auth, node)
+                iotlab_xrn = xrn_object(self.root_auth, node)
                 resa['component_id_list'].append(iotlab_xrn.urn)
 
         if lease_filter_dict: