2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017, 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Checks the image "protected" value and set "True" marker
13 # The script searches the ciman repo for the images presently used and ensures
14 # the protection setting is set for those images to prevent the image from
15 # getting purged by the image cleanup script.
16 # This script assumes images prefixed with the string "ZZCI - " are ci-managed
18 echo "---> Protect in-use images"
20 os_cloud="${OS_CLOUD:-vex}"
26 declare -a yaml_images
27 readarray -t cfg_images <<< "$(grep -r IMAGE_NAME --include \*.cfg \
28 | awk -F'=' '{print $2}' | sort -u)"
29 readarray -t yaml_images <<< "$(grep -r 'ZZCI - ' --include \*.yaml \
30 | awk -F": " '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort -u)"
31 mapfile -t images < <(for R in "${cfg_images[@]}" "${yaml_images[@]}" ; do echo "$R" ; done | sort -u)
34 for image in "${images[@]}"; do
35 os_image_protected=$(openstack --os-cloud "$os_cloud" \
36 image show "$image" -f value -c protected)
37 echo "Protected setting for $image: $os_image_protected"
39 if [[ $os_image_protected != True ]]; then
40 echo " Image NOT set as protected, changing the protected value."
41 openstack --os-cloud "$os_cloud" image set --protected "$image"