Skip to content

Clean Openstack instances running over 8 hours #164

Clean Openstack instances running over 8 hours

Clean Openstack instances running over 8 hours #164

Workflow file for this run

---
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 -sS -o /etc/pki/ca-trust/source/anchors/RH-IT-Root-CA.crt https://password.corp.redhat.com/RH-IT-Root-CA.crt
sudo update-ca-trust extract
# 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 }}