max_uidnumber = self.ldapUserUidNumberMin
#Otherwise, get the highest uidNumber
else:
-
- uidNumberList = [int(r[1]['uidNumber'][0])for r in result_data ]
+ uidNumberList = [int(r[1]['uidNumber'][0])for r in result_data]
logger.debug("LDAPapi.py \tfind_max_uidNumber \
- uidNumberList %s " %(uidNumberList))
+ uidNumberList %s " % (uidNumberList))
max_uidnumber = max(uidNumberList) + 1
return str(max_uidnumber)
req_ldap = ''
req_ldapdict = {}
if record :
- if 'first_name' in record and 'last_name' in record:
- req_ldapdict['cn'] = str(record['first_name'])+" "\
- + str(record['last_name'])
- if 'email' in record :
+ if 'first_name' in record and 'last_name' in record:
+ if record['first_name'] != record['last_name']:
+ req_ldapdict['cn'] = str(record['first_name'])+" "\
+ + str(record['last_name'])
+ if 'email' in record:
req_ldapdict['mail'] = record['email']
if 'mail' in record:
req_ldapdict['mail'] = record['mail']
if 'enabled' in record:
- if record['enabled'] == True :
+ if record['enabled'] is True:
req_ldapdict['shadowExpire'] = '-1'
else:
req_ldapdict['shadowExpire'] = '0'
#Plus, the SFA user may already have an account with iotlab
#using another login.
-
-
logger.debug("\r\n \t LDAP.PY make_ldap_filters_from_record \
- record %s req_ldapdict %s" \
- %(record, req_ldapdict))
+ record %s req_ldapdict %s"
+ % (record, req_ldapdict))
for k in req_ldapdict:
- req_ldap += '('+ str(k)+ '=' + str(req_ldapdict[k]) + ')'
- if len(req_ldapdict.keys()) >1 :
+ req_ldap += '(' + str(k) + '=' + str(req_ldapdict[k]) + ')'
+ if len(req_ldapdict.keys()) >1 :
req_ldap = req_ldap[:0]+"(&"+req_ldap[0:]
size = len(req_ldap)
- req_ldap = req_ldap[:(size-1)] +')'+ req_ldap[(size-1):]
+ req_ldap = req_ldap[:(size-1)] + ')' + req_ldap[(size-1):]
else:
req_ldap = "(cn=*)"
logger.debug(" \r\n \t LDAP LdapAddUser \r\n\r\n ================\r\n ")
user_ldap_attrs = self.make_ldap_attributes_from_record(record)
-
#Check if user already in LDAP wih email, first name and last name
filter_by = self.make_ldap_filters_from_record(user_ldap_attrs)
user_exist = self.LdapSearch(filter_by)
if user_exist:
logger.warning(" \r\n \t LDAP LdapAddUser user %s %s \
- already exists" %(user_ldap_attrs['sn'], \
- user_ldap_attrs['mail']))
+ already exists" % (user_ldap_attrs['sn'],
+ user_ldap_attrs['mail']))
return {'bool': False}
#Bind to the server
return {'bool': True}
except ldap.LDAPError, error:
- logger.log_exc("LDAP Delete Error %s" %error)
+ logger.log_exc("LDAP Delete Error %s" % error)
return {'bool': False, 'message': error}
def LdapDeleteUser(self, record_filter):
pass
return_records = records_list
- logger.debug("IOTLABDRIVER \tGetPeer return_records %s " \
- %(return_records))
+ logger.debug("IOTLABDRIVER \tGetPeer return_records %s "
+ % (return_records))
return return_records
-
-
#TODO : Handling OR request in make_ldap_filters_from_records
#instead of the for loop
#over the records' list
Get the enabled users and their properties from Iotlab LDAP.
If a filter is specified, looks for the user whose properties match
the filter, otherwise returns the whole enabled users'list.
+
:param person_filter: Must be a list of dictionnaries
- with users properties when not set to None.
+ with users properties when not set to None.
:param person_filter: list of dict
:returns:Returns a list of users whose accounts are enabled
- found in ldap.
+ found in ldap.
:rtype: list of dicts
"""
- logger.debug("IOTLABDRIVER \tGetPersons person_filter %s" \
- %(person_filter))
+ logger.debug("IOTLABDRIVER \tGetPersons person_filter %s"
+ % (person_filter))
person_list = []
if person_filter and isinstance(person_filter, list):
#If we are looking for a list of users (list of dict records)
#Get only enabled user accounts in iotlab LDAP :
#add a filter for make_ldap_filters_from_record
- person = self.ldap.LdapFindUser(searched_attributes, \
- is_user_enabled=True)
+ person = self.ldap.LdapFindUser(searched_attributes,
+ is_user_enabled=True)
#If a person was found, append it to the list
if person:
person_list.append(person)
-#!/bin/bash
-if (( ! $# == 2 ))
-then
- echo " Usage : bash_test takes 2 arguments : one jobid and one of the following:"
- echo " LDAP/ OAR / driver "
- echo $#
- exit
-fi
+#!/usr/bin/env python
-sfi.py list iotlab
-echo " ================= SFI.PY RESOURCES ============="
-sfi.py resources
+import os
-echo " ================= SFI.PY RESOURCES -R SLAB ============="
-sfi.py resources -r iotlab
-echo " ================= SFI.PY RESOURCES -L ALL ============="
-sfi.py resources -l all
+print " ================= SFI.PY LIST IOTLAB ============="
+os.system('sfi.py list iotlab')
-echo " ================= SFI.PY RESOURCES -R SLAB -L ALL ============="
-sfi.py resources -r iotlab -l all
-echo " ================= SFI.PY RESOURCES -L ALL > avakian_adv.rspec ============="
-sfi.py resources -l all > /root/tests_rspecs/iotlab_devlille_OUTPUT.rspec
+print " ================= SFI.PY RESOURCES ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources')
-echo " ================= SFI.PY RESOURCES avakian_adv.rspec ============="
-sfi.py resources iotlab.avakian_slice
+print " ================= SFI.PY RESOURCES -R IOTLAB ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources -r iotlab')
+print " ================= SFI.PY RESOURCES -L ALL ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources -l all')
-echo " ================= SFI.PY SHOW SLICE ============="
-sfi.py show iotlab.avakian_slice
+print " ================= SFI.PY RESOURCES -R IOTLAB -L ALL ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources -r iotlab -l all')
-echo " ================= SFI.PY SHOW USER ============="
-sfi.py show iotlab.avakian
+print " ================= SFI.PY RESOURCES -L ALL > avakian_adv.rspec ==========="
+os.system('sfi.py resources -l all > /root/tests_rspecs/iotlab_devlille_OUTPUT.rspec')
-echo " ================= SFI.PY SHOW NODE ============="
-sfi.py show iotlab.node6.devlille.senslab.info
+print " ================= SFI.PY RESOURCES -L LEASES ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources -l leases')
-echo " ================= SFI.PY SLICES ============="
-sfi.py slices
+print " =================SFI.PY RESOURCES -L LEASES -R IOTLAB ============== "
+os.system('sfi.py resources -r iotlab -l leases')
-echo " ================= SFI.PY STATUS SLICE ============="
-sfi.py status iotlab.avakian_slice
+print " ================= SFI.PY RESOURCES avakian_adv.rspec ============="
+input("Press Enter to continue...")
+os.system('sfi.py resources iotlab.avakian_slice')
-echo " ================= SFI.PY CREATE SLICE ============="
-sfi.py create iotlab.avakian_slice /root/tests_rspecs/iotlab_devlille.rspec
-# echo " ================= SFI.PY DELETE SLICE ============="
-# sfi.py delete iotlab.avakian_slice
+print " ================= SFI.PY SHOW SLICE ============="
+os.system('sfi.py show iotlab.avakian_slice')
+
+print " ================= SFI.PY SHOW USER ============="
+input("Press Enter to continue...")
+os.system('sfi.py show iotlab.avakian')
+
+print " ================= SFI.PY SHOW NODE ============="
+os.system('sfi.py show iotlab.node6.devlille.senslab.info')
+
+print " ================= SFI.PY SLICES ============="
+input("Press Enter to continue...")
+os.system('sfi.py slices')
+
+print " ================= SFI.PY STATUS SLICE ============="
+os.system('sfi.py status iotlab.avakian_slice')
+
+print " ================= SFI.PY CREATE SLICE ============="
+input("Press Enter to continue...")
+os.system('sfi.py create iotlab.avakian_slice /root/tests_rspecs/iotlab_devlille.rspec')
+
+
+print " ================= SFI.PY DELETE SLICE ============="
+input("Press Enter to continue...")
+os.system('sfi.py delete iotlab.avakian_slice')
+print "\r\n"
-echo "\r\n"
-echo " PYTHON TEST ", $1, $2