summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-12-23 03:50:18 +0000
committerGerrit Code Review <review@openstack.org>2016-12-23 03:50:18 +0000
commitb829b210b02b87cbd17baa6404554f97511d26cc (patch)
treefa8f17f2bd7e9d7d7acdcd5f38c5a2985c7c050e
parent9e1e7e1c9fde2e60b2f95f3bd000c599a9e1c72a (diff)
parentff18e3d0e9307fb505113b467e58bdb62992fb85 (diff)
downloadpython-openstackclient-b829b210b02b87cbd17baa6404554f97511d26cc.tar.gz
Merge "Should support 'auto' and 'none' as network parameter when boot instances"
-rw-r--r--doc/source/command-objects/server.rst6
-rw-r--r--openstackclient/compute/v2/server.py66
-rw-r--r--releasenotes/notes/add-auto-and-none-as-nic-parameter-ed23a6e7f99f250d.yaml9
3 files changed, 49 insertions, 32 deletions
diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst
index 5ad29a0f..88f22baf 100644
--- a/doc/source/command-objects/server.rst
+++ b/doc/source/command-objects/server.rst
@@ -107,7 +107,7 @@ Create a new server
[--user-data <user-data>]
[--availability-zone <zone-name>]
[--block-device-mapping <dev-name=mapping> [...] ]
- [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid> [...] ]
+ [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid,auto,none> [...] ]
[--hint <key=value> [...] ]
[--config-drive <value>|True ]
[--min <count>]
@@ -158,7 +158,7 @@ Create a new server
Map block devices; map is <id>:<type>:<size(GB)>:<delete_on_terminate> (optional extension)
-.. option:: --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid>
+.. option:: --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid,auto,none>
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.
@@ -166,6 +166,8 @@ Create a new server
port-id: attach NIC to port with this UUID,
v4-fixed-ip: IPv4 fixed address for NIC (optional),
v6-fixed-ip: IPv6 fixed address for NIC (optional).
+ none: (v2.37+) no network is attached.
+ auto: (v2.37+) the compute service will automatically allocate a network.
.. option:: --hint <key=value>
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 48d8b2d0..938c8c06 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -393,7 +393,10 @@ class CreateServer(command.ShowOne):
"net-id: attach NIC to network with this UUID, "
"port-id: attach NIC to port with this UUID, "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
- "v6-fixed-ip: IPv6 fixed address for NIC (optional)."),
+ "v6-fixed-ip: IPv6 fixed address for NIC (optional), "
+ "none: (v2.37+) no network is attached, "
+ "auto: (v2.37+) the compute service will automatically "
+ "allocate a network."),
)
parser.add_argument(
'--hint',
@@ -513,36 +516,39 @@ class CreateServer(command.ShowOne):
block_device_mapping.update({dev_key: block_volume})
nics = []
- for nic_str in parsed_args.nic:
- nic_info = {"net-id": "", "v4-fixed-ip": "",
- "v6-fixed-ip": "", "port-id": ""}
- nic_info.update(dict(kv_str.split("=", 1)
- for kv_str in nic_str.split(",")))
- if bool(nic_info["net-id"]) == bool(nic_info["port-id"]):
- msg = _("either net-id or port-id should be specified "
- "but not both")
- raise exceptions.CommandError(msg)
- if self.app.client_manager.is_network_endpoint_enabled():
- network_client = self.app.client_manager.network
- if nic_info["net-id"]:
- net = network_client.find_network(
- nic_info["net-id"], ignore_missing=False)
- nic_info["net-id"] = net.id
- if nic_info["port-id"]:
- port = network_client.find_port(
- nic_info["port-id"], ignore_missing=False)
- nic_info["port-id"] = port.id
- else:
- if nic_info["net-id"]:
- nic_info["net-id"] = utils.find_resource(
- compute_client.networks,
- nic_info["net-id"]
- ).id
- if nic_info["port-id"]:
- msg = _("can't create server with port specified "
- "since network endpoint not enabled")
+ if parsed_args.nic in ('auto', 'none'):
+ nics = [parsed_args.nic]
+ else:
+ for nic_str in parsed_args.nic:
+ nic_info = {"net-id": "", "v4-fixed-ip": "",
+ "v6-fixed-ip": "", "port-id": ""}
+ nic_info.update(dict(kv_str.split("=", 1)
+ for kv_str in nic_str.split(",")))
+ if bool(nic_info["net-id"]) == bool(nic_info["port-id"]):
+ msg = _("either net-id or port-id should be specified "
+ "but not both")
raise exceptions.CommandError(msg)
- nics.append(nic_info)
+ if self.app.client_manager.is_network_endpoint_enabled():
+ network_client = self.app.client_manager.network
+ if nic_info["net-id"]:
+ net = network_client.find_network(
+ nic_info["net-id"], ignore_missing=False)
+ nic_info["net-id"] = net.id
+ if nic_info["port-id"]:
+ port = network_client.find_port(
+ nic_info["port-id"], ignore_missing=False)
+ nic_info["port-id"] = port.id
+ else:
+ if nic_info["net-id"]:
+ nic_info["net-id"] = utils.find_resource(
+ compute_client.networks,
+ nic_info["net-id"]
+ ).id
+ if nic_info["port-id"]:
+ msg = _("can't create server with port specified "
+ "since network endpoint not enabled")
+ raise exceptions.CommandError(msg)
+ nics.append(nic_info)
hints = {}
for hint in parsed_args.hint:
diff --git a/releasenotes/notes/add-auto-and-none-as-nic-parameter-ed23a6e7f99f250d.yaml b/releasenotes/notes/add-auto-and-none-as-nic-parameter-ed23a6e7f99f250d.yaml
new file mode 100644
index 00000000..9c871f78
--- /dev/null
+++ b/releasenotes/notes/add-auto-and-none-as-nic-parameter-ed23a6e7f99f250d.yaml
@@ -0,0 +1,9 @@
+---
+features:
+ - |
+ Added ``auto`` and ``none`` as values for ``--nic`` to
+ the``server create`` command. Specifying ``none`` will not
+ attach a network to the server. Specifying ``auto``
+ will automatically attach a network. Note, v2.37 (or newer)
+ of the Compute API is required for these options.
+ [Bug `1650342 <https://bugs.launchpad.net/bugs/1650342>`_]