ZenDMD Tip - Add Roles to Users in a jiffy

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

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

usersToEdit are the usernames to add roles to.

usersToEdit = ['User1', 'User2', 'User3']
 
roles = ['ZenManager',]
roleManager = dmd.acl_users.roleManager
for user in usersToEdit:
    sync()
    un = str(user)
    userOb = dmd.ZenUsers.getUserSettings(str(un))
    for role in roles:
        print 'Adding %s role from %s' % (str(role), str(userOb.id))
        roleManager.assignRoleToPrincipal(str(role), str(userOb.id))
    commit()