From 8549071363805a9eef815dd2429b6b860db11a2c Mon Sep 17 00:00:00 2001 From: David Rabel Date: Mon, 13 Mar 2017 15:16:48 +0100 Subject: Add --network and --port to server create --nic option is quite unhandy. It is better to have two seperate options --network and --port to add a network to a new server. Change-Id: I523abdc83ca2dd4c5dd3871f8f109c2bf57c2e02 Closes-Bug: #1612898 --- openstackclient/compute/v2/server.py | 40 +++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index d33c631a..c2482bb1 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -114,6 +114,16 @@ def _get_ip_address(addresses, address_type, ip_address_family): ) +def _prefix_checked_value(prefix): + def func(value): + if ',' in value or '=' in value: + msg = _("Invalid argument %s, " + "characters ',' and '=' are not allowed") % value + raise argparse.ArgumentTypeError(msg) + return prefix + value + return func + + def _prep_server_detail(compute_client, image_client, server): """Prepare the detailed server dict for printing @@ -404,7 +414,6 @@ class CreateServer(command.ShowOne): metavar="", action='append', - default=[], help=_("Create a NIC on the server. " "Specify option multiple times to create multiple NICs. " "Either net-id or port-id must be provided, but not both. " @@ -417,6 +426,28 @@ class CreateServer(command.ShowOne): "allocate a network. Specifying a --nic of auto or none " "cannot be used with any other --nic value."), ) + parser.add_argument( + '--network', + metavar="", + action='append', + dest='nic', + type=_prefix_checked_value('net-id='), + help=_("Create a NIC on the server and connect it to network. " + "Specify option multiple times to create multiple NICs. " + "For more options on NICs see --nic parameter. " + "network: attach NIC to this network "), + ) + parser.add_argument( + '--port', + metavar="", + action='append', + dest='nic', + type=_prefix_checked_value('port-id='), + help=_("Create a NIC on the server and connect it to port. " + "Specify option multiple times to create multiple NICs. " + "For more options on NICs see --nic parameter. " + "port: attach NIC this port "), + ) parser.add_argument( '--hint', metavar='', @@ -549,6 +580,8 @@ class CreateServer(command.ShowOne): nics = [] auto_or_none = False + if parsed_args.nic is None: + parsed_args.nic = [] for nic_str in parsed_args.nic: # Handle the special auto/none cases if nic_str in ('auto', 'none'): @@ -564,7 +597,7 @@ class CreateServer(command.ShowOne): msg = _('Invalid --nic argument %s.') % nic_str raise exceptions.CommandError(msg) if bool(nic_info["net-id"]) == bool(nic_info["port-id"]): - msg = _("either net-id or port-id should be specified " + msg = _("either network or port should be specified " "but not both") raise exceptions.CommandError(msg) if self.app.client_manager.is_network_endpoint_enabled(): @@ -593,7 +626,8 @@ class CreateServer(command.ShowOne): if auto_or_none: if len(nics) > 1: msg = _('Specifying a --nic of auto or none cannot ' - 'be used with any other --nic value.') + 'be used with any other --nic, --network ' + 'or --port value.') raise exceptions.CommandError(msg) nics = nics[0] else: -- cgit v1.2.1