Compute: Add tag support for server add network
Change-Id: I31a66b2d4dac44052a71f43a5a67836247ccac64 Story: 2002195 Task: 21678
This commit is contained in:
parent
a48c05b90a
commit
6f1602312b
@ -387,6 +387,14 @@ class AddNetwork(command.Command):
|
||||
metavar="<network>",
|
||||
help=_("Network to add to the server (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--tag',
|
||||
metavar='<tag>',
|
||||
help=_(
|
||||
'Tag for the attached interface. '
|
||||
'(supported by --os-compute-api-version 2.49 or above)'
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -402,7 +410,23 @@ class AddNetwork(command.Command):
|
||||
else:
|
||||
net_id = parsed_args.network
|
||||
|
||||
server.interface_attach(port_id=None, net_id=net_id, fixed_ip=None)
|
||||
kwargs = {
|
||||
'port_id': None,
|
||||
'net_id': net_id,
|
||||
'fixed_ip': None,
|
||||
}
|
||||
|
||||
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 AddServerSecurityGroup(command.Command):
|
||||
|
@ -681,6 +681,62 @@ class TestServerAddNetwork(TestServer):
|
||||
self._test_server_add_network('fake-network')
|
||||
self.find_network.assert_not_called()
|
||||
|
||||
def test_server_add_network_with_tag(self):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.49')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
self.find_network.return_value.id = 'fake-network'
|
||||
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
'fake-network',
|
||||
'--tag', 'tag1',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('network', 'fake-network'),
|
||||
('tag', 'tag1'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.assertIsNone(result)
|
||||
|
||||
servers[0].interface_attach.assert_called_once_with(
|
||||
port_id=None,
|
||||
net_id='fake-network',
|
||||
fixed_ip=None,
|
||||
tag='tag1'
|
||||
)
|
||||
|
||||
def test_server_add_network_with_tag_pre_v249(self):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.48')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
self.find_network.return_value.id = 'fake-network'
|
||||
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
'fake-network',
|
||||
'--tag', 'tag1',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('network', 'fake-network'),
|
||||
('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(
|
||||
'openstackclient.api.compute_v2.APIv2.security_group_find'
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- Add ``--tag`` option to ``server add network`` command
|
||||
when add network to server. Only available starting
|
||||
with ``--os-compute-api-version 2.49``.
|
Loading…
Reference in New Issue
Block a user