Wednesday 2 October 2013

WLST snippets to Add Remove users in Weblogic

Put below code is .py script.
User-group.txt and RemoveUsers.txt has lines like
user email/Description group
user1 user1@gmail.com Area_manager

To Add Users with Groups:

for line in open("D:\data\ImportUser\user-groups.txt"):
    line = line.strip()
    if len(line) != 0:   
       it=line.split(',')
       print 'Add User ========== user:', it[0], ' desc:', it[1], ' group:', it[2]     
       if atnr.userExists(it[0]) == 0:
          print '   create user:', it[0]
          atnr.createUser(it[0],password,it[1])
       if atnr.isMember(it[2],it[0],true) == 0:
          print '   add group :', it[2], 'for user', it[0]  
          atnr.addMemberToGroup(it[2],it[0]) 
       else:
            print '   User :', it[0], 'is already member of group', it[2] 


To Remove Users:

for line in open("D:\data\RemoveUsers\RemoveUsers.txt"):
    line = line.strip()
    if len(line) != 0:
       it=line.split(',')
       print 'Remove Group ========== user:', it[0], 'group', it[2]     
       if atnr.isMember(it[2],it[0],true) != 0:
          print '   remove group :', it[2], 'for user', it[0]
          atnr.removeMemberFromGroup(it[2], it[0])
       else:
          print '   User :', it[0], 'is not member of group', it[2]


Similar Other functions are:

atnr.createGroup(group,groupcomment)
atnr.createUser(user,password,user)

No comments:

Post a Comment