Revision 03033b54 kamaki/clients/cyclades/__init__.py
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
316 | 316 |
pass |
317 | 317 |
return r['status'] |
318 | 318 |
return False |
319 |
|
|
320 |
def get_floating_ip_pools(self): |
|
321 |
""" |
|
322 |
:returns: (dict) {floating_ip_pools:[{name: ...}, ...]} |
|
323 |
""" |
|
324 |
r = self.floating_ip_pools_get() |
|
325 |
return r.json |
|
326 |
|
|
327 |
def get_floating_ips(self): |
|
328 |
""" |
|
329 |
:returns: (dict) {floating_ips:[ |
|
330 |
{fixed_ip: ..., id: ..., instance_id: ..., ip: ..., pool: ...}, |
|
331 |
... ]} |
|
332 |
""" |
|
333 |
r = self.floating_ips_get() |
|
334 |
return r.json |
|
335 |
|
|
336 |
def alloc_floating_ip(self, pool=None, address=None): |
|
337 |
""" |
|
338 |
:param pool: (str) pool of ips to allocate from |
|
339 |
|
|
340 |
:param address: (str) ip address to request |
|
341 |
|
|
342 |
:returns: (dict) { |
|
343 |
fixed_ip: ..., id: ..., instance_id: ..., ip: ..., pool: ... |
|
344 |
} |
|
345 |
""" |
|
346 |
json_data = dict() |
|
347 |
if pool: |
|
348 |
json_data['pool'] = pool |
|
349 |
if address: |
|
350 |
json_data['address'] = address |
|
351 |
r = self.floating_ips_post(json_data) |
|
352 |
return r.json['floating_ip'] |
|
353 |
|
|
354 |
def get_floating_ip(self, fip_id): |
|
355 |
""" |
|
356 |
:param fip_id: (str) floating ip id |
|
357 |
|
|
358 |
:returns: (dict) |
|
359 |
{fixed_ip: ..., id: ..., instance_id: ..., ip: ..., pool: ...}, |
|
360 |
|
|
361 |
:raises AssertionError: if fip_id is emtpy |
|
362 |
""" |
|
363 |
assert fip_id, 'floating ip id is needed for get_floating_ip' |
|
364 |
r = self.floating_ips_get(fip_id) |
|
365 |
return r.json['floating_ip'] |
|
366 |
|
|
367 |
def delete_floating_ip(self, fip_id=None): |
|
368 |
""" |
|
369 |
:param fip_id: (str) floating ip id (if None, all ips are deleted) |
|
370 |
|
|
371 |
:returns: (dict) request headers |
|
372 |
|
|
373 |
:raises AssertionError: if fip_id is emtpy |
|
374 |
""" |
|
375 |
assert fip_id, 'floating ip id is needed for delete_floating_ip' |
|
376 |
r = self.floating_ips_delete(fip_id) |
|
377 |
return r.headers |
|
378 |
|
|
379 |
def assoc_floating_ip_to_server(self, server_id, address): |
|
380 |
"""Associate the address ip to server with server_id |
|
381 |
|
|
382 |
:param server_id: (int) |
|
383 |
|
|
384 |
:param address: (str) the ip address to assign to server (vm) |
|
385 |
|
|
386 |
:returns: (dict) request headers |
|
387 |
|
|
388 |
:raises ValueError: if server_id cannot be converted to int |
|
389 |
|
|
390 |
:raises ValueError: if server_id is not of a int-convertable type |
|
391 |
|
|
392 |
:raises AssertionError: if address is emtpy |
|
393 |
""" |
|
394 |
server_id = int(server_id) |
|
395 |
assert address, 'address is needed for assoc_floating_ip_to_server' |
|
396 |
r = self.servers_post( |
|
397 |
server_id, 'action', |
|
398 |
json_data=dict(addFloatingIp=dict(address=address))) |
|
399 |
return r.headers |
|
400 |
|
|
401 |
def disassoc_floating_ip_to_server(self, server_id, address): |
|
402 |
"""Disassociate an address ip from the server with server_id |
|
403 |
|
|
404 |
:param server_id: (int) |
|
405 |
|
|
406 |
:param address: (str) the ip address to assign to server (vm) |
|
407 |
|
|
408 |
:returns: (dict) request headers |
|
409 |
|
|
410 |
:raises ValueError: if server_id cannot be converted to int |
|
411 |
|
|
412 |
:raises ValueError: if server_id is not of a int-convertable type |
|
413 |
|
|
414 |
:raises AssertionError: if address is emtpy |
|
415 |
""" |
|
416 |
server_id = int(server_id) |
|
417 |
assert address, 'address is needed for disassoc_floating_ip_to_server' |
|
418 |
r = self.servers_post( |
|
419 |
server_id, 'action', |
|
420 |
json_data=dict(removeFloatingIp=dict(address=address))) |
|
421 |
return r.headers |
Also available in: Unified diff