-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsl_getUsers.py
More file actions
89 lines (72 loc) · 2.04 KB
/
sl_getUsers.py
File metadata and controls
89 lines (72 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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 / このユーザーが親となる子ユーザーをリストから取得する.
parent: 親ユーザーのオブジェクト (User_Customer)
users: 検索対象の子ユーザーのリスト (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:
# print(getChildren(u, users))
userList = getChildren(parent, users)
for x in userList[0:]:
# print(x)
table.add_row(
[
x['ParentID'],
x['ParentName'],
x['ChildID'],
x['ChildName'],
x['Email']
]
)
count = count + 1
print(table)
print(count, "users")
exit()