[Application] CloudShell User management using Python cloudshell-automation-api #305
Quali-Community
started this conversation in
Useful Tips & Guides
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
CloudShell's Python API gives external applications or Python Scripts the ability to manage CloudShell in many different areas.
One of these capabilities is the ability to create, manage and update users and groups, thus providing the external application management access control over CloudShell.
The syntax for performing these actions is very simple and easy to understand, below are a few basic examples (using the qualipy CloudShell API included in Cloudshell 6.4) :
Note: # marks comment rows
# Create the API Session object (replace the string values with the actual relevant server address, username and password
api_session = CloudShellAPISession(“ServerHostNameOrIP”,”Username”,”Password”,”Global”)
# Activate a user (allow login)
api_session.UpdateUser(username=”john.d”, isActive=True, email=”john.d@example.com”)
# Deactivate a user (disallow login, equivalent to expiring a password)
api_session.UpdateUser(username=”john.d”, isActive=False, email=”john.d@example.com”)
# Set a user’s password (admin only, can be used to automate resetting a password or generating a password)
api_session.UpdateUserPassword(username='john.d',password=’new_password')
# Clear all of a user’s groups
api_session.UpdateUserGroups(username="Do.Test",groupsNames=[])
#Set user’s groups to predetermined groups
api_session.UpdateUserGroups(username="Do.Test",groupsNames=[‘Group1Name’,’Group2Name’])
# Advanced: iterate over the users current group memberships and remove only the one you want.
# 1. Get the users Groups
# 2. Convert the group objects list to an str list
# 3. Remove the relevant group
#4. Update the user’s groups using the resulting list
user_groups = api_session.GetUserDetails(username="Do.Test").Groups
user_group_names = [group.Name for group in user_groups]
if "group_name" in user_group_names: user_group_names.remove("group_name")
api_session.UpdateUserGroups(username="Do.Test",groupsNames=user_group_names)
Leeor Vardi (Leeor.V) - 03/21/2016 12:45 PM
· 2497 ·
Beta Was this translation helpful? Give feedback.
All reactions