From 4868da2b214a85ec5c666a4c8d36141e2acafd10 Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Tue, 29 Oct 2013 15:00:56 +0100 Subject: [PATCH] Modifications in get_rspec. Creating a dedicated function to get the ldap uid from the slice record instead of piece of code here and there doing the stuff. --- sfa/iotlab/iotlabaggregate.py | 75 ++++++++++++++++++++++------------- sfa/iotlab/iotlabpostgres.py | 4 +- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/sfa/iotlab/iotlabaggregate.py b/sfa/iotlab/iotlabaggregate.py index fc5b2dbc..bece8bb4 100644 --- a/sfa/iotlab/iotlabaggregate.py +++ b/sfa/iotlab/iotlabaggregate.py @@ -98,6 +98,7 @@ class IotlabAggregate: slice_hrn, _ = urn_to_hrn(slice_xrn) slice_name = slice_hrn + # GetSlices always returns a list, even if there is only one element slices = self.driver.iotlab_api.GetSlices(slice_filter=str(slice_name), slice_filter_type='slice_hrn', login=login) @@ -110,41 +111,58 @@ class IotlabAggregate: # sort slivers by node id , if there is a job #and therefore, node allocated to this slice - for sfa_slice in slices: - try: - node_ids_list = sfa_slice['node_ids'] - except KeyError: - logger.log_exc("IOTLABAGGREGATE \t \ - get_slice_and_slivers No nodes in the slice \ - - KeyError ") - node_ids_list = [] - continue - - for node in node_ids_list: - sliver_xrn = Xrn(slice_urn, type='sliver', id=node) - sliver_xrn.set_authority(self.driver.hrn) - sliver = Sliver({'sliver_id': sliver_xrn.urn, - 'name': sfa_slice['hrn'], - 'type': 'iotlab-node', - 'tags': []}) - - slivers[node] = sliver + # for sfa_slice in slices: + sfa_slice = slices[0] + try: + node_ids_list = sfa_slice['node_ids'] + except KeyError: + logger.log_exc("IOTLABAGGREGATE \t \ + get_slice_and_slivers No nodes in the slice \ + - KeyError ") + node_ids_list = [] + # continue + + for node in node_ids_list: + sliver_xrn = Xrn(slice_urn, type='sliver', id=node) + sliver_xrn.set_authority(self.driver.hrn) + sliver = Sliver({'sliver_id': sliver_xrn.urn, + 'name': sfa_slice['hrn'], + 'type': 'iotlab-node', + 'tags': []}) + + slivers[node] = sliver #Add default sliver attribute : #connection information for iotlab - if get_authority(sfa_slice['hrn']) == self.driver.iotlab_api.root_auth: - tmp = sfa_slice['hrn'].split('.') - ldap_username = tmp[1].split('_')[0] + # if get_authority(sfa_slice['hrn']) == self.driver.iotlab_api.root_auth: + # tmp = sfa_slice['hrn'].split('.') + # ldap_username = tmp[1].split('_')[0] + # ssh_access = None + # slivers['default_sliver'] = {'ssh': ssh_access, + # 'login': ldap_username} + # look in ldap: + ldap_username = self.find_ldap_username_from_slice(sfa_slice) + + if ldap_username is not None: ssh_access = None slivers['default_sliver'] = {'ssh': ssh_access, - 'login': ldap_username} + 'login': ldap_username} - #TODO get_slice_and_slivers Find the login of the external user logger.debug("IOTLABAGGREGATE api get_slice_and_slivers slivers %s " % (slivers)) return (slices, slivers) + def find_ldap_username_from_slice(self, sfa_slice): + researchers = [sfa_slice['reg_researchers'][0].__dict__] + # look in ldap: + ldap_username = None + ret = self.driver.iotlab_api.GetPersons(researchers) + if len(ret) != 0: + ldap_username = ret[0]['uid'] + + return ldap_username + def get_nodes(self, slices=None, slivers=[], options=None): """Returns the nodes in the slice using the rspec format, with all the @@ -383,10 +401,11 @@ class IotlabAggregate: if slice_xrn and slices is not None: #Get user associated with this slice #for one_slice in slices : - ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn'] - # ldap_username = slices[0]['user'] - tmp = ldap_username.split('.') - ldap_username = tmp[1] + ldap_username = self.find_ldap_username_from_slice(slices[0]) + # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn'] + # # ldap_username = slices[0]['user'] + # tmp = ldap_username.split('.') + # ldap_username = tmp[1] logger.debug("IotlabAggregate \tget_rspec **** \ LDAP USERNAME %s \r\n" \ % (ldap_username)) diff --git a/sfa/iotlab/iotlabpostgres.py b/sfa/iotlab/iotlabpostgres.py index 34b26624..54c6db24 100644 --- a/sfa/iotlab/iotlabpostgres.py +++ b/sfa/iotlab/iotlabpostgres.py @@ -55,7 +55,7 @@ class LeaseTableXP (TestbedBase): def __repr__(self): """Prints the SQLAlchemy record to the format defined by the function. - """ + """207 result = " 0: - self.testbed_session.query(LeaseTableXP).filter(LeaseTableXP.job_id.in_(deleted_experiments)).delete(synchronize_session='fetch') + self.testbed_session.query(LeaseTableXP).filter(LeaseTableXP.experiment_id.in_(deleted_experiments)).delete(synchronize_session='fetch') self.testbed_session.commit() return -- 2.43.0