-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_server.py
More file actions
59 lines (47 loc) · 1.8 KB
/
virtual_server.py
File metadata and controls
59 lines (47 loc) · 1.8 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
import SoftLayer
import ConfigParser
from SoftLayer.managers.vs import VSManager
class VirtualServer:
def __init__(self):
self.conf = ConfigParser.ConfigParser()
self.conf.read('client_info.conf')
self.username = self.get_config_val('DEFAULT', 'username')
self.api_key = self.get_config_val('DEFAULT', 'api_key')
self.client = SoftLayer.Client(username=self.username, api_key=self.api_key)
self.virtual_server_manager = VSManager(self.client)
def get_config_val(self, section, field):
return self.conf.get(section, field)
def list_virtual_server(self):
"""
1. Function signature
list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
memory=None, hostname=None, domain=None,
local_disk=None, datacenter=None, nic_speed=None,
public_ip=None, private_ip=None, **kwargs):
**kwargs can be mask, limits and so on.
2. Can have following masks
'id',
'globalIdentifier',
'hostname',
'domain',
'fullyQualifiedDomainName',
'primaryBackendIpAddress',
'primaryIpAddress',
'lastKnownPowerState.name',
'powerState',
'maxCpu',
'maxMemory',
'datacenter',
'activeTransaction.transactionStatus[friendlyName,name]',
'status',
:return: list of virtual servers
"""
mask = 'id,hostname'
return self.virtual_server_manager.list_instances(mask=mask)
def main():
vs = VirtualServer()
virtual_server_list = vs.list_virtual_server()
for vs in virtual_server_list:
print vs['id'], '--', vs['hostname']
if __name__ == '__main__':
main()