Revision b6afe2ec 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 set_firewall_profile(self, server_id, profile, port_id): |
84 | 87 |
"""Set the firewall profile for the public interface of a server |
... | ... | |
123 | 126 |
r = self.servers_action_post(server_id, json_data=req, success=200) |
124 | 127 |
return r.json['console'] |
125 | 128 |
|
129 |
def reassign_server(self, server_id, project): |
|
130 |
req = {'reassign': {'project': project}} |
|
131 |
r = self.servers_action_post(server_id, json_data=req, success=200) |
|
132 |
return r.headers |
|
133 |
|
|
126 | 134 |
def get_server_stats(self, server_id): |
127 | 135 |
""" |
128 | 136 |
:param server_id: integer (str or int) |
... | ... | |
180 | 188 |
r = self.get(path, success=200) |
181 | 189 |
return r.json['networks'] |
182 | 190 |
|
183 |
def create_network(self, type, name=None, shared=None): |
|
191 |
def create_network(self, type, name=None, shared=None, project=None):
|
|
184 | 192 |
req = dict(network=dict(type=type, admin_state_up=True)) |
185 | 193 |
if name: |
186 | 194 |
req['network']['name'] = name |
187 | 195 |
if shared not in (None, ): |
188 | 196 |
req['network']['shared'] = bool(shared) |
197 |
if project is not None: |
|
198 |
req['network']['project'] = project |
|
189 | 199 |
r = self.networks_post(json_data=req, success=201) |
190 | 200 |
return r.json['network'] |
191 | 201 |
|
202 |
def networks_action_post( |
|
203 |
self, network_id='', json_data=None, success=202, **kwargs): |
|
204 |
"""POST base_url/networks/<network_id>/action |
|
205 |
|
|
206 |
:returns: request response |
|
207 |
""" |
|
208 |
if json_data: |
|
209 |
json_data = json.dumps(json_data) |
|
210 |
self.set_header('Content-Type', 'application/json') |
|
211 |
self.set_header('Content-Length', len(json_data)) |
|
212 |
path = path4url('networks', network_id, 'action') |
|
213 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
214 |
|
|
215 |
def reassign_network(self, network_id, project): |
|
216 |
req = {'reassign': {'project': project}} |
|
217 |
r = self.networks_action_post(network_id, json_data=req, success=200) |
|
218 |
return r.headers |
|
219 |
|
|
192 | 220 |
def list_ports(self, detail=None): |
193 | 221 |
path = path4url('ports', 'detail' if detail else '') |
194 | 222 |
r = self.get(path, success=200) |
... | ... | |
215 | 243 |
r = self.ports_post(json_data=dict(port=port), success=201) |
216 | 244 |
return r.json['port'] |
217 | 245 |
|
218 |
def create_floatingip(self, floating_network_id, floating_ip_address=''): |
|
246 |
def create_floatingip(self, floating_network_id, floating_ip_address='', |
|
247 |
project=None): |
|
248 |
args = {"project": project} |
|
219 | 249 |
return super(CycladesNetworkClient, self).create_floatingip( |
220 |
floating_network_id, floating_ip_address=floating_ip_address) |
|
250 |
floating_network_id, |
|
251 |
floating_ip_address=floating_ip_address, args=args) |
|
252 |
|
|
253 |
def floating_ip_action_post( |
|
254 |
self, fip_id, json_data=None, success=202, **kwargs): |
|
255 |
"""POST base_url/floatingips/<fip_id>/action |
|
256 |
|
|
257 |
:returns: request response |
|
258 |
""" |
|
259 |
if json_data: |
|
260 |
json_data = json.dumps(json_data) |
|
261 |
self.set_header('Content-Type', 'application/json') |
|
262 |
self.set_header('Content-Length', len(json_data)) |
|
263 |
path = path4url('floatingips', fip_id, 'action') |
|
264 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
265 |
|
|
266 |
def reassign_floating_ip(self, floating_network_id, project): |
|
267 |
req = {'reassign': {'project': project}} |
|
268 |
r = self.floating_ip_action_post(floating_network_id, json_data=req) |
Also available in: Unified diff