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

From Zenoss Wiki
Jump to: navigation, search
(Noting this is generally frowned upon)
 
(18 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
'''Generally this sort of process is deprecated. Please use the Zenoss JSON API instead'''
 +
 
On the master, `su zenoss` then `zendmd`
 
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 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='rackspace.com'
+
defaultRoles=['ZenUser', 'ZenRestrictedManager']
+
 
+
roleManager=dmd.acl_users.roleManager
+
  
 +
<syntaxhighlight lang="python">
 +
usersToAdd = ['testUserA', 'testUserB', 'testUserC']
 +
emailDomain = 'company.com'
 +
defaultRoles = ['ZenUser',]
 +
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, email=ue, roles=defaultRoles)
     for role in defaultRoles:
+
     commit()
        print 'Adding %s role from %s' % (str(role), str(userOb.id))
+
</syntaxhighlight>
        roleManager.assignRoleToPrincipal(str(role), str(userOb.id))
+
 
+
 
+
Once you're sure you've done what you expect, commit()
+
  
Best,
+
[[Category:Tips]]
--Shane (Hackman238)
+
[[Category:ZenDMD]]

Latest revision as of 16:19, 9 December 2016

Generally this sort of process is deprecated. Please use the Zenoss JSON API instead

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, email=ue, roles=defaultRoles)
    commit()