Transfer "ip fixed add/remove" to "server add/remove fixed ip"
This patch does the following things to transfer "ip fixed add/remove" to "server add/remove fixed ip": * Add new command "server add/remove fixed ip", and unit tests and doc. * Deprecate "ip fixed add/remove" command. compute/v2/fixedip.py is not removed because the arguments' positions are different between the new and old commands. * ip fixed add <network> <server> server add fixed ip <server> <network> * ip fixed remove <ip-address> <server> server remove fixed ip <server> <ip-address> Change-Id: Ica07ccf92a76c21fd5608ecaff86ff7c4d96f5a0 Implements: blueprint rework-ip-commands Partial-bug: 1555990 Co-Authored-By: Dean Troyer <dtroyer@gmail.com>
This commit is contained in:
parent
d1f9ea3f75
commit
179ebe6d64
@ -8,6 +8,7 @@ ip fixed add
|
||||
------------
|
||||
|
||||
Add fixed IP address to server
|
||||
(Deprecated, please use ``server add fixed ip`` instead)
|
||||
|
||||
.. program:: ip fixed add
|
||||
.. code:: bash
|
||||
@ -28,6 +29,7 @@ ip fixed remove
|
||||
---------------
|
||||
|
||||
Remove fixed IP address from server
|
||||
(Deprecated, please use ``server remove fixed ip`` instead)
|
||||
|
||||
.. program:: ip fixed remove
|
||||
.. code:: bash
|
||||
|
@ -4,6 +4,26 @@ server
|
||||
|
||||
Compute v2
|
||||
|
||||
server add fixed ip
|
||||
-------------------
|
||||
|
||||
Add fixed IP address to server
|
||||
|
||||
.. program:: server add fixed ip
|
||||
.. code:: bash
|
||||
|
||||
os server add fixed ip
|
||||
<server>
|
||||
<network>
|
||||
|
||||
.. describe:: <server>
|
||||
|
||||
Server (name or ID) to receive the fixed IP address
|
||||
|
||||
.. describe:: <network>
|
||||
|
||||
Network (name or ID) to allocate the fixed IP address from
|
||||
|
||||
server add floating ip
|
||||
----------------------
|
||||
|
||||
@ -438,6 +458,26 @@ Rebuild server
|
||||
|
||||
Server (name or ID)
|
||||
|
||||
server remove fixed ip
|
||||
----------------------
|
||||
|
||||
Remove fixed IP address from server
|
||||
|
||||
.. program:: server remove fixed ip
|
||||
.. code:: bash
|
||||
|
||||
os server remove fixed ip
|
||||
<server>
|
||||
<ip-address>
|
||||
|
||||
.. describe:: <server>
|
||||
|
||||
Server (name or ID) to remove the fixed IP address from
|
||||
|
||||
.. describe:: <ip-address>
|
||||
|
||||
Fixed IP address (IP address only) to remove from the server
|
||||
|
||||
server remove floating ip
|
||||
-------------------------
|
||||
|
||||
|
@ -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
|
||||
* ``fixed ip``: (**Compute**, **Network**) - an internal IP address assigned to a server
|
||||
* ``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
|
||||
|
@ -15,28 +15,43 @@
|
||||
|
||||
"""Fixed IP action implementations"""
|
||||
|
||||
import logging
|
||||
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
class AddFixedIP(command.Command):
|
||||
"""Add fixed IP address to server"""
|
||||
|
||||
# TODO(tangchen): Remove this class and ``ip fixed 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(AddFixedIP, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"network",
|
||||
metavar="<network>",
|
||||
help="Network to fetch an IP address from (name or ID)",
|
||||
help=_("Network to fetch an IP address from (name or ID)"),
|
||||
)
|
||||
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 fixed ip" instead.'))
|
||||
|
||||
compute_client = self.app.client_manager.compute
|
||||
|
||||
network = utils.find_resource(
|
||||
@ -51,21 +66,32 @@ class AddFixedIP(command.Command):
|
||||
class RemoveFixedIP(command.Command):
|
||||
"""Remove fixed IP address from server"""
|
||||
|
||||
# TODO(tangchen): Remove this class and ``ip fixed 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(RemoveFixedIP, 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 fixed ip" instead.'))
|
||||
|
||||
compute_client = self.app.client_manager.compute
|
||||
|
||||
server = utils.find_resource(
|
||||
|
@ -174,6 +174,36 @@ def _show_progress(progress):
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
class AddFixedIP(command.Command):
|
||||
"""Add fixed IP address to server"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(AddFixedIP, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"server",
|
||||
metavar="<server>",
|
||||
help=_("Server (name or ID) to receive the fixed IP address"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"network",
|
||||
metavar="<network>",
|
||||
help=_("Network (name or ID) to allocate "
|
||||
"the fixed IP address from"),
|
||||
)
|
||||
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)
|
||||
|
||||
network = utils.find_resource(
|
||||
compute_client.networks, parsed_args.network)
|
||||
|
||||
server.add_fixed_ip(network.id)
|
||||
|
||||
|
||||
class AddFloatingIP(command.Command):
|
||||
"""Add floating IP address to server"""
|
||||
|
||||
@ -1108,6 +1138,33 @@ class RebuildServer(command.ShowOne):
|
||||
return zip(*sorted(six.iteritems(details)))
|
||||
|
||||
|
||||
class RemoveFixedIP(command.Command):
|
||||
"""Remove fixed IP address from server"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RemoveFixedIP, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"server",
|
||||
metavar="<server>",
|
||||
help=_("Server (name or ID) to remove the fixed IP address from"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"ip_address",
|
||||
metavar="<ip-address>",
|
||||
help=_("Fixed IP address (IP address only) to remove from the "
|
||||
"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_fixed_ip(parsed_args.ip_address)
|
||||
|
||||
|
||||
class RemoveFloatingIP(command.Command):
|
||||
"""Remove floating IP address from server"""
|
||||
|
||||
|
@ -88,6 +88,45 @@ class TestServer(compute_fakes.TestComputev2):
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestServerAddFixedIP(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerAddFixedIP, 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.AddFixedIP(self.app, None)
|
||||
|
||||
# Set add_fixed_ip method to be tested.
|
||||
self.methods = {
|
||||
'add_fixed_ip': None,
|
||||
}
|
||||
|
||||
def test_server_add_fixed_ip(self):
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
network = compute_fakes.FakeNetwork.create_one_network()
|
||||
self.networks_mock.get.return_value = network
|
||||
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
network.id,
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('network', network.id)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
servers[0].add_fixed_ip.assert_called_once_with(
|
||||
network.id,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestServerAddFloatingIP(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
@ -878,6 +917,38 @@ class TestServerRebuild(TestServer):
|
||||
self.server.rebuild.assert_called_with(self.image, None)
|
||||
|
||||
|
||||
class TestServerRemoveFixedIP(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerRemoveFixedIP, self).setUp()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.RemoveFixedIP(self.app, None)
|
||||
|
||||
# Set unshelve method to be tested.
|
||||
self.methods = {
|
||||
'remove_fixed_ip': None,
|
||||
}
|
||||
|
||||
def test_server_remove_fixed_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_fixed_ip.assert_called_once_with('1.2.3.4')
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestServerRemoveFloatingIP(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -7,8 +7,13 @@ features:
|
||||
- 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>`_]
|
||||
- Add new commands ``server add/remove fixed ip``. They are used to
|
||||
replace the old commands ``ip fixed 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>`_]
|
||||
- Deprecate commands ``ip fixed add/remove``.
|
||||
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
|
||||
|
@ -98,6 +98,7 @@ openstack.compute.v2 =
|
||||
keypair_list = openstackclient.compute.v2.keypair:ListKeypair
|
||||
keypair_show = openstackclient.compute.v2.keypair:ShowKeypair
|
||||
|
||||
server_add_fixed_ip = openstackclient.compute.v2.server:AddFixedIP
|
||||
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
|
||||
@ -109,6 +110,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_fixed_ip = openstackclient.compute.v2.server:RemoveFixedIP
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user