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>
This commit is contained in:
Tang Chen 2016-04-07 14:10:37 +08:00
parent 50bd56db25
commit d1f9ea3f75
8 changed files with 202 additions and 4 deletions

View File

@ -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

View File

@ -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
----------------------------

View File

@ -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

View File

@ -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(

View File

@ -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"""

View File

@ -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):

View File

@ -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>`_]

View File

@ -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