Clean Openstack instances running over 8 hours #1217
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Clean Openstack instances running over 8 hours | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 */8 * * *' | |
jobs: | |
clean-rhos: | |
# Do not run this job on any fork repos | |
if: github.repository == 'virt-s1/kite-action' | |
runs-on: container-runner | |
container: | |
image: quay.io/fedora/fedora:38-x86_64 | |
steps: | |
- name: Prepare openstack client environment | |
run: | | |
sudo dnf install -y python-openstackclient jq | |
sudo curl -kLO ${CERT_URL}/certs/Current-IT-Root-CAs.pem --output-dir /etc/pki/ca-trust/source/anchors | |
sudo update-ca-trust extract | |
env: | |
CERT_URL: ${{ secrets.CERT_URL }} | |
# Get required authentication env variables from openrc.sh exported from openstack UI | |
- name: 3rd - Clean Openstack VMs running over 8 hours | |
run: | | |
EARLY_TIME=$(date -u -d '-8 hour' +"%Y-%m-%dT%H:%M:%SZ") | |
openstack server list --name "^runner-*" --changes-before "$EARLY_TIME" --no-name-lookup --format json --os-compute-api-version 2.66 | |
VM_LIST=$(openstack server list --name "^runner-*" --status ACTIVE --changes-before "$EARLY_TIME" --no-name-lookup --format json --column Name --os-compute-api-version 2.66 | jq -r 'select(. | length > 0) | .[] | .Name') | |
if [ ! -z "$VM_LIST" ]; then | |
for item in ${VM_LIST[*]} | |
do | |
openstack server delete "$item" --force --wait | |
done | |
fi | |
env: | |
OS_USERNAME: ${{ secrets.OS_USERNAME_RHOS_01 }} | |
OS_PASSWORD: ${{ secrets.OS_PASSWORD_RHOS_01 }} | |
OS_PROJECT_NAME: ${{ secrets.OS_PROJECT_NAME_RHOS_01 }} | |
OS_AUTH_URL: ${{ secrets.OS_AUTH_URL_RHOS_01 }} | |
OS_REGION_NAME: ${{ secrets.OS_REGION_NAME_RHOS_01 }} | |
OS_USER_DOMAIN_NAME: ${{ secrets.OS_USER_DOMAIN_NAME_RHOS_01 }} | |
OS_PROJECT_DOMAIN_ID: ${{ secrets.OS_PROJECT_DOMAIN_ID_RHOS_01 }} | |
OS_IDENTITY_API_VERSION: ${{ secrets.OS_IDENTITY_API_VERSION_RHOS_01 }} | |
- name: RHEL-Edge - Clean Openstack VMs running over 8 hours | |
run: | | |
EARLY_TIME=$(date -u -d '-8 hour' +"%Y-%m-%dT%H:%M:%SZ") | |
openstack server list --name "^runner-*" --changes-before "$EARLY_TIME" --no-name-lookup --format json --os-compute-api-version 2.66 | |
VM_LIST=$(openstack server list --name "^runner-*" --status ACTIVE --changes-before "$EARLY_TIME" --no-name-lookup --format json --column Name --os-compute-api-version 2.66 | jq -r 'select(. | length > 0) | .[] | .Name') | |
if [ ! -z "$VM_LIST" ]; then | |
for item in ${VM_LIST[*]} | |
do | |
openstack server delete "$item" --force --wait | |
done | |
fi | |
env: | |
OS_USERNAME: ${{ secrets.OS_USERNAME_RHOS_0x }} | |
OS_PASSWORD: ${{ secrets.OS_PASSWORD_RHOS_0x }} | |
OS_PROJECT_NAME: ${{ secrets.OS_PROJECT_NAME_RHOS_0x }} | |
OS_AUTH_URL: ${{ secrets.OS_AUTH_URL_RHOS_0x }} | |
OS_REGION_NAME: ${{ secrets.OS_REGION_NAME_RHOS_0x }} | |
OS_USER_DOMAIN_NAME: ${{ secrets.OS_USER_DOMAIN_NAME_RHOS_0x }} | |
OS_PROJECT_DOMAIN_ID: ${{ secrets.OS_PROJECT_DOMAIN_ID_RHOS_0x }} | |
OS_IDENTITY_API_VERSION: ${{ secrets.OS_IDENTITY_API_VERSION_RHOS_0x }} |