Revision 89a1c636 kamaki/clients/cyclades/__init__.py
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
35 | 35 |
from kamaki.clients.network import NetworkClient |
36 | 36 |
from kamaki.clients.utils import path4url |
37 | 37 |
from kamaki.clients import ClientError, Waiter |
38 |
|
|
38 |
import json |
|
39 | 39 |
|
40 | 40 |
class CycladesClient(CycladesRestClient, Waiter): |
41 | 41 |
"""Synnefo Cyclades Compute API client""" |
42 | 42 |
|
43 | 43 |
def create_server( |
44 | 44 |
self, name, flavor_id, image_id, |
45 |
metadata=None, personality=None, networks=None): |
|
45 |
metadata=None, personality=None, networks=None, project=None):
|
|
46 | 46 |
"""Submit request to create a new server |
47 | 47 |
|
48 | 48 |
:param name: (str) |
... | ... | |
64 | 64 |
ATTENTION: Empty list is different to None. None means ' do not |
65 | 65 |
mention it', empty list means 'automatically get an ip' |
66 | 66 |
|
67 |
:param project: the project where to assign the server |
|
68 |
|
|
67 | 69 |
:returns: a dict with the new virtual server details |
68 | 70 |
|
69 | 71 |
:raises ClientError: wraps request errors |
... | ... | |
78 | 80 |
|
79 | 81 |
return super(CycladesClient, self).create_server( |
80 | 82 |
name, flavor_id, image_id, |
81 |
metadata=metadata, personality=personality, networks=networks) |
|
83 |
metadata=metadata, personality=personality, networks=networks, |
|
84 |
project=project) |
|
82 | 85 |
|
83 | 86 |
def start_server(self, server_id): |
84 | 87 |
"""Submit a startup request |
... | ... | |
112 | 115 |
r = self.servers_action_post(server_id, json_data=req, success=200) |
113 | 116 |
return r.json['console'] |
114 | 117 |
|
118 |
def reassign_server(self, server_id, project): |
|
119 |
req = {'reassign': {'project': project}} |
|
120 |
r = self.servers_action_post(server_id, json_data=req, success=200) |
|
121 |
return r.headers |
|
122 |
|
|
115 | 123 |
def get_server_stats(self, server_id): |
116 | 124 |
""" |
117 | 125 |
:param server_id: integer (str or int) |
... | ... | |
169 | 177 |
r = self.get(path, success=200) |
170 | 178 |
return r.json['networks'] |
171 | 179 |
|
172 |
def create_network(self, type, name=None, shared=None): |
|
180 |
def create_network(self, type, name=None, shared=None, project=None):
|
|
173 | 181 |
req = dict(network=dict(type=type, admin_state_up=True)) |
174 | 182 |
if name: |
175 | 183 |
req['network']['name'] = name |
176 | 184 |
if shared not in (None, ): |
177 | 185 |
req['network']['shared'] = bool(shared) |
186 |
if project is not None: |
|
187 |
req['network']['project'] = project |
|
178 | 188 |
r = self.networks_post(json_data=req, success=201) |
179 | 189 |
return r.json['network'] |
180 | 190 |
|
191 |
def networks_action_post( |
|
192 |
self, network_id='', json_data=None, success=202, **kwargs): |
|
193 |
"""POST base_url/networks/<network_id>/action |
|
194 |
|
|
195 |
:returns: request response |
|
196 |
""" |
|
197 |
if json_data: |
|
198 |
json_data = json.dumps(json_data) |
|
199 |
self.set_header('Content-Type', 'application/json') |
|
200 |
self.set_header('Content-Length', len(json_data)) |
|
201 |
path = path4url('networks', network_id, 'action') |
|
202 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
203 |
|
|
204 |
def reassign_network(self, network_id, project): |
|
205 |
req = {'reassign': {'project': project}} |
|
206 |
r = self.networks_action_post(network_id, json_data=req, success=200) |
|
207 |
return r.headers |
|
208 |
|
|
181 | 209 |
def list_ports(self, detail=None): |
182 | 210 |
path = path4url('ports', 'detail' if detail else '') |
183 | 211 |
r = self.get(path, success=200) |
... | ... | |
204 | 232 |
r = self.ports_post(json_data=dict(port=port), success=201) |
205 | 233 |
return r.json['port'] |
206 | 234 |
|
207 |
def create_floatingip(self, floating_network_id, floating_ip_address=''): |
|
235 |
def create_floatingip(self, floating_network_id, floating_ip_address='', |
|
236 |
project=None): |
|
237 |
args = {"project": project} |
|
208 | 238 |
return super(CycladesNetworkClient, self).create_floatingip( |
209 |
floating_network_id, floating_ip_address=floating_ip_address) |
|
239 |
floating_network_id, floating_ip_address=floating_ip_address, |
|
240 |
args=args) |
|
210 | 241 |
|
211 | 242 |
def update_floatingip(self, floating_network_id, floating_ip_address=''): |
212 | 243 |
"""To nullify something optional, use None""" |
213 | 244 |
return super(CycladesNetworkClient, self).update_floatingip( |
214 | 245 |
floating_network_id, floating_ip_address=floating_ip_address) |
246 |
|
|
247 |
def floating_ip_action_post( |
|
248 |
self, fip_id, json_data=None, success=202, **kwargs): |
|
249 |
"""POST base_url/floatingips/<fip_id>/action |
|
250 |
|
|
251 |
:returns: request response |
|
252 |
""" |
|
253 |
if json_data: |
|
254 |
json_data = json.dumps(json_data) |
|
255 |
self.set_header('Content-Type', 'application/json') |
|
256 |
self.set_header('Content-Length', len(json_data)) |
|
257 |
path = path4url('floatingips', fip_id, 'action') |
|
258 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
259 |
|
|
260 |
def reassign_floating_ip(self, floating_network_id, project): |
|
261 |
req = {'reassign': {'project': project}} |
|
262 |
r = self.floating_ip_action_post(floating_network_id, json_data=req) |
Also available in: Unified diff