forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_storage.py
More file actions
58 lines (46 loc) · 1.84 KB
/
object_storage.py
File metadata and controls
58 lines (46 loc) · 1.84 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
"""
SoftLayer.object_storage
~~~~~~~~~~~~~~~~~~~~~~~~
Object Storage Manager/helpers
:license: MIT, see LICENSE for more details.
"""
LIST_ACCOUNTS_MASK = '''mask(SoftLayer_Network_Storage_Hub_Swift)[
id,username,notes
]'''
ENDPOINT_MASK = '''mask(SoftLayer_Network_Storage_Hub_Swift)[
id,storageNodes[id,backendIpAddress,frontendIpAddress,datacenter]
]'''
class ObjectStorageManager(object):
"""Manager for SoftLayer Object Storage accounts.
See product information here: http://www.softlayer.com/object-storage
:param SoftLayer.API.BaseClient client: the client instance
"""
def __init__(self, client):
self.client = client
def list_accounts(self):
"""Lists your object storage accounts."""
_filter = {
'hubNetworkStorage': {'vendorName': {'operation': 'Swift'}},
}
return self.client.call('Account', 'getHubNetworkStorage',
mask=LIST_ACCOUNTS_MASK,
filter=_filter)
def list_endpoints(self):
"""Lists the known object storage endpoints."""
_filter = {
'hubNetworkStorage': {'vendorName': {'operation': 'Swift'}},
}
endpoints = []
network_storage = self.client.call('Account',
'getHubNetworkStorage',
mask=ENDPOINT_MASK,
limit=1,
filter=_filter)
if network_storage:
for node in network_storage['storageNodes']:
endpoints.append({
'datacenter': node['datacenter'],
'public': node['frontendIpAddress'],
'private': node['backendIpAddress'],
})
return endpoints