Merge "compute: Add '--no-network', '--auto-network' flags"
This commit is contained in:
commit
681934a96a
@ -409,8 +409,8 @@ class AddPort(command.Command):
|
|||||||
'--tag',
|
'--tag',
|
||||||
metavar='<tag>',
|
metavar='<tag>',
|
||||||
help=_(
|
help=_(
|
||||||
"Tag for the attached interface. "
|
'Tag for the attached interface '
|
||||||
"(Supported by API versions '2.49' - '2.latest')"
|
'(supported by --os-compute-api-version 2.49 or later)'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
@ -652,29 +652,68 @@ class AddServerVolume(command.ShowOne):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO(stephenfin): Replace with 'MultiKeyValueAction' when we no longer
|
class NoneNICAction(argparse.Action):
|
||||||
# support '--nic=auto' and '--nic=none'
|
|
||||||
|
def __init__(self, option_strings, dest, help=None):
|
||||||
|
super().__init__(
|
||||||
|
option_strings=option_strings,
|
||||||
|
dest=dest,
|
||||||
|
nargs=0,
|
||||||
|
default=[],
|
||||||
|
required=False,
|
||||||
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
# Make sure we have an empty dict rather than None
|
||||||
|
if getattr(namespace, self.dest, None) is None:
|
||||||
|
setattr(namespace, self.dest, [])
|
||||||
|
|
||||||
|
getattr(namespace, self.dest).append('none')
|
||||||
|
|
||||||
|
|
||||||
|
class AutoNICAction(argparse.Action):
|
||||||
|
|
||||||
|
def __init__(self, option_strings, dest, help=None):
|
||||||
|
super().__init__(
|
||||||
|
option_strings=option_strings,
|
||||||
|
dest=dest,
|
||||||
|
nargs=0,
|
||||||
|
default=[],
|
||||||
|
required=False,
|
||||||
|
help=help,
|
||||||
|
)
|
||||||
|
|
||||||
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
# Make sure we have an empty dict rather than None
|
||||||
|
if getattr(namespace, self.dest, None) is None:
|
||||||
|
setattr(namespace, self.dest, [])
|
||||||
|
|
||||||
|
getattr(namespace, self.dest).append('auto')
|
||||||
|
|
||||||
|
|
||||||
class NICAction(argparse.Action):
|
class NICAction(argparse.Action):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
option_strings,
|
option_strings,
|
||||||
dest,
|
dest,
|
||||||
nargs=None,
|
|
||||||
const=None,
|
|
||||||
default=None,
|
|
||||||
type=None,
|
|
||||||
choices=None,
|
|
||||||
required=False,
|
|
||||||
help=None,
|
help=None,
|
||||||
metavar=None,
|
metavar=None,
|
||||||
key=None,
|
key=None,
|
||||||
):
|
):
|
||||||
self.key = key
|
self.key = key
|
||||||
super().__init__(
|
super().__init__(
|
||||||
option_strings=option_strings, dest=dest, nargs=nargs, const=const,
|
option_strings=option_strings,
|
||||||
default=default, type=type, choices=choices, required=required,
|
dest=dest,
|
||||||
help=help, metavar=metavar,
|
nargs=None,
|
||||||
|
const=None,
|
||||||
|
default=[],
|
||||||
|
type=None,
|
||||||
|
choices=None,
|
||||||
|
required=False,
|
||||||
|
help=help,
|
||||||
|
metavar=metavar,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
@ -707,7 +746,7 @@ class NICAction(argparse.Action):
|
|||||||
}
|
}
|
||||||
|
|
||||||
for kv_str in values.split(','):
|
for kv_str in values.split(','):
|
||||||
k, sep, v = kv_str.partition("=")
|
k, sep, v = kv_str.partition('=')
|
||||||
|
|
||||||
if k not in list(info) + ['tag'] or not v:
|
if k not in list(info) + ['tag'] or not v:
|
||||||
msg = _(
|
msg = _(
|
||||||
@ -998,28 +1037,23 @@ class CreateServer(command.ShowOne):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--network',
|
'--network',
|
||||||
metavar="<network>",
|
metavar='<network>',
|
||||||
dest='nics',
|
dest='nics',
|
||||||
default=[],
|
|
||||||
action=NICAction,
|
action=NICAction,
|
||||||
key='net-id',
|
key='net-id',
|
||||||
# NOTE(RuiChen): Add '\n' to the end of line to improve formatting;
|
|
||||||
# see cliff's _SmartHelpFormatter for more details.
|
|
||||||
help=_(
|
help=_(
|
||||||
"Create a NIC on the server and connect it to network. "
|
"Create a NIC on the server and connect it to network. "
|
||||||
"Specify option multiple times to create multiple NICs. "
|
"Specify option multiple times to create multiple NICs. "
|
||||||
"This is a wrapper for the '--nic net-id=<network>' "
|
"This is a wrapper for the '--nic net-id=<network>' "
|
||||||
"parameter that provides simple syntax for the standard "
|
"parameter that provides simple syntax for the standard "
|
||||||
"use case of connecting a new server to a given network. "
|
"use case of connecting a new server to a given network. "
|
||||||
"For more advanced use cases, refer to the '--nic' "
|
"For more advanced use cases, refer to the '--nic' parameter."
|
||||||
"parameter."
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--port',
|
'--port',
|
||||||
metavar="<port>",
|
metavar='<port>',
|
||||||
dest='nics',
|
dest='nics',
|
||||||
default=[],
|
|
||||||
action=NICAction,
|
action=NICAction,
|
||||||
key='port-id',
|
key='port-id',
|
||||||
help=_(
|
help=_(
|
||||||
@ -1031,13 +1065,41 @@ class CreateServer(command.ShowOne):
|
|||||||
"more advanced use cases, refer to the '--nic' parameter."
|
"more advanced use cases, refer to the '--nic' parameter."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--no-network',
|
||||||
|
dest='nics',
|
||||||
|
action=NoneNICAction,
|
||||||
|
help=_(
|
||||||
|
"Do not attach a network to the server. "
|
||||||
|
"This is a wrapper for the '--nic none' option that provides "
|
||||||
|
"a simple syntax for disabling network connectivity for a new "
|
||||||
|
"server. "
|
||||||
|
"For more advanced use cases, refer to the '--nic' parameter. "
|
||||||
|
"(supported by --os-compute-api-version 2.37 or above)"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--auto-network',
|
||||||
|
dest='nics',
|
||||||
|
action=AutoNICAction,
|
||||||
|
help=_(
|
||||||
|
"Automatically allocate a network to the server. "
|
||||||
|
"This is the default network allocation policy. "
|
||||||
|
"This is a wrapper for the '--nic auto' option that provides "
|
||||||
|
"a simple syntax for enabling automatic configuration of "
|
||||||
|
"network connectivity for a new server. "
|
||||||
|
"For more advanced use cases, refer to the '--nic' parameter. "
|
||||||
|
"(supported by --os-compute-api-version 2.37 or above)"
|
||||||
|
),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--nic',
|
'--nic',
|
||||||
metavar="<net-id=net-uuid,port-id=port-uuid,v4-fixed-ip=ip-addr,"
|
metavar="<net-id=net-uuid,port-id=port-uuid,v4-fixed-ip=ip-addr,"
|
||||||
"v6-fixed-ip=ip-addr,tag=tag,auto,none>",
|
"v6-fixed-ip=ip-addr,tag=tag,auto,none>",
|
||||||
action=NICAction,
|
|
||||||
dest='nics',
|
dest='nics',
|
||||||
default=[],
|
action=NICAction,
|
||||||
|
# NOTE(RuiChen): Add '\n' to the end of line to improve formatting;
|
||||||
|
# see cliff's _SmartHelpFormatter for more details.
|
||||||
help=_(
|
help=_(
|
||||||
"Create a NIC on the server.\n"
|
"Create a NIC on the server.\n"
|
||||||
"NIC in the format:\n"
|
"NIC in the format:\n"
|
||||||
|
@ -1900,13 +1900,7 @@ class TestServerCreate(TestServer):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.CommandError, self.cmd.take_action, parsed_args)
|
exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||||
|
|
||||||
def test_server_create_with_auto_network(self):
|
def _test_server_create_with_auto_network(self, arglist):
|
||||||
arglist = [
|
|
||||||
'--image', 'image1',
|
|
||||||
'--flavor', 'flavor1',
|
|
||||||
'--nic', 'auto',
|
|
||||||
self.new_server.name,
|
|
||||||
]
|
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', 'image1'),
|
('image', 'image1'),
|
||||||
('flavor', 'flavor1'),
|
('flavor', 'flavor1'),
|
||||||
@ -1946,6 +1940,27 @@ class TestServerCreate(TestServer):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.datalist(), data)
|
self.assertEqual(self.datalist(), data)
|
||||||
|
|
||||||
|
# NOTE(stephenfin): '--auto-network' is an alias for '--nic auto' so the
|
||||||
|
# tests are nearly identical
|
||||||
|
|
||||||
|
def test_server_create_with_auto_network_legacy(self):
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--nic', 'auto',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
self._test_server_create_with_auto_network(arglist)
|
||||||
|
|
||||||
|
def test_server_create_with_auto_network(self):
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--auto-network',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
self._test_server_create_with_auto_network(arglist)
|
||||||
|
|
||||||
def test_server_create_with_auto_network_default_v2_37(self):
|
def test_server_create_with_auto_network_default_v2_37(self):
|
||||||
"""Tests creating a server without specifying --nic using 2.37."""
|
"""Tests creating a server without specifying --nic using 2.37."""
|
||||||
arglist = [
|
arglist = [
|
||||||
@ -1996,13 +2011,7 @@ class TestServerCreate(TestServer):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.datalist(), data)
|
self.assertEqual(self.datalist(), data)
|
||||||
|
|
||||||
def test_server_create_with_none_network(self):
|
def _test_server_create_with_none_network(self, arglist):
|
||||||
arglist = [
|
|
||||||
'--image', 'image1',
|
|
||||||
'--flavor', 'flavor1',
|
|
||||||
'--nic', 'none',
|
|
||||||
self.new_server.name,
|
|
||||||
]
|
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', 'image1'),
|
('image', 'image1'),
|
||||||
('flavor', 'flavor1'),
|
('flavor', 'flavor1'),
|
||||||
@ -2042,6 +2051,27 @@ class TestServerCreate(TestServer):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.datalist(), data)
|
self.assertEqual(self.datalist(), data)
|
||||||
|
|
||||||
|
# NOTE(stephenfin): '--no-network' is an alias for '--nic none' so the
|
||||||
|
# tests are nearly identical
|
||||||
|
|
||||||
|
def test_server_create_with_none_network_legacy(self):
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--nic', 'none',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
self._test_server_create_with_none_network(arglist)
|
||||||
|
|
||||||
|
def test_server_create_with_none_network(self):
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--no-network',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
self._test_server_create_with_none_network(arglist)
|
||||||
|
|
||||||
def test_server_create_with_conflict_network_options(self):
|
def test_server_create_with_conflict_network_options(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--image', 'image1',
|
'--image', 'image1',
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The ``server create`` command now accepts two new options, ``--no-network``
|
||||||
|
and ``--auto-network``. These are aliases for ``--nic none`` and
|
||||||
|
``--nic auto``, respectively.
|
Loading…
x
Reference in New Issue
Block a user