Cleaning and documenting cortexlabdriver.
[sfa.git] / sfa / cortexlab / cortexlabshell.py
index 94cb7d9..d68f635 100644 (file)
@@ -21,7 +21,8 @@ from sfa.trust.certificate import Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 from sfa.trust.hierarchy import Hierarchy
 
-from sfa.cortexlab.iotlabaggregate import iotlab_xrn_object
+from sfa.iotlab.iotlabaggregate import iotlab_xrn_object
+from sfa.cortexlab.cortexlabnodes import CortexlabQueryTestbed
 
 class CortexlabShell():
     """ Class enabled to use LDAP and OAR api calls. """
@@ -37,8 +38,8 @@ class CortexlabShell():
         :param config: configuration object from sfa.util.config
         :type config: Config object
         """
-        self.cortexlab_leases_db = TestbedAdditionalSfaDB(config)
-        self.query_sites = CortexlabQueryNodes()
+        self.leases_db = TestbedAdditionalSfaDB(config)
+        self.query_sites = CortexlabQueryTestbed()
         self.ldap = LDAPapi()
         self.time_format = "%Y-%m-%d %H:%M:%S"
         self.root_auth = config.SFA_REGISTRY_ROOT_AUTH
@@ -57,8 +58,8 @@ class CortexlabShell():
         """
         return CortexlabShell._MINIMUM_DURATION
 
-    @staticmethod
-    def GetPeers(peer_filter=None ):
+
+    def GetPeers(self, peer_filter=None ):
         """ Gathers registered authorities in SFA DB and looks for specific peer
         if peer_filter is specified.
         :param peer_filter: name of the site authority looked for.
@@ -275,10 +276,7 @@ class CortexlabShell():
         return_node_list = node_list_dict
         return return_node_list
 
-
-
-    @staticmethod
-    def AddSlice(slice_record, user_record):
+    def AddSlice(self, slice_record, user_record):
         """
 
         Add slice to the local cortexlab sfa tables if the slice comes
@@ -392,8 +390,8 @@ class CortexlabShell():
                     delete_failed))
         return delete_failed or True
 
-    @staticmethod
-    def __add_person_to_db(user_dict):
+
+    def __add_person_to_db(self, user_dict):
         """
         Add a federated user straight to db when the user issues a lease
         request with iotlab nodes and that he has not registered with cortexlab
@@ -679,8 +677,8 @@ class CortexlabShell():
 
         logger.debug("CORTEXLAB_API \r\n \r\n \t AddLeases testbed_xp_row %s" \
                 %(testbed_xp_row))
-        self.cortexlab_leases_db.testbed_session.add(testbed_xp_row)
-        self.cortexlab_leases_db.testbed_session.commit()
+        self.leases_db.testbed_session.add(testbed_xp_row)
+        self.leases_db.testbed_session.commit()
 
         logger.debug("CORTEXLAB_API \t AddLeases hostname_list start_time %s " \
                 %(start_time))
@@ -777,8 +775,8 @@ class CortexlabShell():
     #     deleted_jobs = set_jobs_psql.difference(kept_jobs)
     #     deleted_jobs = list(deleted_jobs)
     #     if len(deleted_jobs) > 0:
-    #         self.cortexlab_leases_db.testbed_session.query(LeaseTableXP).filter(LeaseTableXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch')
-    #         self.cortexlab_leases_db.testbed_session.commit()
+    #         self.leases_db.testbed_session.query(LeaseTableXP).filter(LeaseTableXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch')
+    #         self.leases_db.testbed_session.commit()
 
     #     return
 
@@ -892,7 +890,7 @@ class CortexlabShell():
         #the same user in LDAP SA 27/07/12
 
 
-        db_xp_query = self.cortexlab_leases_db.testbed_session.query(LeaseTableXP).all()
+        db_xp_query = self.leases_db.testbed_session.query(LeaseTableXP).all()
         db_xp_dict = dict([(row.experiment_id, row.__dict__)
                                for row in db_xp_query])
 
@@ -938,7 +936,7 @@ class CortexlabShell():
         if lease_filter_dict is None:
             reservation_list = unfiltered_reservation_list
 
-        self.cortexlab_leases_db.update_experiments_in_additional_sfa_db(
+        self.leases_db.update_experiments_in_additional_sfa_db(
             testbed_xp_list, db_xp_id_list)
 
         logger.debug(" CORTEXLAB_API.PY \tGetLeases reservation_list %s"
@@ -1020,14 +1018,14 @@ class CortexlabShell():
 
         #"""
         ##new_row = FederatedToIotlab(iotlab_hrn, federated_hrn)
-        ##self.cortexlab_leases_db.testbed_session.add(new_row)
-        ##self.cortexlab_leases_db.testbed_session.commit()
+        ##self.leases_db.testbed_session.add(new_row)
+        ##self.leases_db.testbed_session.commit()
 
         #logger.debug("CORTEXLAB_API UpdatePerson EMPTY - DO NOTHING \r\n ")
         #return
 
-    @staticmethod
-    def GetKeys(key_filter=None):
+
+    def GetKeys(self, key_filter=None):
         """Returns a dict of dict based on the key string. Each dict entry
         contains the key id, the ssh key, the user's email and the
         user's hrn.
@@ -1081,10 +1079,7 @@ class CortexlabShell():
         return ret['bool']
 
 
-
-
-    @staticmethod
-    def _sql_get_slice_info(slice_filter):
+    def _sql_get_slice_info(self, slice_filter):
         """
         Get the slice record based on the slice hrn. Fetch the record of the
         user associated with the slice by using joinedload based on the
@@ -1120,8 +1115,8 @@ class CortexlabShell():
         else:
             return None
 
-    @staticmethod
-    def _sql_get_slice_info_from_user(slice_filter):
+
+    def _sql_get_slice_info_from_user(self, slice_filter):
         """
         Get the slice record based on the user recordid by using a joinedload
         on the relationship reg_slices_as_researcher. Format the sql record