Skip to content

Commit ff18e3d

Browse files
author
Kevin_Zheng
committed
Should support 'auto' and 'none' as network parameter when boot instances
Nova added support using 'auto' and 'none' as network parameters since microversion 2.37: http://git.openstack.org/cgit/openstack/nova/tree/nova/api/openstack/rest_api_version_history.rst#n389 we should also add support for this in OSC. Change-Id: I6e5f616dfa48895ebd13144effe9fda7cb94c649 Closes-bug: #1651288
1 parent 5d62981 commit ff18e3d

3 files changed

Lines changed: 49 additions & 32 deletions

File tree

doc/source/command-objects/server.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Create a new server
107107
[--user-data <user-data>]
108108
[--availability-zone <zone-name>]
109109
[--block-device-mapping <dev-name=mapping> [...] ]
110-
[--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid> [...] ]
110+
[--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid,auto,none> [...] ]
111111
[--hint <key=value> [...] ]
112112
[--config-drive <value>|True ]
113113
[--min <count>]
@@ -158,14 +158,16 @@ Create a new server
158158

159159
Map block devices; map is <id>:<type>:<size(GB)>:<delete_on_terminate> (optional extension)
160160

161-
.. option:: --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid>
161+
.. option:: --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid,auto,none>
162162

163163
Create a NIC on the server. Specify option multiple times to create
164164
multiple NICs. Either net-id or port-id must be provided, but not both.
165165
net-id: attach NIC to network with this UUID,
166166
port-id: attach NIC to port with this UUID,
167167
v4-fixed-ip: IPv4 fixed address for NIC (optional),
168168
v6-fixed-ip: IPv6 fixed address for NIC (optional).
169+
none: (v2.37+) no network is attached.
170+
auto: (v2.37+) the compute service will automatically allocate a network.
169171

170172
.. option:: --hint <key=value>
171173

openstackclient/compute/v2/server.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ def get_parser(self, prog_name):
393393
"net-id: attach NIC to network with this UUID, "
394394
"port-id: attach NIC to port with this UUID, "
395395
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
396-
"v6-fixed-ip: IPv6 fixed address for NIC (optional)."),
396+
"v6-fixed-ip: IPv6 fixed address for NIC (optional), "
397+
"none: (v2.37+) no network is attached, "
398+
"auto: (v2.37+) the compute service will automatically "
399+
"allocate a network."),
397400
)
398401
parser.add_argument(
399402
'--hint',
@@ -513,36 +516,39 @@ def take_action(self, parsed_args):
513516
block_device_mapping.update({dev_key: block_volume})
514517

515518
nics = []
516-
for nic_str in parsed_args.nic:
517-
nic_info = {"net-id": "", "v4-fixed-ip": "",
518-
"v6-fixed-ip": "", "port-id": ""}
519-
nic_info.update(dict(kv_str.split("=", 1)
520-
for kv_str in nic_str.split(",")))
521-
if bool(nic_info["net-id"]) == bool(nic_info["port-id"]):
522-
msg = _("either net-id or port-id should be specified "
523-
"but not both")
524-
raise exceptions.CommandError(msg)
525-
if self.app.client_manager.is_network_endpoint_enabled():
526-
network_client = self.app.client_manager.network
527-
if nic_info["net-id"]:
528-
net = network_client.find_network(
529-
nic_info["net-id"], ignore_missing=False)
530-
nic_info["net-id"] = net.id
531-
if nic_info["port-id"]:
532-
port = network_client.find_port(
533-
nic_info["port-id"], ignore_missing=False)
534-
nic_info["port-id"] = port.id
535-
else:
536-
if nic_info["net-id"]:
537-
nic_info["net-id"] = utils.find_resource(
538-
compute_client.networks,
539-
nic_info["net-id"]
540-
).id
541-
if nic_info["port-id"]:
542-
msg = _("can't create server with port specified "
543-
"since network endpoint not enabled")
519+
if parsed_args.nic in ('auto', 'none'):
520+
nics = [parsed_args.nic]
521+
else:
522+
for nic_str in parsed_args.nic:
523+
nic_info = {"net-id": "", "v4-fixed-ip": "",
524+
"v6-fixed-ip": "", "port-id": ""}
525+
nic_info.update(dict(kv_str.split("=", 1)
526+
for kv_str in nic_str.split(",")))
527+
if bool(nic_info["net-id"]) == bool(nic_info["port-id"]):
528+
msg = _("either net-id or port-id should be specified "
529+
"but not both")
544530
raise exceptions.CommandError(msg)
545-
nics.append(nic_info)
531+
if self.app.client_manager.is_network_endpoint_enabled():
532+
network_client = self.app.client_manager.network
533+
if nic_info["net-id"]:
534+
net = network_client.find_network(
535+
nic_info["net-id"], ignore_missing=False)
536+
nic_info["net-id"] = net.id
537+
if nic_info["port-id"]:
538+
port = network_client.find_port(
539+
nic_info["port-id"], ignore_missing=False)
540+
nic_info["port-id"] = port.id
541+
else:
542+
if nic_info["net-id"]:
543+
nic_info["net-id"] = utils.find_resource(
544+
compute_client.networks,
545+
nic_info["net-id"]
546+
).id
547+
if nic_info["port-id"]:
548+
msg = _("can't create server with port specified "
549+
"since network endpoint not enabled")
550+
raise exceptions.CommandError(msg)
551+
nics.append(nic_info)
546552

547553
hints = {}
548554
for hint in parsed_args.hint:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Added ``auto`` and ``none`` as values for ``--nic`` to
5+
the``server create`` command. Specifying ``none`` will not
6+
attach a network to the server. Specifying ``auto``
7+
will automatically attach a network. Note, v2.37 (or newer)
8+
of the Compute API is required for these options.
9+
[Bug `1650342 <https://bugs.launchpad.net/bugs/1650342>`_]

0 commit comments

Comments
 (0)