From 4f92f7ba02c5eb2d418de9e1b50030cf68acc6d7 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Tue, 7 Jan 2014 09:13:53 +0000 Subject: [PATCH] Using floating-ip-{associate|disassociate} This patch implements a blueprint to add more consistency into nova command, especially for the subcommand "floating-ip-*" Currently when we want to associate or disassociate an ip with nova we have to use add-floating-ip and remove-floating-ip. This is not consitent with the actual scheme of the subcommands: example: nova image-* nova flavor-* nova floating-ip-* + In the client v1.1 this patch displays a deprecated message when printing the help message for add-floating-ip and remove-floating-ip. + In the client v3 this patch do nothing because all floating ip commands are being removed. $:~/python-novaclient$ nova help | grep floating add-floating-ip DEPRECATED, use floating-ip-associate instead. floating-ip-associate Associate a floating IP address to a server. floating-ip-bulk-create Bulk create floating ips by range. floating-ip-bulk-delete Bulk delete floating ips by range. floating-ip-bulk-list List all floating ips. floating-ip-create Allocate a floating IP for the current tenant. floating-ip-delete De-allocate a floating IP. floating-ip-disassociate Remove a floating IP address from a server. floating-ip-list List floating ips for this tenant. floating-ip-pool-list List all floating ip pools. remove-floating-ip DEPRECATED, use floating-ip-disassociate instead. Implements: blueprint commands-floating-ip Change-Id: I5337d0f1ce5ec4826da6ecd2b6ae4ae7b97801e0 --- novaclient/tests/v1_1/test_shell.py | 10 ++++++++++ novaclient/v1_1/shell.py | 30 +++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index fa012a557..91f60c970 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -1054,6 +1054,16 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/servers/1234/action', {'removeFloatingIp': {'address': '11.0.0.1'}}) + def test_server_floating_ip_associate(self): + self.run_command('floating-ip-associate sample-server 11.0.0.1') + self.assert_called('POST', '/servers/1234/action', + {'addFloatingIp': {'address': '11.0.0.1'}}) + + def test_server_floating_ip_disassociate(self): + self.run_command('floating-ip-disassociate sample-server 11.0.0.1') + self.assert_called('POST', '/servers/1234/action', + {'removeFloatingIp': {'address': '11.0.0.1'}}) + def test_usage_list(self): self.run_command('usage-list --start 2000-01-20 --end 2005-02-01') self.assert_called('GET', diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index e6b3160a3..62e3f5066 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1925,7 +1925,22 @@ def do_console_log(cs, args): default=None, help='Fixed IP Address to associate with.') def do_add_floating_ip(cs, args): - """Add a floating IP address to a server.""" + """DEPRECATED, use floating-ip-associate instead.""" + _associate_floating_ip(cs, args) + + +@utils.arg('server', metavar='', help='Name or ID of server.') +@utils.arg('address', metavar='
', help='IP Address.') +@utils.arg('--fixed-address', + metavar='', + default=None, + help='Fixed IP Address to associate with.') +def do_floating_ip_associate(cs, args): + """Associate a floating IP address to a server.""" + _associate_floating_ip(cs, args) + + +def _associate_floating_ip(cs, args): server = _find_server(cs, args.server) server.add_floating_ip(args.address, args.fixed_address) @@ -1933,7 +1948,18 @@ def do_add_floating_ip(cs, args): @utils.arg('server', metavar='', help='Name or ID of server.') @utils.arg('address', metavar='
', help='IP Address.') def do_remove_floating_ip(cs, args): - """Remove a floating IP address from a server.""" + """DEPRECATED, use floating-ip-disassociate instead.""" + _disassociate_floating_ip(cs, args) + + +@utils.arg('server', metavar='', help='Name or ID of server.') +@utils.arg('address', metavar='
', help='IP Address.') +def do_floating_ip_disassociate(cs, args): + """Disassociate a floating IP address from a server.""" + _disassociate_floating_ip(cs, args) + + +def _disassociate_floating_ip(cs, args): server = _find_server(cs, args.server) server.remove_floating_ip(args.address)