summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-04-25 13:54:46 +0000
committerGerrit Code Review <review@openstack.org>2017-04-25 13:54:46 +0000
commit7977f7df1887de570e17ed37bbb7da7b226e303d (patch)
tree6ced1f0f62e772fbd3f7b545e28d7d6b85ac1fb6 /openstackclient/compute
parentef99f444628282d06feae04514bd2a6328d87b93 (diff)
parent8549071363805a9eef815dd2429b6b860db11a2c (diff)
downloadpython-openstackclient-7977f7df1887de570e17ed37bbb7da7b226e303d.tar.gz
Merge "Add --network and --port to server create"
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 81efd9f3..8b4a3721 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -110,6 +110,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
@@ -447,7 +457,6 @@ class CreateServer(command.ShowOne):
metavar="<net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,"
"port-id=port-uuid,auto,none>",
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. "
@@ -461,6 +470,28 @@ class CreateServer(command.ShowOne):
"cannot be used with any other --nic value."),
)
parser.add_argument(
+ '--network',
+ metavar="<network>",
+ 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="<port>",
+ 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='<key=value>',
action='append',
@@ -592,6 +623,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'):
@@ -607,7 +640,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():
@@ -636,7 +669,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: