Merge "Compute: Add tag support for server add fixed ip"
This commit is contained in:
commit
77a45fe685
openstackclient
releasenotes/notes
@ -236,6 +236,14 @@ class AddFixedIP(command.Command):
|
|||||||
metavar="<ip-address>",
|
metavar="<ip-address>",
|
||||||
help=_("Requested fixed IP address"),
|
help=_("Requested fixed IP address"),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--tag',
|
||||||
|
metavar='<tag>',
|
||||||
|
help=_(
|
||||||
|
'Tag for the attached interface. '
|
||||||
|
'(supported by --os-compute-api-version 2.52 or above)'
|
||||||
|
)
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -246,11 +254,23 @@ class AddFixedIP(command.Command):
|
|||||||
|
|
||||||
network = compute_client.api.network_find(parsed_args.network)
|
network = compute_client.api.network_find(parsed_args.network)
|
||||||
|
|
||||||
server.interface_attach(
|
kwargs = {
|
||||||
port_id=None,
|
'port_id': None,
|
||||||
net_id=network['id'],
|
'net_id': network['id'],
|
||||||
fixed_ip=parsed_args.fixed_ip_address,
|
'fixed_ip': parsed_args.fixed_ip_address,
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if parsed_args.tag:
|
||||||
|
if compute_client.api_version < api_versions.APIVersion('2.49'):
|
||||||
|
msg = _(
|
||||||
|
'--os-compute-api-version 2.49 or greater is required to '
|
||||||
|
'support the --tag option'
|
||||||
|
)
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
kwargs['tag'] = parsed_args.tag
|
||||||
|
|
||||||
|
server.interface_attach(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AddFloatingIP(network_common.NetworkAndComputeCommand):
|
class AddFloatingIP(network_common.NetworkAndComputeCommand):
|
||||||
|
@ -182,6 +182,72 @@ class TestServerAddFixedIP(TestServer):
|
|||||||
extralist = ['--fixed-ip-address', '5.6.7.8']
|
extralist = ['--fixed-ip-address', '5.6.7.8']
|
||||||
self._test_server_add_fixed_ip(extralist, '5.6.7.8')
|
self._test_server_add_fixed_ip(extralist, '5.6.7.8')
|
||||||
|
|
||||||
|
def test_server_add_fixed_ip_with_tag(self):
|
||||||
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
|
'2.49')
|
||||||
|
|
||||||
|
servers = self.setup_servers_mock(count=1)
|
||||||
|
network = compute_fakes.FakeNetwork.create_one_network()
|
||||||
|
with mock.patch(
|
||||||
|
'openstackclient.api.compute_v2.APIv2.network_find'
|
||||||
|
) as net_mock:
|
||||||
|
net_mock.return_value = network
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
servers[0].id,
|
||||||
|
network['id'],
|
||||||
|
'--fixed-ip-address', '5.6.7.8',
|
||||||
|
'--tag', 'tag1',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('server', servers[0].id),
|
||||||
|
('network', network['id']),
|
||||||
|
('fixed_ip_address', '5.6.7.8'),
|
||||||
|
('tag', 'tag1'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
servers[0].interface_attach.assert_called_once_with(
|
||||||
|
port_id=None,
|
||||||
|
net_id=network['id'],
|
||||||
|
fixed_ip='5.6.7.8',
|
||||||
|
tag='tag1'
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_server_add_fixed_ip_with_tag_pre_v249(self):
|
||||||
|
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||||
|
'2.48')
|
||||||
|
|
||||||
|
servers = self.setup_servers_mock(count=1)
|
||||||
|
network = compute_fakes.FakeNetwork.create_one_network()
|
||||||
|
with mock.patch(
|
||||||
|
'openstackclient.api.compute_v2.APIv2.network_find'
|
||||||
|
) as net_mock:
|
||||||
|
net_mock.return_value = network
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
servers[0].id,
|
||||||
|
network['id'],
|
||||||
|
'--fixed-ip-address', '5.6.7.8',
|
||||||
|
'--tag', 'tag1',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('server', servers[0].id),
|
||||||
|
('network', network['id']),
|
||||||
|
('fixed_ip_address', '5.6.7.8'),
|
||||||
|
('tag', 'tag1'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
ex = self.assertRaises(
|
||||||
|
exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
self.assertIn(
|
||||||
|
'--os-compute-api-version 2.49 or greater is required',
|
||||||
|
str(ex))
|
||||||
|
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'openstackclient.api.compute_v2.APIv2.floating_ip_add'
|
'openstackclient.api.compute_v2.APIv2.floating_ip_add'
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add ``--tag`` option to ``server add fixed ip`` command
|
||||||
|
when adding a fixed IP to server. Only available starting
|
||||||
|
with ``--os-compute-api-version 2.49``.
|
Loading…
x
Reference in New Issue
Block a user