Since no group emptied the user's function, the first function to write is three parameters: Group identity, add user, delete user. Feel the interface is not good to use, then found the combination can be, the code is as follows:
#清除, insert all users in Def update_users (self, groupname, users=[]): "" ":p Aram GroupName: Group name, string type such as" Groupna
Me "; :p Aram Users: User list, such as addusers [' User1 ', ' User2 ']: return: Note the parameters defined in the function modlist can accept multiple argument lists, where: Mod_add: If the
Sex exists, this attribute can have multiple values, then the new value is added, the old value is retained Mod_delete: If the value of the property exists, the value will be deleted mod_replace: This attribute all the old values will be deleted, this value is added to the example: [(LDAP. Mod_add, ' memberuid ', ' User1 '), (LDAP. Mod_delete, ' memberuid ', ' User3 ')] "" "modlist = [] If len (users) = 0:modlist.append (LDAP. Mod_replace, ' Memberuid ', "")) for index in range (len (users)): If index = = 0:modlist. Append (LDAP. Mod_replace, ' Memberuid ', str (Users[index])) else:modlist.append (LDAP. Mod_add, ' Memberuid ', str (Users[index])) Try:obj = Self.ldapconn Obj.protocal_version = Ldap. VERSION3 modifyDN = "cn=%s,ou=group,%s"% (GroupnamE, self.base_dn) obj.modify_s (modifyDN, Modlist) obj.unbind_s () return True ex Cept LDAP. Ldaperror, E:print ("%s Update users Failed,reason:%s"% (groupname, str (e))) return False