Revision 1ad949a7 kamaki/clients/cyclades/__init__.py

b/kamaki/clients/cyclades/__init__.py
407 407
        return self._wait(
408 408
            server_id, current_status, get_status, delay, max_wait, wait_cb)
409 409

  
410
    def get_floating_ip_pools(self):
411
        """
412
        :returns: (dict) {floating_ip_pools:[{name: ...}, ...]}
413
        """
414
        r = self.floating_ip_pools_get()
415
        return r.json
416

  
417
    def get_floating_ips(self):
418
        """
419
        :returns: (dict) {floating_ips: [fixed_ip: , id: , ip: , pool: ]}
420
        """
421
        r = self.floating_ips_get()
422
        return r.json
423

  
424
    def alloc_floating_ip(self, pool=None, address=None):
425
        """
426
        :param pool: (str) pool of ips to allocate from
427

  
428
        :param address: (str) ip address to request
429

  
430
        :returns: (dict) {
431
            fixed_ip: ..., id: ..., instance_id: ..., ip: ..., pool: ...}
432
        """
433
        json_data = dict()
434
        if pool:
435
            json_data['pool'] = pool
436
        if address:
437
            json_data['address'] = address
438
        r = self.floating_ips_post(json_data)
439
        return r.json['floating_ip']
440

  
441
    def get_floating_ip(self, fip_id):
442
        """
443
        :param fip_id: (str) floating ip id
444

  
445
        :returns: (dict)
446
            {fixed_ip: ..., id: ..., instance_id: ..., ip: ..., pool: ...},
447

  
448
        :raises AssertionError: if fip_id is emtpy
449
        """
450
        assert fip_id, 'floating ip id is needed for get_floating_ip'
451
        r = self.floating_ips_get(fip_id)
452
        return r.json['floating_ip']
453

  
454
    def delete_floating_ip(self, fip_id=None):
455
        """
456
        :param fip_id: (str) floating ip id (if None, all ips are deleted)
457

  
458
        :returns: (dict) request headers
459

  
460
        :raises AssertionError: if fip_id is emtpy
461
        """
462
        assert fip_id, 'floating ip id is needed for delete_floating_ip'
463
        r = self.floating_ips_delete(fip_id)
464
        return r.headers
465

  
466
    def attach_floating_ip(self, server_id, address):
467
        """Associate the address ip to server with server_id
468

  
469
        :param server_id: (int)
470

  
471
        :param address: (str) the ip address to assign to server (vm)
472

  
473
        :returns: (dict) request headers
474

  
475
        :raises ValueError: if server_id cannot be converted to int
476

  
477
        :raises ValueError: if server_id is not of a int-convertable type
478

  
479
        :raises AssertionError: if address is emtpy
480
        """
481
        server_id = int(server_id)
482
        assert address, 'address is needed for attach_floating_ip'
483
        req = dict(addFloatingIp=dict(address=address))
484
        r = self.servers_action_post(server_id, json_data=req)
485
        return r.headers
486

  
487
    def detach_floating_ip(self, server_id, address):
488
        """Disassociate an address ip from the server with server_id
489

  
490
        :param server_id: (int)
491

  
492
        :param address: (str) the ip address to assign to server (vm)
493

  
494
        :returns: (dict) request headers
495

  
496
        :raises ValueError: if server_id cannot be converted to int
497

  
498
        :raises ValueError: if server_id is not of a int-convertable type
499

  
500
        :raises AssertionError: if address is emtpy
501
        """
502
        server_id = int(server_id)
503
        assert address, 'address is needed for detach_floating_ip'
504
        req = dict(removeFloatingIp=dict(address=address))
505
        r = self.servers_action_post(server_id, json_data=req)
506
        return r.headers
507

  
508 410

  
509 411
class CycladesNetworkClient(NetworkClient):
510 412
    """Cyclades Network API extentions"""

Also available in: Unified diff