X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fiotlab%2Fiotlabslices.py;h=80b4f47680e4101c6a2121a0e4cd5778436cd662;hb=b0eccc986c2335bd2f49caf0c23fa1c72d194bee;hp=b7a81e0e59ec516e351db298c2e451c0bfefc1f3;hpb=7398a32ecc65a97db664c918b6c224417a9947c4;p=sfa.git diff --git a/sfa/iotlab/iotlabslices.py b/sfa/iotlab/iotlabslices.py index b7a81e0e..80b4f476 100644 --- a/sfa/iotlab/iotlabslices.py +++ b/sfa/iotlab/iotlabslices.py @@ -58,7 +58,7 @@ class IotlabSlices: # check if we are already peered with this site_authority #if so find the peer record - peers = self.driver.testbed_shell.GetPeers(peer_filter=site_authority) + peers = self.driver.GetPeers(peer_filter=site_authority) for peer_record in peers: if site_authority == peer_record.hrn: peer = peer_record @@ -108,7 +108,7 @@ class IotlabSlices: logger.debug("IOTLABSLICES verify_slice_leases sfa_slice %s " % (sfa_slice)) #First get the list of current leases from OAR - leases = self.driver.testbed_shell.GetLeases({'slice_hrn': sfa_slice['hrn']}) + leases = self.driver.GetLeases({'slice_hrn': sfa_slice['hrn']}) logger.debug("IOTLABSLICES verify_slice_leases requested_jobs_dict %s \ leases %s " % (requested_jobs_dict, leases)) @@ -133,7 +133,8 @@ class IotlabSlices: job['duration'] = \ str(int(job['duration']) \ * self.driver.testbed_shell.GetLeaseGranularity()) - if job['duration'] < self.driver.testbed_shell.GetLeaseGranularity(): + if job['duration'] < \ + self.driver.testbed_shell.GetLeaseGranularity(): del requested_jobs_dict[job['start_time']] #Requested jobs @@ -207,15 +208,22 @@ class IotlabSlices: logger.debug("IOTLABSLICES \ NEWLEASE slice %s job %s" % (sfa_slice, job)) - self.driver.testbed_shell.AddLeases( + job_id = self.driver.AddLeases( job['hostname'], sfa_slice, int(job['start_time']), int(job['duration'])) + if job_id is not None: + new_leases = self.driver.GetLeases(login= + sfa_slice['login']) + for new_lease in new_leases: + leases.append(new_lease) #Deleted leases are the ones with lease id not declared in the Rspec if deleted_leases: self.driver.testbed_shell.DeleteLeases(deleted_leases, - sfa_slice['user']['uid']) + sfa_slice['login']) + #self.driver.testbed_shell.DeleteLeases(deleted_leases, + # sfa_slice['user']['uid']) logger.debug("IOTLABSLICES \ verify_slice_leases slice %s deleted_leases %s" % (sfa_slice, deleted_leases)) @@ -223,7 +231,7 @@ class IotlabSlices: if reschedule_jobs_dict: for start_time in reschedule_jobs_dict: job = reschedule_jobs_dict[start_time] - self.driver.testbed_shell.AddLeases( + self.driver.AddLeases( job['hostname'], sfa_slice, int(job['start_time']), int(job['duration'])) @@ -300,15 +308,15 @@ class IotlabSlices: slicename = slice_hrn # check if slice belongs to Iotlab - slices_list = self.driver.testbed_shell.GetSlices( - slice_filter=slicename, slice_filter_type='slice_hrn') + slices_list = self.driver.GetSlices(slice_filter=slicename, + slice_filter_type='slice_hrn') sfa_slice = None if slices_list: for sl in slices_list: - logger.debug("SLABSLICE \t verify_slice slicename %s \ + logger.debug("IOTLABSLICES \t verify_slice slicename %s \ slices_list %s sl %s \r slice_record %s" % (slicename, slices_list, sl, slice_record)) sfa_slice = sl @@ -333,7 +341,8 @@ class IotlabSlices: } if ldap_user: - hrn = self.driver.testbed_shell.root_auth + '.' + ldap_user['uid'] + hrn = self.driver.testbed_shell.root_auth + '.' \ + + ldap_user['uid'] user = self.driver.get_user_record(hrn) logger.debug(" IOTLABSLICES \tverify_slice hrn %s USER %s" @@ -341,7 +350,7 @@ class IotlabSlices: # add the external slice to the local SFA iotlab DB if sfa_slice: - self.driver.testbed_shell.AddSlice(sfa_slice, user) + self.driver.AddSlice(sfa_slice, user) logger.debug("IOTLABSLICES \tverify_slice ADDSLICE OK") return sfa_slice @@ -349,7 +358,7 @@ class IotlabSlices: def verify_persons(self, slice_hrn, slice_record, users, options={}): """Ensures the users in users list exist and are enabled in LDAP. Adds - person if needed. + person if needed (AddPerson). Checking that a user exist is based on the user's email. If the user is still not found in the LDAP, it means that the user comes from another @@ -361,8 +370,8 @@ class IotlabSlices: :param slice_record: record of the slice_hrn :param users: users is a record list. Records can either be local records or users records from known and trusted federated - sites.If the user is from another site that iotlab doesn't trust yet, - then Resolve will raise an error before getting to create_sliver. + sites.If the user is from another site that iotlab doesn't trust + yet, then Resolve will raise an error before getting to allocate. :type slice_hrn: string :type slice_record: string @@ -373,12 +382,10 @@ class IotlabSlices: """ - #TODO SA 21/08/12 verify_persons Needs review logger.debug("IOTLABSLICES \tverify_persons \tslice_hrn %s \ \t slice_record %s\r\n users %s \t " % (slice_hrn, slice_record, users)) - users_by_id = {} users_by_email = {} #users_dict : dict whose keys can either be the user's hrn or its id. @@ -387,19 +394,18 @@ class IotlabSlices: #First create dicts by hrn and id for each user in the user record list: for info in users: - if 'slice_record' in info: - slice_rec = info['slice_record'] - if 'user' in slice_rec : - user = slice_rec['user'] + # if 'slice_record' in info: + # slice_rec = info['slice_record'] + # if 'user' in slice_rec : + # user = slice_rec['user'] - if 'email' in user: - users_by_email[user['email']] = user - users_dict[user['email']] = user + if 'email' in info: + users_by_email[info['email']] = info + users_dict[info['email']] = info - logger.debug("SLABSLICE.PY \t verify_person \ - users_dict %s \r\n user_by_email %s \r\n \ - \tusers_by_id %s " - % (users_dict, users_by_email, users_by_id)) + logger.debug("IOTLABSLICES.PY \t verify_person \ + users_dict %s \r\n user_by_email %s \r\n " + % (users_dict, users_by_email)) existing_user_ids = [] existing_user_emails = [] @@ -417,12 +423,13 @@ class IotlabSlices: #Needed because what if the user has been deleted in LDAP but #is still in SFA? existing_users = self.driver.testbed_shell.GetPersons(filter_user) - logger.debug(" \r\n IOTLABSLICES.PY \tverify_person filter_user \ - %s existing_users %s " + logger.debug(" \r\n IOTLABSLICES.PY \tverify_person filter_user %s\ + existing_users %s " % (filter_user, existing_users)) #User is in iotlab LDAP if existing_users: for user in existing_users: + user['login'] = user['uid'] users_dict[user['email']].update(user) existing_user_emails.append( users_dict[user['email']]['email']) @@ -439,32 +446,32 @@ class IotlabSlices: ldap_reslt = self.driver.testbed_shell.ldap.LdapSearch(req) if ldap_reslt: - logger.debug(" SLABSLICE.PY \tverify_person users \ + logger.debug(" IOTLABSLICES.PY \tverify_person users \ USER already in Iotlab \t ldap_reslt %s \ " % (ldap_reslt)) existing_users.append(ldap_reslt[1]) else: #User not existing in LDAP - logger.debug("SLABSLICE.PY \tverify_person users \ + logger.debug("IOTLABSLICES.PY \tverify_person users \ not in ldap ...NEW ACCOUNT NEEDED %s \r\n \t \ ldap_reslt %s " % (users, ldap_reslt)) requested_user_emails = users_by_email.keys() - requested_user_hrns = \ - [users_by_email[user]['hrn'] for user in users_by_email] - logger.debug("SLABSLICE.PY \tverify_person \ - users_by_email %s " % (users_by_email)) + # requested_user_hrns = \ + # [users_by_email[user]['hrn'] for user in users_by_email] + # logger.debug("IOTLABSLICES.PY \tverify_person \ + # users_by_email %s " % (users_by_email)) - #Check that the user of the slice in the slice record - #matches one of the existing users - try: - if slice_record['PI'][0] in requested_user_hrns: - logger.debug(" SLABSLICE \tverify_person ['PI']\ - slice_record %s" % (slice_record)) + # #Check that the user of the slice in the slice record + # #matches one of the existing users + # try: + # if slice_record['reg-researchers'][0] in requested_user_hrns: + # logger.debug(" IOTLABSLICES \tverify_person ['PI']\ + # slice_record %s" % (slice_record)) - except KeyError: - pass + # except KeyError: + # pass # users to be added, removed or updated #One user in one iotlab slice : there should be no need @@ -483,7 +490,7 @@ class IotlabSlices: #requested_user_email is in existing_user_emails if len(added_user_emails) == 0: slice_record['login'] = users_dict[requested_user_emails[0]]['uid'] - logger.debug(" SLABSLICE \tverify_person QUICK DIRTY %s" + logger.debug(" IOTLABSLICES \tverify_person QUICK DIRTY %s" % (slice_record)) for added_user_email in added_user_emails: @@ -496,13 +503,14 @@ class IotlabSlices: for k in k_list: if k in added_user: person[k] = added_user[k] - - person['pkey'] = added_user['keys'][0] + # bug user without key + if added_user['keys']: + person['pkey'] = added_user['keys'][0] person['mail'] = added_user['email'] person['email'] = added_user['email'] person['key_ids'] = added_user.get('key_ids', []) - ret = self.driver.testbed_shell.AddPerson(person) + ret = self.driver.AddPerson(person) if 'uid' in ret: # meaning bool is True and the AddPerson was successful person['uid'] = ret['uid'] @@ -511,7 +519,7 @@ class IotlabSlices: # error message in ret logger.debug(" IOTLABSLICES ret message %s" %(ret)) - logger.debug(" SLABSLICE \r\n \r\n \t THE SECOND verify_person\ + logger.debug(" IOTLABSLICES \r\n \r\n \t THE SECOND verify_person\ person %s" % (person)) #Update slice_Record with the id now known to LDAP @@ -528,7 +536,7 @@ class IotlabSlices: key_ids = [] for person in persons: key_ids.extend(person['key_ids']) - keylist = self.driver.testbed_shell.GetKeys(key_ids, ['key_id', 'key']) + keylist = self.driver.GetKeys(key_ids, ['key_id', 'key']) keydict = {} for key in keylist: @@ -566,12 +574,6 @@ class IotlabSlices: #key['key_id'], peer['shortname'], \ #remote_key_id) - #finally: - #if peer: - #self.driver.testbed_shell.BindObjectToPeer('person', \ - #person['person_id'], peer['shortname'], \ - #user['person_id']) - # remove old keys (only if we are not appending) append = options.get('append', True) if append is False: