Commit d1bced10 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Expose Network floatingip commands

Refs: #4583, #4563
parent 8fd99602
......@@ -41,7 +41,7 @@ from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import remove_from_items, filter_dicts_by_dict
from kamaki.cli.errors import (
raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
from kamaki.clients.cyclades import CycladesClient, ClientError
from kamaki.clients.cyclades import CycladesClient
from kamaki.cli.argument import (
FlagArgument, ValueArgument, KeyValueArgument, RepeatableArgument,
ProgressBarArgument, DateArgument, IntArgument)
......@@ -54,7 +54,7 @@ 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')
ip_cmds = CommandTree('ip', 'Cyclades/Compute API floating ip commands')
_commands = [server_cmds, flavor_cmds, network_cmds, ip_cmds]
_commands = [server_cmds, flavor_cmds, network_cmds]
about_authentication = '\nUser Authentication:\
......@@ -889,100 +889,3 @@ class network_wait(_init_cyclades, _network_wait):
def main(self, network_id, current_status='PENDING'):
super(self.__class__, self)._run()
self._run(network_id=network_id, current_status=current_status)
@command(ip_cmds)
class ip_pools(_init_cyclades, _optional_json):
"""List 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'] or self['output_format'] else r[
'floating_ip_pools'])
def main(self):
super(self.__class__, self)._run()
self._run()
@command(ip_cmds)
class ip_list(_init_cyclades, _optional_json):
"""List reserved floating IPs"""
@errors.generic.all
@errors.cyclades.connection
def _run(self):
r = self.client.get_floating_ips()
self._print(r if self['json_output'] or self['output_format'] else r[
'floating_ips'])
def main(self):
super(self.__class__, self)._run()
self._run()
@command(ip_cmds)
class ip_info(_init_cyclades, _optional_json):
"""Details for an IP"""
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip):
self._print(self.client.get_floating_ip(ip), self.print_dict)
def main(self, IP):
super(self.__class__, self)._run()
self._run(ip=IP)
@command(ip_cmds)
class ip_reserve(_init_cyclades, _optional_json):
"""Reserve a floating IP
An IP is reserved from an IP pool. The default IP pool is chosen
automatically, but there is the option if specifying an explicit IP pool.
"""
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)])
def main(self, requested_IP=None):
super(self.__class__, self)._run()
self._run(ip=requested_IP)
@command(ip_cmds)
class ip_release(_init_cyclades, _optional_output_cmd):
"""Release a floating IP
The release IP is "returned" to the IP pool it came from.
"""
@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(ip_cmds)
class ip_attach(_init_cyclades, _optional_output_cmd):
"""DEPRECATED, use /port create"""
def main(self):
raise CLISyntaxError('DEPRECATED, replaced by kamaki port create')
@command(ip_cmds)
class ip_detach(_init_cyclades, _optional_output_cmd):
"""DEPRECATED, use /port delete"""
def main(self):
raise CLISyntaxError('DEPRECATED, replaced by kamaki port delete')
......@@ -49,7 +49,8 @@ from kamaki.cli.utils import filter_dicts_by_dict
network_cmds = CommandTree('network', 'Networking API network commands')
port_cmds = CommandTree('port', 'Networking API network commands')
subnet_cmds = CommandTree('subnet', 'Networking API network commands')
_commands = [network_cmds, port_cmds, subnet_cmds]
ip_cmds = CommandTree('ip', 'Networking API floatingip commands')
_commands = [network_cmds, port_cmds, subnet_cmds, ip_cmds]
about_authentication = '\nUser Authentication:\
......@@ -470,8 +471,73 @@ class port_create(_init_network, _optional_json):
self._run(network_id=self['network_id'], device_id=self['device_id'])
# Warn users for some importand changes
@command(ip_cmds)
class ip_list(_init_network, _optional_json):
"""List reserved floating IPs"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.network_id
def _run(self):
self._print(self.client.list_floatingips())
def main(self):
super(self.__class__, self)._run()
self._run()
@command(ip_cmds)
class ip_info(_init_network, _optional_json):
"""Get details on a floating IP"""
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip_id):
self._print(self.client.get_floatingip_details(ip_id))
def main(self, ip_id):
super(self.__class__, self)._run()
self._run(ip_id=ip_id)
@command(ip_cmds)
class ip_create(_init_network, _optional_json):
"""Reserve an IP on a network"""
arguments = dict(
network_id=ValueArgument(
'The network to preserve the IP on', '--network-id'),
ip_address=ValueArgument('Allocate a specific IP address', '--address')
)
required = ('network_id', )
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.network_id
def _run(self, network_id):
self._print(
self.client.create_floatingip(
network_id, floating_ip_address=self['ip_address']),
self.print_dict)
def main(self):
super(self.__class__, self)._run()
self._run(network_id=self['network_id'])
@command(ip_cmds)
class ip_delete(_init_network, _optional_output_cmd):
"""Unreserve an IP (also delete the port, if attached)"""
def _run(self, ip_id):
self._optional_output(self.client.floatingip_delete(ip_id))
def main(self, ip_id):
super(self.__class__, self)._run()
self._run(ip_id=ip_id)
# Warn users for some importand changes
@command(network_cmds)
class network_connect(_init_network, _optional_output_cmd):
......
......@@ -89,7 +89,7 @@ DEFAULTS = {
'network_cli': 'network',
'subnet_cli': 'network',
'port_cli': 'network',
'ip_cli': 'cyclades',
'ip_cli': 'network',
'image_cli': 'image',
'imagecompute_cli': 'image',
'config_cli': 'config',
......
......@@ -321,7 +321,7 @@ class NetworkClient(NetworkRestClient):
r = self.ports_put(port_id, json_data=dict(port=port), success=201)
return r.json['port']
def list_floatingip(self):
def list_floatingips(self):
r = self.floatingips_get(success=200)
return r['floatingips']
......@@ -333,11 +333,11 @@ class NetworkClient(NetworkRestClient):
self, floating_network_id,
floating_ip_address='', port_id='', fixed_ip_address=''):
floatingip = dict(floating_network_id=floating_network_id)
if floating_ip_address != '':
if floating_ip_address:
floatingip['floating_ip_address'] = floating_ip_address
if port_id != '':
if port_id:
floatingip['port_id'] = port_id
if fixed_ip_address != '':
if fixed_ip_address:
floatingip['fixed_ip_address'] = fixed_ip_address
r = self.floatingips_post(
json_data=dict(floatingip=floatingip), success=201)
......
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