Difference between revisions of "ZenDMD Tip - Create Users in a Jiffy"

From Zenoss Wiki
Jump to: navigation, search
(Editing ZenDMD Tip - Create Users in a Jiffy)
 
Line 3: Line 3:
 
Massage usersToAdd to reflect the usernames to add, the emailDomain to reflect the second half of the users email addresses and the defaultRoles to reflect the roles the users should have.
 
Massage usersToAdd to reflect the usernames to add, the emailDomain to reflect the second half of the users email addresses and the defaultRoles to reflect the roles the users should have.
  
usersToAdd = ['testUserA', 'testUserB', 'testUserC']
+
usersToAdd=['testUserA', 'testUserB', 'testUserC']
emailDomain = 'rackspace.com'
+
emailDomain='rackspace.com'
defaultRoles = ['ZenUser', 'ZenRestrictedManager']
+
defaultRoles=['ZenUser', 'ZenRestrictedManager']
  
roleManager = dmd.acl_users.roleManager
+
roleManager=dmd.acl_users.roleManager
  
 
for user in usersToAdd:
 
for user in usersToAdd:
 
     sync()
 
     sync()
     un = str(user)
+
     un=str(user)
     ue = '%s@%s' % (str(un), str(emailDomain))
+
     ue='%s@%s' % (str(un), str(emailDomain))
 
     print 'Adding user %s, email %s' % (str(un), str(ue))
 
     print 'Adding user %s, email %s' % (str(un), str(ue))
     userOb = dmd.ZenUsers.manage_addUser(un, ue)
+
     userOb=dmd.ZenUsers.manage_addUser(un, ue)
 
     for role in defaultRoles:
 
     for role in defaultRoles:
 
         print 'Adding %s role from %s' % (str(role), str(userOb.id))
 
         print 'Adding %s role from %s' % (str(role), str(userOb.id))

Revision as of 20:23, 9 July 2012

On the master, `su zenoss` then `zendmd`

Massage usersToAdd to reflect the usernames to add, the emailDomain to reflect the second half of the users email addresses and the defaultRoles to reflect the roles the users should have.

usersToAdd=['testUserA', 'testUserB', 'testUserC'] emailDomain='rackspace.com' defaultRoles=['ZenUser', 'ZenRestrictedManager']

roleManager=dmd.acl_users.roleManager

for user in usersToAdd:

   sync()
   un=str(user)
   ue='%s@%s' % (str(un), str(emailDomain))
   print 'Adding user %s, email %s' % (str(un), str(ue))
   userOb=dmd.ZenUsers.manage_addUser(un, ue)
   for role in defaultRoles:
       print 'Adding %s role from %s' % (str(role), str(userOb.id))
       roleManager.assignRoleToPrincipal(str(role), str(userOb.id))


Once you're sure you've done what you expect, commit()

Best, --Shane (Hackman238)