Commit 9b47150e authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Expose impemented floating IP methods

New commands:

floatingip list/create/delete/info/pools
server ip attach/detach

Also, renamed the assoc/disassoc floating ip clients methods to
attach/detach_floating_ip
parent 56d361de
......@@ -48,6 +48,8 @@ from os.path import exists
server_cmds = CommandTree('server', 'Cyclades/Compute API server commands')
flavor_cmds = CommandTree('flavor', 'Cyclades/Compute API flavor commands')
network_cmds = CommandTree('network', 'Cyclades/Compute API network commands')
floatingip_cmds = CommandTree(
'floatingip', 'Cyclades/Compute API floating ip commands')
_commands = [server_cmds, flavor_cmds, network_cmds]
......@@ -719,3 +721,112 @@ class network_disconnect(_init_cyclades):
super(self.__class__, self)._run()
server_id = self._server_id_from_nic(nic_id=nic_id)
self._run(nic_id=nic_id, server_id=server_id)
@command(floatingip_cmds)
class floatingip_pools(_init_cyclades, _optional_json):
"""List all floating pools of floating ips"""
@errors.generic.all
@errors.cyclades.connection
def _run(self):
r = self.client.get_floating_ip_pools()
self._print(r if self['json_output'] else r['floating_ip_pools'])
def main(self):
super(self.__class__, self)._run()
self._run()
@command(floatingip_cmds)
class floatingip_list(_init_cyclades, _optional_json):
"""List all floating ips"""
@errors.generic.all
@errors.cyclades.connection
def _run(self):
r = self.client.get_floating_ips()
self._print(r if self['json_output'] else r['floating_ips'])
def main(self):
super(self.__class__, self)._run()
self._run()
@command(floatingip_cmds)
class floatingip_info(_init_cyclades, _optional_json):
"""A floating IPs' details"""
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip):
self._print(self.client.get_floating_ip(ip), print_dict)
def main(self, ip):
super(self.__class__, self)._run()
self._run(ip=ip)
@command(floatingip_cmds)
class floatingip_create(_init_cyclades, _optional_json):
"""Create a new floating IP"""
arguments = dict(
pool=ValueArgument('Source IP pool', ('--pool'), None)
)
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip=None):
self._print(
self.client.alloc_floating_ip(self['pool'], ip), print_dict)
def main(self, requested_address=None):
super(self.__class__, self)._run()
self._run(ip=requested_address)
@command(floatingip_cmds)
class floatingip_delete(_init_cyclades, _optional_output_cmd):
"""Delete a floating ip"""
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip):
self._optional_output(self.client.delete_floating_ip(ip))
def main(self, ip):
super(self.__class__, self)._run()
self._run(ip=ip)
@command(server_cmds)
class server_ip_attach(_init_cyclades, _optional_output_cmd):
"""Attach a floating ip to a server with server_id
"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
def _run(self, server_id, ip):
self._optional_output(self.client.attach_floating_ip(server_id, ip))
def main(self, server_id, ip):
super(self.__class__, self)._run()
self._run(server_id=server_id, ip=ip)
@command(server_cmds)
class server_ip_detach(_init_cyclades):
"""detach_floating_ip_to_server
"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
def _run(self, server_id, ip):
self._optional_output(self.client.detach_floating_ip(server_id, ip))
def main(self, server_id, ip):
super(self.__class__, self)._run()
self._run(server_id=server_id, ip=ip)
......@@ -50,6 +50,7 @@ class generic(object):
try:
return foo(self, *args, **kwargs)
except Exception as e:
print 'BUH?'
if _debug:
print_stack()
print_exc(e)
......
......@@ -40,7 +40,7 @@ from kamaki.cli.commands import (
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict
from kamaki.cli.argument import FlagArgument, ValueArgument
from kamaki.cli.logger import add_file_logger, get_logger, logging
from kamaki.cli.logger import get_logger
snfastakos_cmds = CommandTree('astakos', 'astakosclient CLI')
_commands = [snfastakos_cmds]
......
......@@ -377,7 +377,7 @@ class CycladesClient(CycladesRestClient):
r = self.floating_ips_delete(fip_id)
return r.headers
def assoc_floating_ip_to_server(self, server_id, address):
def attach_floating_ip(self, server_id, address):
"""Associate the address ip to server with server_id
:param server_id: (int)
......@@ -393,13 +393,13 @@ class CycladesClient(CycladesRestClient):
:raises AssertionError: if address is emtpy
"""
server_id = int(server_id)
assert address, 'address is needed for assoc_floating_ip_to_server'
assert address, 'address is needed for attach_floating_ip'
r = self.servers_post(
server_id, 'action',
json_data=dict(addFloatingIp=dict(address=address)))
return r.headers
def disassoc_floating_ip_to_server(self, server_id, address):
def detach_floating_ip(self, server_id, address):
"""Disassociate an address ip from the server with server_id
:param server_id: (int)
......@@ -415,7 +415,7 @@ class CycladesClient(CycladesRestClient):
:raises AssertionError: if address is emtpy
"""
server_id = int(server_id)
assert address, 'address is needed for disassoc_floating_ip_to_server'
assert address, 'address is needed for detach_floating_ip'
r = self.servers_post(
server_id, 'action',
json_data=dict(removeFloatingIp=dict(address=address)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment