forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage_utils.py
More file actions
110 lines (98 loc) · 2.96 KB
/
storage_utils.py
File metadata and controls
110 lines (98 loc) · 2.96 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""Utility functions for use with File and Block commands."""
# :license: MIT, see LICENSE for more details.
from SoftLayer.CLI import columns as column_helper
def _format_name(obj):
if obj['type'] == 'VIRTUAL':
return "{0}.{1}".format(obj['hostname'], obj['domain'])
elif obj['type'] == 'HARDWARE':
return "{0}.{1}".format(obj['hostname'], obj['domain'])
elif obj['type'] == 'SUBNET':
name = "{0}/{1}".format(
obj['networkIdentifier'],
obj['cidr']
)
if 'note' in obj.keys():
name = "{0} ({1})".format(name, obj['note'])
return name
elif obj['type'] == 'IP':
name = obj['ipAddress']
if 'note' in obj.keys():
name = "{0} ({1})".format(name, obj['note'])
return name
else:
raise Exception('Unknown type %s' % obj['type'])
COLUMNS = [
column_helper.Column('id', ('id',)),
column_helper.Column('name', _format_name, """
allowedVirtualGuests[hostname,domain],
allowedHardware[hostname,domain],
allowedSubnets[networkIdentifier,cidr,note],
allowedIpAddresses[ipAddress,note],
"""),
column_helper.Column('type', ('type',)),
column_helper.Column(
'private_ip_address',
('primaryBackendIpAddress',),
"""
allowedVirtualGuests.primaryBackendIpAddress
allowedHardware.primaryBackendIpAddress
allowedSubnets.primaryBackendIpAddress
allowedIpAddresses.primaryBackendIpAddress
"""),
column_helper.Column(
'source_subnet',
('allowedHost', 'sourceSubnet',),
"""
allowedVirtualGuests.allowedHost.sourceSubnet
allowedHardware.allowedHost.sourceSubnet
allowedSubnets.allowedHost.sourceSubnet
allowedIpAddresses.allowedHost.sourceSubnet
"""),
column_helper.Column(
'host_iqn',
('allowedHost', 'name',),
"""
allowedVirtualGuests.allowedHost.name
allowedHardware.allowedHost.name
allowedSubnets.allowedHost.name
allowedIpAddresses.allowedHost.name
"""),
column_helper.Column(
'username',
('allowedHost', 'credential', 'username',),
"""
allowedVirtualGuests.allowedHost.credential.username
allowedHardware.allowedHost.credential.username
allowedSubnets.allowedHost.credential.username
allowedIpAddresses.allowedHost.credential.username
"""),
column_helper.Column(
'password',
('allowedHost', 'credential', 'password',),
"""
allowedVirtualGuests.allowedHost.credential.password
allowedHardware.allowedHost.credential.password
allowedSubnets.allowedHost.credential.password
allowedIpAddresses.allowedHost.credential.password
"""),
column_helper.Column(
'allowed_host_id',
('allowedHost', 'id',),
"""
allowedVirtualGuests.allowedHost.id
allowedHardware.allowedHost.id
allowedSubnets.allowedHost.id
allowedIpAddresses.allowedHost.id
"""),
]
DEFAULT_COLUMNS = [
'id',
'name',
'type',
'private_ip_address',
'source_subnet',
'host_iqn',
'username',
'password',
'allowed_host_id',
]