File: object_storage.py

package info (click to toggle)
python-softlayer 5.8.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,888 kB
  • sloc: python: 41,631; makefile: 289; sh: 43
file content (98 lines) | stat: -rw-r--r-- 3,190 bytes parent folder | download
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
"""
    SoftLayer.object_storage
    ~~~~~~~~~~~~~~~~~~~~~~~~
    Object Storage Manager/helpers

    :license: MIT, see LICENSE for more details.
"""

LIST_ACCOUNTS_MASK = '''mask[
    id,username,notes,vendorName,serviceResource
]'''

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."""
        return self.client.call('Account', 'getHubNetworkStorage',
                                mask=LIST_ACCOUNTS_MASK)

    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

    def create_credential(self, identifier):
        """Create object storage credential.

        :param int identifier: The object storage account identifier.

        """

        return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'credentialCreate',
                                id=identifier)

    def delete_credential(self, identifier, credential_id=None):
        """Delete the object storage credential.

        :param int id: The object storage account identifier.
        :param int credential_id: The credential id to be deleted.

        """
        credential = {
            'id': credential_id
        }

        return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'credentialDelete',
                                credential, id=identifier)

    def limit_credential(self, identifier):
        """Limit object storage credentials.

        :param int identifier: The object storage account identifier.

        """

        return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getCredentialLimit',
                                id=identifier)

    def list_credential(self, identifier):
        """List the object storage credentials.

        :param int identifier: The object storage account identifier.

        """

        return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getCredentials',
                                id=identifier)