ZenDMD Tip - Create Users in a Jiffy

From Zenoss Wiki
Jump to: navigation, search

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

usersToAdd are the usernames to add, emailDomain is the second half of the users' email addresses, and the defaultRoles are 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, roles=defaultRoles)
    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)