Added new boolean option 'GLANCE_USE_IMPORT_WORKFLOW' default to False.
If this parameter set in local.conf as True then devstack will use the
new import workflow to create the image.
In order to use new import workflow of glance;
user need to set below options in local.conf
GLANCE_USE_IMPORT_WORKFLOW=True
Note that the import workflow does not work in uwsgi because of
some fundamental restrictions it has. Thus, devstack must be configured
with WSGI_MODE=mod_wsgi, otherwise glance will not be able to process
the imports. The new helper function will abort to avoid in that case
to avoid the image never being moved to "active" state by an import
task that will never be executed.
Co-Authored-By: Abhishek Kekane <akekane@redhat.com>
Co-Authored-By: Dan Smith <dansmith@redhat.com>
Needed-By: https://review.opendev.org/#/c/734184
Change-Id: I1306fe816b7a3eca1e2312c0c454be3d81118eca
| ... | ... |
@@ -77,6 +77,41 @@ function get_extra_file {
|
| 77 | 77 |
fi |
| 78 | 78 |
} |
| 79 | 79 |
|
| 80 |
+# Upload an image to glance using the configured mechanism |
|
| 81 |
+# |
|
| 82 |
+# Arguments: |
|
| 83 |
+# image name |
|
| 84 |
+# container format |
|
| 85 |
+# disk format |
|
| 86 |
+# path to image file |
|
| 87 |
+# optional properties (format of propname=value) |
|
| 88 |
+# |
|
| 89 |
+function _upload_image {
|
|
| 90 |
+ local image_name="$1" |
|
| 91 |
+ shift |
|
| 92 |
+ local container="$1" |
|
| 93 |
+ shift |
|
| 94 |
+ local disk="$1" |
|
| 95 |
+ shift |
|
| 96 |
+ local image="$1" |
|
| 97 |
+ shift |
|
| 98 |
+ local properties |
|
| 99 |
+ local useimport |
|
| 100 |
+ |
|
| 101 |
+ for prop in $*; do |
|
| 102 |
+ properties+=" --property $prop" |
|
| 103 |
+ done |
|
| 104 |
+ |
|
| 105 |
+ if [[ "$GLANCE_USE_IMPORT_WORKFLOW" == "True" ]]; then |
|
| 106 |
+ if [[ "$WSGI_MODE" != "uwsgi" ]]; then |
|
| 107 |
+ useimport="--import" |
|
| 108 |
+ else |
|
| 109 |
+ echo "*** Unable to use glance import workflow because WSGI_MODE=uwsgi! ***" |
|
| 110 |
+ fi |
|
| 111 |
+ fi |
|
| 112 |
+ |
|
| 113 |
+ openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" --public --container-format "$container" --disk-format "$disk" $useimport $properties < "${image}"
|
|
| 114 |
+} |
|
| 80 | 115 |
|
| 81 | 116 |
# Retrieve an image from a URL and upload into Glance. |
| 82 | 117 |
# Uses the following variables: |
| ... | ... |
@@ -118,7 +153,7 @@ function upload_image {
|
| 118 | 118 |
# OpenVZ-format images are provided as .tar.gz, but not decompressed prior to loading |
| 119 | 119 |
if [[ "$image_url" =~ 'openvz' ]]; then |
| 120 | 120 |
image_name="${image_fname%.tar.gz}"
|
| 121 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" --public --container-format ami --disk-format ami < "${image}"
|
|
| 121 |
+ _upload_image "$image_name" ami ami "$image" |
|
| 122 | 122 |
return |
| 123 | 123 |
fi |
| 124 | 124 |
|
| ... | ... |
@@ -232,7 +267,8 @@ function upload_image {
|
| 232 | 232 |
vmdk_adapter_type="${props[1]:-$vmdk_adapter_type}"
|
| 233 | 233 |
vmdk_net_adapter="${props[2]:-$vmdk_net_adapter}"
|
| 234 | 234 |
|
| 235 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" --public --container-format bare --disk-format vmdk --property vmware_disktype="$vmdk_disktype" --property vmware_adaptertype="$vmdk_adapter_type" --property hw_vif_model="$vmdk_net_adapter" < "${image}"
|
|
| 235 |
+ _upload_image "$image_name" bare vmdk "$image" vmware_disktype="$vmdk_disktype" vmware_adaptertype="$vmdk_adapter_type" hw_vif_model="$vmdk_net_adapter" |
|
| 236 |
+ |
|
| 236 | 237 |
return |
| 237 | 238 |
fi |
| 238 | 239 |
|
| ... | ... |
@@ -246,14 +282,9 @@ function upload_image {
|
| 246 | 246 |
# Nova defaults to PV for all VHD images, but |
| 247 | 247 |
# the glance setting is needed for booting |
| 248 | 248 |
# directly from volume. |
| 249 |
- force_vm_mode="--property vm_mode=xen" |
|
| 249 |
+ force_vm_mode="vm_mode=xen" |
|
| 250 | 250 |
fi |
| 251 |
- openstack \ |
|
| 252 |
- --os-cloud=devstack-admin --os-region-name="$REGION_NAME" \ |
|
| 253 |
- image create \ |
|
| 254 |
- "$image_name" --public \ |
|
| 255 |
- --container-format=ovf --disk-format=vhd \ |
|
| 256 |
- $force_vm_mode < "${image}"
|
|
| 251 |
+ _upload_image "$image_name" ovf vhd "$image" $force_vm_mode |
|
| 257 | 252 |
return |
| 258 | 253 |
fi |
| 259 | 254 |
|
| ... | ... |
@@ -262,12 +293,7 @@ function upload_image {
|
| 262 | 262 |
# Setting metadata, so PV mode is used. |
| 263 | 263 |
if [[ "$image_url" =~ '.xen-raw.tgz' ]]; then |
| 264 | 264 |
image_name="${image_fname%.xen-raw.tgz}"
|
| 265 |
- openstack \ |
|
| 266 |
- --os-cloud=devstack-admin --os-region-name="$REGION_NAME" \ |
|
| 267 |
- image create \ |
|
| 268 |
- "$image_name" --public \ |
|
| 269 |
- --container-format=tgz --disk-format=raw \ |
|
| 270 |
- --property vm_mode=xen < "${image}"
|
|
| 265 |
+ _upload_image "$image_name" tgz raw "$image" vm_mode=xen |
|
| 271 | 266 |
return |
| 272 | 267 |
fi |
| 273 | 268 |
|
| ... | ... |
@@ -278,12 +304,7 @@ function upload_image {
|
| 278 | 278 |
die $LINENO "Unknown vm_mode=${vm_mode} for Virtuozzo image"
|
| 279 | 279 |
fi |
| 280 | 280 |
|
| 281 |
- openstack \ |
|
| 282 |
- --os-cloud=devstack-admin --os-region-name="$REGION_NAME" \ |
|
| 283 |
- image create \ |
|
| 284 |
- "$image_name" --public \ |
|
| 285 |
- --container-format=bare --disk-format=ploop \ |
|
| 286 |
- --property vm_mode=$vm_mode < "${image}"
|
|
| 281 |
+ _upload_image "$image_name" bare ploop "$image" vm_mode=$vm_mode |
|
| 287 | 282 |
return |
| 288 | 283 |
fi |
| 289 | 284 |
|
| ... | ... |
@@ -292,7 +313,7 @@ function upload_image {
|
| 292 | 292 |
local disk_format="" |
| 293 | 293 |
local container_format="" |
| 294 | 294 |
local unpack="" |
| 295 |
- local img_property="--property hw_rng_model=virtio" |
|
| 295 |
+ local img_property="hw_rng_model=virtio" |
|
| 296 | 296 |
case "$image_fname" in |
| 297 | 297 |
*.tar.gz|*.tgz) |
| 298 | 298 |
# Extract ami and aki files |
| ... | ... |
@@ -370,18 +391,18 @@ function upload_image {
|
| 370 | 370 |
esac |
| 371 | 371 |
|
| 372 | 372 |
if is_arch "ppc64le" || is_arch "ppc64" || is_arch "ppc"; then |
| 373 |
- img_property="$img_property --property hw_cdrom_bus=scsi --property os_command_line=console=hvc0" |
|
| 373 |
+ img_property="$img_property hw_cdrom_bus=scsi os_command_line=console=hvc0" |
|
| 374 | 374 |
fi |
| 375 | 375 |
|
| 376 | 376 |
if is_arch "aarch64"; then |
| 377 |
- img_property="$img_property --property hw_machine_type=virt --property hw_cdrom_bus=scsi --property hw_scsi_model=virtio-scsi --property os_command_line='console=ttyAMA0'" |
|
| 377 |
+ img_property="$img_property hw_machine_type=virt hw_cdrom_bus=scsi hw_scsi_model=virtio-scsi os_command_line='console=ttyAMA0'" |
|
| 378 | 378 |
fi |
| 379 | 379 |
|
| 380 | 380 |
if [ "$container_format" = "bare" ]; then |
| 381 | 381 |
if [ "$unpack" = "zcat" ]; then |
| 382 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" $img_property --public --container-format=$container_format --disk-format $disk_format < <(zcat --force "${image}")
|
|
| 382 |
+ _upload_image "$image_name" $container_format $disk_format <(zcat --force "$image") $img_property |
|
| 383 | 383 |
elif [ "$unpack" = "bunzip2" ]; then |
| 384 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" $img_property --public --container-format=$container_format --disk-format $disk_format < <(bunzip2 -cdk "${image}")
|
|
| 384 |
+ _upload_image "$image_name" $container_format $disk_format <(bunzip2 -cdk "$image") $img_property |
|
| 385 | 385 |
elif [ "$unpack" = "unxz" ]; then |
| 386 | 386 |
# NOTE(brtknr): unxz the file first and cleanup afterwards to |
| 387 | 387 |
# prevent timeout while Glance tries to upload image (e.g. to Swift). |
| ... | ... |
@@ -390,10 +411,10 @@ function upload_image {
|
| 390 | 390 |
tmp_dir=$(mktemp -d) |
| 391 | 391 |
image_path="$tmp_dir/$image_name" |
| 392 | 392 |
unxz -cv "${image}" > "$image_path"
|
| 393 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" $img_property --public --container-format=$container_format --disk-format $disk_format --file "$image_path" |
|
| 393 |
+ _upload_image "$image_name" $container_format $disk_format "$image_path" $img_property |
|
| 394 | 394 |
rm -rf $tmp_dir |
| 395 | 395 |
else |
| 396 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name" $img_property --public --container-format=$container_format --disk-format $disk_format < "${image}"
|
|
| 396 |
+ _upload_image "$image_name" $container_format $disk_format "$image" $img_property |
|
| 397 | 397 |
fi |
| 398 | 398 |
else |
| 399 | 399 |
# Use glance client to add the kernel the root filesystem. |
| ... | ... |
@@ -406,7 +427,7 @@ function upload_image {
|
| 406 | 406 |
if [ -n "$ramdisk" ]; then |
| 407 | 407 |
ramdisk_id=$(openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "$image_name-ramdisk" $img_property --public --container-format ari --disk-format ari < "$ramdisk" | grep ' id ' | get_field 2) |
| 408 | 408 |
fi |
| 409 |
- openstack --os-cloud=devstack-admin --os-region-name="$REGION_NAME" image create "${image_name%.img}" $img_property --public --container-format ami --disk-format ami ${kernel_id:+--property kernel_id=$kernel_id} ${ramdisk_id:+--property ramdisk_id=$ramdisk_id} < "${image}"
|
|
| 409 |
+ _upload_image "${image_name%.img}" ami ami "$image" ${kernel_id:+ kernel_id=$kernel_id} ${ramdisk_id:+ ramdisk_id=$ramdisk_id} $img_property
|
|
| 410 | 410 |
fi |
| 411 | 411 |
} |
| 412 | 412 |
|
| ... | ... |
@@ -65,6 +65,8 @@ GLANCE_LOCK_DIR=${GLANCE_LOCK_DIR:=$DATA_DIR/glance/locks}
|
| 65 | 65 |
GLANCE_STAGING_DIR=${GLANCE_MULTISTORE_FILE_IMAGE_DIR:=$DATA_DIR/os_glance_staging_store}
|
| 66 | 66 |
GLANCE_TASKS_DIR=${GLANCE_MULTISTORE_FILE_IMAGE_DIR:=$DATA_DIR/os_glance_tasks_store}
|
| 67 | 67 |
|
| 68 |
+GLANCE_USE_IMPORT_WORKFLOW=$(trueorfalse False GLANCE_USE_IMPORT_WORKFLOW) |
|
| 69 |
+ |
|
| 68 | 70 |
GLANCE_CONF_DIR=${GLANCE_CONF_DIR:-/etc/glance}
|
| 69 | 71 |
GLANCE_METADEF_DIR=$GLANCE_CONF_DIR/metadefs |
| 70 | 72 |
GLANCE_API_CONF=$GLANCE_CONF_DIR/glance-api.conf |