summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-04-07 14:10:37 +0800
committerTang Chen <chen.tang@easystack.cn>2016-07-04 10:40:59 +0800
commitd1f9ea3f750bb4c1f440ebfa93d06a40673ec0aa (patch)
tree559dfdb90602c15ad0d47baf2fb08fa501bbe9ca
parent50bd56db258a16199463afcdeb2f0579384cc711 (diff)
downloadpython-openstackclient-d1f9ea3f750bb4c1f440ebfa93d06a40673ec0aa.tar.gz
Transfer "ip floating add/remove" to "server add/remove
floating ip" This patch does the following things to transfer "ip floating add/remove" to "server add/remove floating ip": * Add new command "server add/remove floating ip", and unit tests and doc. * Deprecate "ip floating add/remove" command. compute/v2/floatingip.py is not removed because the arguments' positions are different between the new and old commands. * ip floating add <ip-address> <server> server add floating ip <server> <ip-address> * ip floating remove <ip-address> <server> server remove floating ip <server> <ip-address> Change-Id: Ic0dd22ca6fb7b7bc3e820fd5a14d7c551e7ab963 Implements: blueprint rework-ip-commands Partial-bug: 1555990 Co-Authored-By: Dean Troyer <dtroyer@gmail.com>
-rw-r--r--doc/source/command-objects/ip-floating.rst2
-rw-r--r--doc/source/command-objects/server.rst40
-rw-r--r--doc/source/commands.rst1
-rw-r--r--openstackclient/compute/v2/floatingip.py34
-rw-r--r--openstackclient/compute/v2/server.py55
-rw-r--r--openstackclient/tests/compute/v2/test_server.py67
-rw-r--r--releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml5
-rw-r--r--setup.cfg2
8 files changed, 202 insertions, 4 deletions
diff --git a/doc/source/command-objects/ip-floating.rst b/doc/source/command-objects/ip-floating.rst
index 8dd94782..378812d1 100644
--- a/doc/source/command-objects/ip-floating.rst
+++ b/doc/source/command-objects/ip-floating.rst
@@ -8,6 +8,7 @@ ip floating add
---------------
Add floating IP address to server
+(Deprecated, please use ``server add floating ip`` instead)
.. program:: ip floating add
.. code:: bash
@@ -92,6 +93,7 @@ ip floating remove
------------------
Remove floating IP address from server
+(Deprecated, please use ``server remove floating ip`` instead)
.. program:: ip floating remove
.. code:: bash
diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst
index f11355b6..3393e7fb 100644
--- a/doc/source/command-objects/server.rst
+++ b/doc/source/command-objects/server.rst
@@ -4,6 +4,26 @@ server
Compute v2
+server add floating ip
+----------------------
+
+Add floating IP address to server
+
+.. program:: server add floating ip
+.. code:: bash
+
+ os server add floating ip
+ <server>
+ <ip-address>
+
+.. describe:: <server>
+
+ Server (name or ID) to receive the floating IP address
+
+.. describe:: <ip-address>
+
+ Floating IP address (IP address only) to assign to server
+
server add security group
-------------------------
@@ -418,6 +438,26 @@ Rebuild server
Server (name or ID)
+server remove floating ip
+-------------------------
+
+Remove floating IP address from server
+
+.. program:: server remove floating ip
+.. code:: bash
+
+ os server remove floating ip
+ <server>
+ <ip-address>
+
+.. describe:: <server>
+
+ Server (name or ID) to remove the floating IP address from
+
+.. describe:: <ip-address>
+
+ Floating IP address (IP address only) to remove from server
+
server remove security group
----------------------------
diff --git a/doc/source/commands.rst b/doc/source/commands.rst
index 42268c25..714cd518 100644
--- a/doc/source/commands.rst
+++ b/doc/source/commands.rst
@@ -91,6 +91,7 @@ referring to both Compute and Volume quotas.
* ``extension``: (**Compute**, **Identity**, **Network**, **Volume**) OpenStack server API extensions
* ``federation protocol``: (**Identity**) the underlying protocol used while federating identities
* ``flavor``: (**Compute**) predefined server configurations: ram, root disk and so on
+* ``floating ip``: (**Compute**, **Network**) - a public IP address that can be mapped to a server
* ``floating ip pool``: (**Compute**, **Network**) - a pool of public IP addresses
* ``group``: (**Identity**) a grouping of users
* ``host``: (**Compute**) - the physical computer running compute services
diff --git a/openstackclient/compute/v2/floatingip.py b/openstackclient/compute/v2/floatingip.py
index 98079fbc..8398ea57 100644
--- a/openstackclient/compute/v2/floatingip.py
+++ b/openstackclient/compute/v2/floatingip.py
@@ -15,28 +15,43 @@
"""Floating IP action implementations"""
+import logging
+
from osc_lib.command import command
from osc_lib import utils
+from openstackclient.i18n import _
+
class AddFloatingIP(command.Command):
"""Add floating IP address to server"""
+ # TODO(tangchen): Remove this class and ``ip floating add`` command
+ # two cycles after Mitaka.
+
+ # This notifies cliff to not display the help for this command
+ deprecated = True
+
+ log = logging.getLogger('deprecated')
+
def get_parser(self, prog_name):
parser = super(AddFloatingIP, self).get_parser(prog_name)
parser.add_argument(
"ip_address",
metavar="<ip-address>",
- help="IP address to add to server (name only)",
+ help=_("IP address to add to server (name only)"),
)
parser.add_argument(
"server",
metavar="<server>",
- help="Server to receive the IP address (name or ID)",
+ help=_("Server to receive the IP address (name or ID)"),
)
return parser
def take_action(self, parsed_args):
+ self.log.warning(_('This command has been deprecated. '
+ 'Please use "server add floating ip" instead.'))
+
compute_client = self.app.client_manager.compute
server = utils.find_resource(
@@ -48,21 +63,32 @@ class AddFloatingIP(command.Command):
class RemoveFloatingIP(command.Command):
"""Remove floating IP address from server"""
+ # TODO(tangchen): Remove this class and ``ip floating remove`` command
+ # two cycles after Mitaka.
+
+ # This notifies cliff to not display the help for this command
+ deprecated = True
+
+ log = logging.getLogger('deprecated')
+
def get_parser(self, prog_name):
parser = super(RemoveFloatingIP, self).get_parser(prog_name)
parser.add_argument(
"ip_address",
metavar="<ip-address>",
- help="IP address to remove from server (name only)",
+ help=_("IP address to remove from server (name only)"),
)
parser.add_argument(
"server",
metavar="<server>",
- help="Server to remove the IP address from (name or ID)",
+ help=_("Server to remove the IP address from (name or ID)"),
)
return parser
def take_action(self, parsed_args):
+ self.log.warning(_('This command has been deprecated. '
+ 'Please use "server remove floating ip" instead.'))
+
compute_client = self.app.client_manager.compute
server = utils.find_resource(
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 7e4b0dc1..d7c3a656 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -174,6 +174,33 @@ def _show_progress(progress):
sys.stdout.flush()
+class AddFloatingIP(command.Command):
+ """Add floating IP address to server"""
+
+ def get_parser(self, prog_name):
+ parser = super(AddFloatingIP, self).get_parser(prog_name)
+ parser.add_argument(
+ "server",
+ metavar="<server>",
+ help=_("Server (name or ID) to receive the floating IP address"),
+ )
+ parser.add_argument(
+ "ip_address",
+ metavar="<ip-address>",
+ help=_("Floating IP address (IP address only) to assign "
+ "to server"),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ compute_client = self.app.client_manager.compute
+
+ server = utils.find_resource(
+ compute_client.servers, parsed_args.server)
+
+ server.add_floating_ip(parsed_args.ip_address)
+
+
class AddServerSecurityGroup(command.Command):
"""Add security group to server"""
@@ -1081,6 +1108,34 @@ class RebuildServer(command.ShowOne):
return zip(*sorted(six.iteritems(details)))
+class RemoveFloatingIP(command.Command):
+ """Remove floating IP address from server"""
+
+ def get_parser(self, prog_name):
+ parser = super(RemoveFloatingIP, self).get_parser(prog_name)
+ parser.add_argument(
+ "server",
+ metavar="<server>",
+ help=_("Server (name or ID) to remove the "
+ "floating IP address from"),
+ )
+ parser.add_argument(
+ "ip_address",
+ metavar="<ip-address>",
+ help=_("Floating IP address (IP address only) "
+ "to remove from server"),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ compute_client = self.app.client_manager.compute
+
+ server = utils.find_resource(
+ compute_client.servers, parsed_args.server)
+
+ server.remove_floating_ip(parsed_args.ip_address)
+
+
class RemoveServerSecurityGroup(command.Command):
"""Remove security group from server"""
diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py
index 0f155601..81f21856 100644
--- a/openstackclient/tests/compute/v2/test_server.py
+++ b/openstackclient/tests/compute/v2/test_server.py
@@ -88,6 +88,41 @@ class TestServer(compute_fakes.TestComputev2):
self.assertIsNone(result)
+class TestServerAddFloatingIP(TestServer):
+
+ def setUp(self):
+ super(TestServerAddFloatingIP, self).setUp()
+
+ # Get a shortcut to the compute client ServerManager Mock
+ self.networks_mock = self.app.client_manager.compute.networks
+
+ # Get the command object to test
+ self.cmd = server.AddFloatingIP(self.app, None)
+
+ # Set add_floating_ip method to be tested.
+ self.methods = {
+ 'add_floating_ip': None,
+ }
+
+ def test_server_add_floating_ip(self):
+ servers = self.setup_servers_mock(count=1)
+
+ arglist = [
+ servers[0].id,
+ '1.2.3.4',
+ ]
+ verifylist = [
+ ('server', servers[0].id),
+ ('ip_address', '1.2.3.4'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ servers[0].add_floating_ip.assert_called_once_with('1.2.3.4')
+ self.assertIsNone(result)
+
+
class TestServerCreate(TestServer):
columns = (
@@ -843,6 +878,38 @@ class TestServerRebuild(TestServer):
self.server.rebuild.assert_called_with(self.image, None)
+class TestServerRemoveFloatingIP(TestServer):
+
+ def setUp(self):
+ super(TestServerRemoveFloatingIP, self).setUp()
+
+ # Get the command object to test
+ self.cmd = server.RemoveFloatingIP(self.app, None)
+
+ # Set unshelve method to be tested.
+ self.methods = {
+ 'remove_floating_ip': None,
+ }
+
+ def test_server_remove_floating_ip(self):
+ servers = self.setup_servers_mock(count=1)
+
+ arglist = [
+ servers[0].id,
+ '1.2.3.4',
+ ]
+ verifylist = [
+ ('server', servers[0].id),
+ ('ip_address', '1.2.3.4'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ servers[0].remove_floating_ip.assert_called_once_with('1.2.3.4')
+ self.assertIsNone(result)
+
+
class TestServerResize(TestServer):
def setUp(self):
diff --git a/releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml b/releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml
index c5e36cfa..3cfb11ba 100644
--- a/releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml
+++ b/releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml
@@ -4,6 +4,11 @@ features:
pools. This command is used to replace the old command
``ip floating pool list``.
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
+ - Add new commands ``server add/remove floating ip``. They are used to
+ replace the old commands ``ip floating add/remove``.
+ [Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
deprecations:
- Deprecate command ``ip floating pool list``.
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
+ - Deprecate commands ``ip floating add/remove``.
+ [Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
diff --git a/setup.cfg b/setup.cfg
index cf78baf7..bab657ff 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -98,6 +98,7 @@ openstack.compute.v2 =
keypair_list = openstackclient.compute.v2.keypair:ListKeypair
keypair_show = openstackclient.compute.v2.keypair:ShowKeypair
+ server_add_floating_ip = openstackclient.compute.v2.server:AddFloatingIP
server_add_security_group = openstackclient.compute.v2.server:AddServerSecurityGroup
server_add_volume = openstackclient.compute.v2.server:AddServerVolume
server_create = openstackclient.compute.v2.server:CreateServer
@@ -108,6 +109,7 @@ openstack.compute.v2 =
server_pause = openstackclient.compute.v2.server:PauseServer
server_reboot = openstackclient.compute.v2.server:RebootServer
server_rebuild = openstackclient.compute.v2.server:RebuildServer
+ server_remove_floating_ip = openstackclient.compute.v2.server:RemoveFloatingIP
server_remove_security_group = openstackclient.compute.v2.server:RemoveServerSecurityGroup
server_remove_volume = openstackclient.compute.v2.server:RemoveServerVolume
server_rescue = openstackclient.compute.v2.server:RescueServer