Revision 6a0b1658 kamaki/clients/cyclades.py
b/kamaki/clients/cyclades.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
import json |
|
35 |
|
|
36 | 34 |
from .compute import ComputeClient |
37 | 35 |
|
38 | 36 |
|
... | ... | |
41 | 39 |
|
42 | 40 |
def start_server(self, server_id): |
43 | 41 |
"""Submit a startup request for a server specified by id""" |
44 |
path = '/servers/%d/action' % server_id |
|
45 |
body = json.dumps({'start': {}}) |
|
46 |
self.http_post(path, body) |
|
42 |
|
|
43 |
path = '/servers/%s/action' % (server_id,) |
|
44 |
req = {'start': {}} |
|
45 |
self.post(path, json=req, success=202) |
|
47 | 46 |
|
48 | 47 |
def shutdown_server(self, server_id): |
49 | 48 |
"""Submit a shutdown request for a server specified by id""" |
50 |
path = '/servers/%d/action' % server_id |
|
51 |
body = json.dumps({'shutdown': {}}) |
|
52 |
self.http_post(path, body) |
|
49 |
|
|
50 |
path = '/servers/%s/action' % (server_id,) |
|
51 |
req = {'shutdown': {}} |
|
52 |
self.post(path, json=req, success=202) |
|
53 | 53 |
|
54 | 54 |
def get_server_console(self, server_id): |
55 | 55 |
"""Get a VNC connection to the console of a server specified by id""" |
56 |
path = '/servers/%d/action' % server_id |
|
57 |
body = json.dumps({'console': {'type': 'vnc'}}) |
|
58 |
reply = self.http_post(path, body, success=200) |
|
59 |
return reply['console'] |
|
56 |
|
|
57 |
path = '/servers/%s/action' % (server_id,) |
|
58 |
req = {'console': {'type': 'vnc'}} |
|
59 |
r = self.post(path, json=req, success=200) |
|
60 |
return r.json['console'] |
|
60 | 61 |
|
61 | 62 |
def set_firewall_profile(self, server_id, profile): |
62 | 63 |
"""Set the firewall profile for the public interface of a server |
... | ... | |
64 | 65 |
The server is specified by id, the profile argument |
65 | 66 |
is one of (ENABLED, DISABLED, PROTECTED). |
66 | 67 |
""" |
67 |
path = '/servers/%d/action' % server_id
|
|
68 |
body = json.dumps({'firewallProfile': {'profile': profile}})
|
|
69 |
self.http_post(path, body)
|
|
68 |
path = '/servers/%s/action' % (server_id,)
|
|
69 |
req = {'firewallProfile': {'profile': profile}}
|
|
70 |
self.post(path, json=req, success=202)
|
|
70 | 71 |
|
71 | 72 |
def list_server_addresses(self, server_id, network=None): |
72 |
path = '/servers/%d/ips' % server_id
|
|
73 |
path = '/servers/%s/ips' % (server_id,)
|
|
73 | 74 |
if network: |
74 | 75 |
path += '/%s' % network |
75 |
reply = self.http_get(path) |
|
76 |
return [reply['network']] if network else reply['addresses']['values'] |
|
76 |
r = self.get(path, success=200) |
|
77 |
if network: |
|
78 |
return [r.json['network']] |
|
79 |
else: |
|
80 |
return r.json['addresses']['values'] |
|
77 | 81 |
|
78 | 82 |
def get_server_stats(self, server_id): |
79 |
path = '/servers/%d/stats' % server_id
|
|
80 |
reply = self.http_get(path)
|
|
81 |
return reply['stats']
|
|
83 |
path = '/servers/%s/stats' % (server_id,)
|
|
84 |
r = self.get(path, success=200)
|
|
85 |
return r.json['stats']
|
|
82 | 86 |
|
83 | 87 |
|
84 | 88 |
def list_networks(self, detail=False): |
85 | 89 |
path = '/networks/detail' if detail else '/networks' |
86 |
reply = self.http_get(path)
|
|
87 |
return reply['networks']['values']
|
|
90 |
r = self.get(path, success=200)
|
|
91 |
return r.json['networks']['values']
|
|
88 | 92 |
|
89 | 93 |
def create_network(self, name): |
90 |
body = json.dumps({'network': {'name': name}})
|
|
91 |
reply = self.http_post('/networks', body)
|
|
92 |
return reply['network']
|
|
94 |
req = {'network': {'name': name}}
|
|
95 |
r = self.post('/networks', json=req, success=202)
|
|
96 |
return r.json['network']
|
|
93 | 97 |
|
94 | 98 |
def get_network_details(self, network_id): |
95 |
path = '/networks/%s' % network_id
|
|
96 |
reply = self.http_get(path)
|
|
97 |
return reply['network']
|
|
99 |
path = '/networks/%s' % (network_id,)
|
|
100 |
r = self.get(path, success=200)
|
|
101 |
return r.json['network']
|
|
98 | 102 |
|
99 | 103 |
def update_network_name(self, network_id, new_name): |
100 |
path = '/networks/%s' % network_id
|
|
101 |
body = json.dumps({'network': {'name': new_name}})
|
|
102 |
self.http_put(path, body)
|
|
104 |
path = '/networks/%s' % (network_id,)
|
|
105 |
req = {'network': {'name': new_name}}
|
|
106 |
self.put(path, json=req, success=204)
|
|
103 | 107 |
|
104 | 108 |
def delete_network(self, network_id): |
105 |
path = '/networks/%s' % network_id
|
|
106 |
self.http_delete(path)
|
|
109 |
path = '/networks/%s' % (network_id,)
|
|
110 |
self.delete(path, success=204)
|
|
107 | 111 |
|
108 | 112 |
def connect_server(self, server_id, network_id): |
109 |
path = '/networks/%s/action' % network_id
|
|
110 |
body = json.dumps({'add': {'serverRef': server_id}})
|
|
111 |
self.http_post(path, body)
|
|
113 |
path = '/networks/%s/action' % (network_id,)
|
|
114 |
req = {'add': {'serverRef': server_id}}
|
|
115 |
self.post(path, json=req, success=202)
|
|
112 | 116 |
|
113 | 117 |
def disconnect_server(self, server_id, network_id): |
114 |
path = '/networks/%s/action' % network_id |
|
115 |
body = json.dumps({'remove': {'serverRef': server_id}}) |
|
116 |
self.http_post(path, body) |
|
118 |
path = '/networks/%s/action' % (network_id,) |
|
119 |
req = {'remove': {'serverRef': server_id}} |
|
120 |
self.post(path, json=req, success=202) |
Also available in: Unified diff