SoftLayer manages systems in the cloud from Portal. SoftLayer Customer Portal
You need a user ID to access the Portal. The first user ID created when you create a SoftLayer account is called the master user and has all permissions for that account's system.
Since it is not practical for a master user to manage all systems, the master user typically creates child users and delegates administrative privileges over some systems. The child user further creates a child user and delegates the authority, and delegates the development and operation management on the system to the developer and the person in charge of operation.
The figure is as follows.
The master user assigns permissions to child users and specifies which devices they can access. The child user assigns permissions to the grandchild user to delegate management and specifies which devices they can access.
In this way, users have a hierarchical structure. You can see the list of users in Portal, but you cannot see the parent-child relationship of users in the list in Portal or CLI. This is inconvenient for user management, so I created a script that uses the SoftLayer API to get a list of users and a parent-child relationship.
sluser.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
SL_USERNAME = <SL User Name>
SL_API_KEY = <SL API Key>
sl_getUser.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'takechika'
import sys
from prettytable import PrettyTable
import SoftLayer
import sluser
SL_USERNAME = sluser.SL_USERNAME
SL_API_KEY = sluser.SL_API_KEY
_userMask = '''
id,
accountId,
parentId,
firstName,
lastName,
email
'''
_userTableHeader = [
'ParentID',
'ParentName',
'UserID',
'UserName',
'EMail'
]
def getChildren(parent, users):
"""Get children of the parent from the user list /Get the child user that this user is a parent from the list.
parent:Parent user object(User_Customer)
users:List of child users to search(an array of User_Customer)
"""
a = {}
b = []
for u in users:
if u.get('parentId') == parent.get('id'):
a = {
"ParentID": u.get('parentId'),
"ParentName": parent.get('lastName') + " " + parent.get('firstName'),
"ChildID": u.get('id'),
"ChildName": u.get('lastName') + " " + u.get('firstName'),
"Email": u.get('email')
}
b.append(a)
return(b)
client = SoftLayer.Client(username=SL_USERNAME, api_key=SL_API_KEY)
users = client['Account'].getUsers(mask=_userMask)
# Find the master user id
for u in users:
if u.get('parentId') == '':
masterUser = u
print("Master user is \"%s %s\" (id: %s)" % (masterUser.get('lastName'), masterUser.get('firstName'), masterUser.get('id')))
# Table definition
table = PrettyTable(_userTableHeader)
table.padding_width = 1
# Get user list
count = 0
for parent in users:
userList = getChildren(parent, users)
for x in userList[0:]:
table.add_row(
[
x['ParentID'],
x['ParentName'],
x['ChildID'],
x['ChildName'],
x['Email']
]
)
count = count + 1
print(table)
print(count, "users")
exit()
The output looks like this (username and email address are fictitious): The child user and the corresponding parent user are displayed in a list.
Master user is "Jedi Master" (id: 182178)
+----------+--------------------+--------+-----------------------+--------------------------+
| ParentID | ParentName | UserID | UserName | EMail |
+----------+--------------------+--------+-----------------------+--------------------------+
| 182178 | Jedi Master | 183358 | Obi-Wan Kenobi | [email protected] |
| 182178 | Jedi Master | 183362 | R2 D2 | [email protected] |
| 182178 | Jedi Master | 183372 | C 3PO | [email protected] |
| 182178 | Jedi Master | 183376 | Luke Skywalker | [email protected] |
| 183362 | Jedi Master | 183378 | Chew Bacca | [email protected] |
| 183358 | Obi-Wan Kenobi | 183360 | Anakin Skywalker | [email protected] |
+----------+--------------------+--------+-----------------------+--------------------------+
6 users
Recommended Posts