-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.py
102 lines (84 loc) · 2.83 KB
/
account.py
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
'''
Created on Mar 24, 2013
@author: mmartin
'''
from pymez.accept_header import ACCOUNT_INFO
from pymez.http import Http
import json
class Account(object):
'''
Representation of account information for the owner of this account
'''
def __init__(self,
url,
userid,
passwd,
headers={}):
'''
Initialize
'''
self.headers = headers
self.headers['Accept'] = ACCOUNT_INFO
self.passwd = passwd
self.url = url
self.userid = userid
self.http = Http(self.url,
headers=self.headers)
self._get()
def _get(self):
'''
Get the account information.
'''
status, content, _headers = self.http.GET()
if not status in [200]:
return None
self._account_info = json.loads(content)
self._account_type = \
self._account_info['account-info']['account_type']
self._allocated_bandwidth = \
self._account_info['account-info']['bandwidth']['allocated']
self._private_bandwidth = \
self._account_info['account-info']['bandwidth']['private']
self._public_bandwidth = \
self._account_info['account-info']['bandwidth']['public']
self._total_bandwidth = \
self._account_info['account-info']['bandwidth']['total']
self._mgmt_uri = \
self._account_info['account-info']['mgmt_uri']
self._s3_auth_id = \
self._account_info['account-info']['s3_auth_id']
self._s3_auth_key = \
self._account_info['account-info']['s3_auth_key']
self._allocated_storage = \
self._account_info['account-info']['storage']['allocated']
self._storage_used = \
self._account_info['account-info']['storage']['used']
self._username = \
self._account_info['account-info']['username']
def GET(self):
'''
Return the account information as a dictionary.
'''
return self._account_info
def get_account_type(self):
return self._account_type
def get_allocated_bandwidth(self):
return self._allocated_bandwidth
def get_private_bandwidth(self):
return self._private_bandwidth
def get_public_bandwidth(self):
return self._public_bandwidth
def get_total_bandwidth(self):
return self._total_bandwidth
def get_management_uri(self):
return self._mgmt_uri
def get_s3_auth_id(self):
return self._s3_auth_id
def get_s3_auth_key(self):
return self._s3_auth_key
def get_allocated_storage(self):
return self._allocated_storage
def get_storage_used(self):
return self._storage_used
def get_username(self):
return self._username