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

From Zenoss Wiki
Jump to: navigation, search
Line 19: Line 19:
 
       userObB = dmd.ZenUsers.getUserSettings(str(userOb.getId()))
 
       userObB = dmd.ZenUsers.getUserSettings(str(userOb.getId()))
 
       userObB.email = ue
 
       userObB.email = ue
 +
      commit()
  
 
Once you're sure you've done what you expect, commit()
 
  
 
Source: http://shanewilliamscott.com/Code/zendmd-tip-create-users-in-a-jiffy.html
 
Source: http://shanewilliamscott.com/Code/zendmd-tip-create-users-in-a-jiffy.html

Revision as of 19:57, 17 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 = 'company.com'
  defaultRoles = ['ZenUser',]
  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))
      userObB = dmd.ZenUsers.getUserSettings(str(userOb.getId()))
      userObB.email = ue
      commit()


Source: http://shanewilliamscott.com/Code/zendmd-tip-create-users-in-a-jiffy.html

Best, --Shane (Hackman238)