Compute: Add tag support for server add port
Change-Id: Ice6bf5fb57afeb10862c870b42732dcf166772d1 Story: 2002195 Task: 21676
This commit is contained in:
parent
a48c05b90a
commit
f3fbb1b648
@ -354,6 +354,14 @@ class AddPort(command.Command):
|
||||
metavar="<port>",
|
||||
help=_("Port to add to the server (name or ID)"),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--tag',
|
||||
metavar='<tag>',
|
||||
help=_(
|
||||
"Tag for the attached interface. "
|
||||
"(Supported by API versions '2.49' - '2.latest')"
|
||||
)
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -369,7 +377,22 @@ class AddPort(command.Command):
|
||||
else:
|
||||
port_id = parsed_args.port
|
||||
|
||||
server.interface_attach(port_id=port_id, net_id=None, fixed_ip=None)
|
||||
kwargs = {
|
||||
'port_id': port_id,
|
||||
'net_id': None,
|
||||
'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 AddNetwork(command.Command):
|
||||
|
@ -465,6 +465,59 @@ class TestServerAddPort(TestServer):
|
||||
self._test_server_add_port('fake-port')
|
||||
self.find_port.assert_not_called()
|
||||
|
||||
def test_server_add_port_with_tag(self):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.49')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
self.find_port.return_value.id = 'fake-port'
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
'fake-port',
|
||||
'--tag', 'tag1',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('port', 'fake-port'),
|
||||
('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='fake-port',
|
||||
net_id=None,
|
||||
fixed_ip=None,
|
||||
tag='tag1')
|
||||
|
||||
def test_server_add_port_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_port.return_value.id = 'fake-port'
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
'fake-port',
|
||||
'--tag', 'tag1',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('port', 'fake-port'),
|
||||
('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))
|
||||
|
||||
|
||||
class TestServerVolume(TestServer):
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- Add ``--tag`` option to ``server add port`` command when
|
||||
add a port to server. Only available starting with
|
||||
``--os-compute-api-version 2.49``.
|
Loading…
Reference in New Issue
Block a user