8d1ddd5de6395a05d2750fb0259faddeb25b6d6b
[releng/global-jjb.git] / shell / openstack-cleanup-old-images.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017, 2018 The Linux Foundation and others.
5 #
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 # Removes openstack images older than X days in the cloud
12 echo "---> Cleanup old images"
13
14 # shellcheck disable=SC1090
15 source ~/lf-env.sh
16
17 set -x
18 # Check if openstack venv was previously created
19 if [ -f "/tmp/.os_lf_venv" ]; then
20     os_lf_venv=$(cat "/tmp/.os_lf_venv")
21 fi
22
23 if [ -d "${os_lf_venv}" ] && [ -f "${os_lf_venv}/bin/openstack" ]; then
24     echo "Re-use existing venv: ${os_lf_venv}"
25     PATH=$os_lf_venv/bin:$PATH
26 else
27     lf-activate-venv --python python3 "cryptography<3.4" \
28         "lftools[openstack]" \
29         kubernetes \
30         "niet~=1.4.2" \
31         python-heatclient \
32         python-openstackclient \
33         python-magnumclient \
34         setuptools \
35         "openstacksdk<0.99" \
36         yq
37 fi
38
39 os_cloud="${OS_CLOUD:-vex}"
40 os_image_cleanup_age="${OS_IMAGE_CLEANUP_AGE:-30}"
41
42 set -eux -o pipefail
43
44 lftools openstack --os-cloud "${os_cloud}" image cleanup --days="${os_image_cleanup_age}"