summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem.os@gmail.com>2019-08-01 15:11:29 -0400
committerMatt Riedemann <mriedem.os@gmail.com>2019-08-09 16:44:46 +0000
commitb9d63105566c84db11a976846844ad7b3a0b331e (patch)
tree66e9aeee501de4c87a33aafd6c088b9f11b3c0f8 /openstackclient/compute
parentc28ed25e3a6f2d9cf5fc349c544354a9d07aa957 (diff)
downloadpython-openstackclient-b9d63105566c84db11a976846844ad7b3a0b331e.tar.gz
Add openstack server create --boot-from-volume option
This adds a --boot-from-volume option to the server create command which is used with the --image or --image-property option and will create a volume-backed server from the specified image with the specified size. Similar to the --volume option, the created root volume will not be deleted when the server is deleted. The --boot-from-volume option is not allowed with the --volume option since they both create a block device mapping with boot_index=0. Change-Id: I88c590361cb232c1df7b5bb010dcea307080d34c Story: 2006302 Task: 36017
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index fee2b27d..95c2f28a 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -568,6 +568,19 @@ class CreateServer(command.ShowOne):
'2.74 or above)'),
)
parser.add_argument(
+ '--boot-from-volume',
+ metavar='<volume-size>',
+ type=int,
+ help=_('When used in conjunction with the ``--image`` or '
+ '``--image-property`` option, this option automatically '
+ 'creates a block device mapping with a boot index of 0 '
+ 'and tells the compute service to create a volume of the '
+ 'given size (in GB) from the specified image and use it '
+ 'as the root disk of the server. The root volume will not '
+ 'be deleted when the server is deleted. This option is '
+ 'mutually exclusive with the ``--volume`` option.')
+ )
+ parser.add_argument(
'--block-device-mapping',
metavar='<dev-name=mapping>',
action=parseractions.KeyValueAction,
@@ -730,6 +743,10 @@ class CreateServer(command.ShowOne):
# Lookup parsed_args.volume
volume = None
if parsed_args.volume:
+ # --volume and --boot-from-volume are mutually exclusive.
+ if parsed_args.boot_from_volume:
+ raise exceptions.CommandError(
+ _('--volume is not allowed with --boot-from-volume'))
volume = utils.find_resource(
volume_client.volumes,
parsed_args.volume,
@@ -739,8 +756,6 @@ class CreateServer(command.ShowOne):
flavor = utils.find_resource(compute_client.flavors,
parsed_args.flavor)
- boot_args = [parsed_args.server_name, image, flavor]
-
files = {}
for f in parsed_args.file:
dst, src = f.split('=', 1)
@@ -787,6 +802,20 @@ class CreateServer(command.ShowOne):
'source_type': 'volume',
'destination_type': 'volume'
}]
+ elif parsed_args.boot_from_volume:
+ # Tell nova to create a root volume from the image provided.
+ block_device_mapping_v2 = [{
+ 'uuid': image.id,
+ 'boot_index': '0',
+ 'source_type': 'image',
+ 'destination_type': 'volume',
+ 'volume_size': parsed_args.boot_from_volume
+ }]
+ # If booting from volume we do not pass an image to compute.
+ image = None
+
+ boot_args = [parsed_args.server_name, image, flavor]
+
# Handle block device by device name order, like: vdb -> vdc -> vdd
for dev_name in sorted(six.iterkeys(parsed_args.block_device_mapping)):
dev_map = parsed_args.block_device_mapping[dev_name]