-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsl_getNetworkStorage.py
More file actions
91 lines (71 loc) · 1.99 KB
/
sl_getNetworkStorage.py
File metadata and controls
91 lines (71 loc) · 1.99 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'
from prettytable import PrettyTable
import SoftLayer
import sluser
SL_USERNAME = sluser.SL_USERNAME
SL_API_KEY = sluser.SL_API_KEY
_maskNetworkStorage = '''
hardware,
iops,
iscsiLuns,
iscsiLunCount,
osTypeId,
serviceResource,
serviceResource.datacenter,
serviceResourceName,
serviceResourceBackendIpAddress,
storageGroups,
vendorName
'''
_tableHeader = [
'id',
'nasType',
'datacenter',
'username',
'gb',
'iops',
'serviceResourceName',
'serviceResourceBackendIpAddress',
'serviceResourceType',
'hardware',
'vendorName',
'osTypeId'
]
def lookup(dic, key, *keys):
"""A generic dictionary access helper.
This helps simplify code that uses heavily nested dictionaries. It will
return None if any of the keys in *keys do not exist.
> lookup({'this': {'is': 'nested'}}, 'this', 'is')
nested
> lookup({}, 'this', 'is')
None
"""
if keys:
return lookup(dic.get(key, {}), *keys)
return dic.get(key)
client = SoftLayer.Client(username=SL_USERNAME, api_key=SL_API_KEY)
networkStorage = client['Account'].getNetworkStorage(mask=_maskNetworkStorage)
#networkStorage = client['Account'].getIscsiNetworkStorage(mask=_maskNetworkStorage)
# Table definition
table = PrettyTable(_tableHeader)
table.padding_width = 1
for ns in networkStorage:
table.add_row(
[
ns['id'],
ns['nasType'],
lookup(ns, 'serviceResource', 'datacenter', 'name') or '-',
ns['username'],
ns['capacityGb'],
lookup(ns, 'iops') or '-' ,
ns['serviceResourceName'],
ns['serviceResourceBackendIpAddress'],
lookup(ns, 'serviceResource', 'type', 'type') or '-',
lookup(ns, 'hardware') or '-',
lookup(ns, 'vendorName') or '-',
lookup(ns, 'osTypeId') or '-',
]
)
print(table)