Revision 9b47150e

b/kamaki/cli/commands/cyclades.py
48 48
server_cmds = CommandTree('server', 'Cyclades/Compute API server commands')
49 49
flavor_cmds = CommandTree('flavor', 'Cyclades/Compute API flavor commands')
50 50
network_cmds = CommandTree('network', 'Cyclades/Compute API network commands')
51
floatingip_cmds = CommandTree(
52
    'floatingip', 'Cyclades/Compute API floating ip commands')
51 53
_commands = [server_cmds, flavor_cmds, network_cmds]
52 54

  
53 55

  
......
719 721
        super(self.__class__, self)._run()
720 722
        server_id = self._server_id_from_nic(nic_id=nic_id)
721 723
        self._run(nic_id=nic_id, server_id=server_id)
724

  
725

  
726
@command(floatingip_cmds)
727
class floatingip_pools(_init_cyclades, _optional_json):
728
    """List all floating pools of floating ips"""
729

  
730
    @errors.generic.all
731
    @errors.cyclades.connection
732
    def _run(self):
733
        r = self.client.get_floating_ip_pools()
734
        self._print(r if self['json_output'] else r['floating_ip_pools'])
735

  
736
    def main(self):
737
        super(self.__class__, self)._run()
738
        self._run()
739

  
740

  
741
@command(floatingip_cmds)
742
class floatingip_list(_init_cyclades, _optional_json):
743
    """List all floating ips"""
744

  
745
    @errors.generic.all
746
    @errors.cyclades.connection
747
    def _run(self):
748
        r = self.client.get_floating_ips()
749
        self._print(r if self['json_output'] else r['floating_ips'])
750

  
751
    def main(self):
752
        super(self.__class__, self)._run()
753
        self._run()
754

  
755

  
756
@command(floatingip_cmds)
757
class floatingip_info(_init_cyclades, _optional_json):
758
    """A floating IPs' details"""
759

  
760
    @errors.generic.all
761
    @errors.cyclades.connection
762
    def _run(self, ip):
763
        self._print(self.client.get_floating_ip(ip), print_dict)
764

  
765
    def main(self, ip):
766
        super(self.__class__, self)._run()
767
        self._run(ip=ip)
768

  
769

  
770
@command(floatingip_cmds)
771
class floatingip_create(_init_cyclades, _optional_json):
772
    """Create a new floating IP"""
773

  
774
    arguments = dict(
775
        pool=ValueArgument('Source IP pool', ('--pool'), None)
776
    )
777

  
778
    @errors.generic.all
779
    @errors.cyclades.connection
780
    def _run(self, ip=None):
781
        self._print(
782
            self.client.alloc_floating_ip(self['pool'], ip), print_dict)
783

  
784
    def main(self, requested_address=None):
785
        super(self.__class__, self)._run()
786
        self._run(ip=requested_address)
787

  
788

  
789
@command(floatingip_cmds)
790
class floatingip_delete(_init_cyclades, _optional_output_cmd):
791
    """Delete a floating ip"""
792

  
793
    @errors.generic.all
794
    @errors.cyclades.connection
795
    def _run(self, ip):
796
        self._optional_output(self.client.delete_floating_ip(ip))
797

  
798
    def main(self, ip):
799
        super(self.__class__, self)._run()
800
        self._run(ip=ip)
801

  
802

  
803
@command(server_cmds)
804
class server_ip_attach(_init_cyclades, _optional_output_cmd):
805
    """Attach a floating ip to a server with server_id
806
    """
807

  
808
    @errors.generic.all
809
    @errors.cyclades.connection
810
    @errors.cyclades.server_id
811
    def _run(self, server_id, ip):
812
        self._optional_output(self.client.attach_floating_ip(server_id, ip))
813

  
814
    def main(self, server_id, ip):
815
        super(self.__class__, self)._run()
816
        self._run(server_id=server_id, ip=ip)
817

  
818

  
819
@command(server_cmds)
820
class server_ip_detach(_init_cyclades):
821
    """detach_floating_ip_to_server
822
    """
823

  
824
    @errors.generic.all
825
    @errors.cyclades.connection
826
    @errors.cyclades.server_id
827
    def _run(self, server_id, ip):
828
        self._optional_output(self.client.detach_floating_ip(server_id, ip))
829

  
830
    def main(self, server_id, ip):
831
        super(self.__class__, self)._run()
832
        self._run(server_id=server_id, ip=ip)
b/kamaki/cli/commands/errors.py
50 50
            try:
51 51
                return foo(self, *args, **kwargs)
52 52
            except Exception as e:
53
                print 'BUH?'
53 54
                if _debug:
54 55
                    print_stack()
55 56
                    print_exc(e)
b/kamaki/cli/commands/snf-astakos.py
40 40
from kamaki.cli.command_tree import CommandTree
41 41
from kamaki.cli.utils import print_dict
42 42
from kamaki.cli.argument import FlagArgument, ValueArgument
43
from kamaki.cli.logger import add_file_logger, get_logger, logging
43
from kamaki.cli.logger import get_logger
44 44

  
45 45
snfastakos_cmds = CommandTree('astakos', 'astakosclient CLI')
46 46
_commands = [snfastakos_cmds]
b/kamaki/clients/cyclades/__init__.py
377 377
        r = self.floating_ips_delete(fip_id)
378 378
        return r.headers
379 379

  
380
    def assoc_floating_ip_to_server(self, server_id, address):
380
    def attach_floating_ip(self, server_id, address):
381 381
        """Associate the address ip to server with server_id
382 382

  
383 383
        :param server_id: (int)
......
393 393
        :raises AssertionError: if address is emtpy
394 394
        """
395 395
        server_id = int(server_id)
396
        assert address, 'address is needed for assoc_floating_ip_to_server'
396
        assert address, 'address is needed for attach_floating_ip'
397 397
        r = self.servers_post(
398 398
            server_id, 'action',
399 399
            json_data=dict(addFloatingIp=dict(address=address)))
400 400
        return r.headers
401 401

  
402
    def disassoc_floating_ip_to_server(self, server_id, address):
402
    def detach_floating_ip(self, server_id, address):
403 403
        """Disassociate an address ip from the server with server_id
404 404

  
405 405
        :param server_id: (int)
......
415 415
        :raises AssertionError: if address is emtpy
416 416
        """
417 417
        server_id = int(server_id)
418
        assert address, 'address is needed for disassoc_floating_ip_to_server'
418
        assert address, 'address is needed for detach_floating_ip'
419 419
        r = self.servers_post(
420 420
            server_id, 'action',
421 421
            json_data=dict(removeFloatingIp=dict(address=address)))

Also available in: Unified diff