X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fiotlab%2Fiotlabapi.py;h=f50441d379487a9034b0719c5771421fc1159676;hb=9fd509abe353d65f6f0a6a35c721b9d1694cda23;hp=de5d00dfe8a15511ac145631a25750d8fa06dbf5;hpb=0a4f0ce95a763b227ed4b7c553804a1c072867d5;p=sfa.git diff --git a/sfa/iotlab/iotlabapi.py b/sfa/iotlab/iotlabapi.py index de5d00df..f50441d3 100644 --- a/sfa/iotlab/iotlabapi.py +++ b/sfa/iotlab/iotlabapi.py @@ -11,7 +11,7 @@ from sfa.util.sfalogging import logger from sfa.storage.alchemy import dbsession from sqlalchemy.orm import joinedload from sfa.storage.model import RegRecord, RegUser, RegSlice, RegKey -from sfa.iotlab.iotlabpostgres import TestbedAdditionalSfaDB, TestbedXP +from sfa.iotlab.iotlabpostgres import TestbedAdditionalSfaDB, LeaseTableXP from sfa.iotlab.OARrestapi import OARrestapi from sfa.iotlab.LDAPapi import LDAPapi @@ -299,18 +299,15 @@ class IotlabTestbedAPI(): """ return self.oar.parser.SendRequest("GET_running_jobs") - def __get_hostnames_from_oar_node_ids(self, resource_id_list ): + def __get_hostnames_from_oar_node_ids(self, oar_id_node_dict, + resource_id_list ): """Get the hostnames of the nodes from their OAR identifiers. Get the list of nodes dict using GetNodes and find the hostname associated with the identifier. + :param oar_id_node_dict: full node dictionary list keyed by oar node id :param resource_id_list: list of nodes identifiers :returns: list of node hostnames. """ - full_nodes_dict_list = self.GetNodes() - #Put the full node list into a dictionary keyed by oar node id - oar_id_node_dict = {} - for node in full_nodes_dict_list: - oar_id_node_dict[node['oar_id']] = node hostname_list = [] for resource_id in resource_id_list: @@ -337,12 +334,21 @@ class IotlabTestbedAPI(): self.oar.parser.SendRequest("GET_reserved_nodes", \ username = username) + # Get the full node dict list once for all + # so that we can get the hostnames given their oar node id afterwards + # when the reservations are checked. + full_nodes_dict_list = self.GetNodes() + #Put the full node list into a dictionary keyed by oar node id + oar_id_node_dict = {} + for node in full_nodes_dict_list: + oar_id_node_dict[node['oar_id']] = node for resa in reservation_dict_list: logger.debug ("GetReservedNodes resa %s"%(resa)) #dict list of hostnames and their site resa['reserved_nodes'] = \ - self.__get_hostnames_from_oar_node_ids(resa['resource_ids']) + self.__get_hostnames_from_oar_node_ids(oar_id_node_dict, + resa['resource_ids']) #del resa['resource_ids'] return reservation_dict_list @@ -836,7 +842,7 @@ class IotlabTestbedAPI(): 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 = TestbedXP(slice_hrn = slice_record['hrn'], job_id=job_id, + 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" \ @@ -911,7 +917,7 @@ class IotlabTestbedAPI(): # deleted_jobs = set_jobs_psql.difference(kept_jobs) # deleted_jobs = list(deleted_jobs) # if len(deleted_jobs) > 0: - # self.iotlab_db.testbed_session.query(TestbedXP).filter(TestbedXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch') + # self.iotlab_db.testbed_session.query(LeaseTableXP).filter(LeaseTableXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch') # self.iotlab_db.testbed_session.commit() # return @@ -941,6 +947,7 @@ class IotlabTestbedAPI(): return filtered_reservation_list + def GetLeases(self, lease_filter_dict=None, login=None): """ @@ -971,13 +978,13 @@ class IotlabTestbedAPI(): #the same user in LDAP SA 27/07/12 job_oar_list = [] - jobs_psql_query = self.iotlab_db.testbed_session.query(TestbedXP).all() - jobs_psql_dict = dict([(row.job_id, row.__dict__) + jobs_psql_query = self.iotlab_db.testbed_session.query(LeaseTableXP).all() + jobs_psql_dict = dict([(row.experiment_id, row.__dict__) for row in jobs_psql_query]) #jobs_psql_dict = jobs_psql_dict) logger.debug("IOTLAB_API \tGetLeases jobs_psql_dict %s" % (jobs_psql_dict)) - jobs_psql_id_list = [row.job_id for row in jobs_psql_query] + jobs_psql_id_list = [row.experiment_id for row in jobs_psql_query] for resa in unfiltered_reservation_list: logger.debug("IOTLAB_API \tGetLeases USER %s"