Skip to content

Commit

Permalink
workflow: Add Openstack VM clean up job
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywang committed Jun 6, 2023
1 parent 3e07d7e commit bdd0208
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ':w
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Clean Openstack instances running over 8 hours
on:
workflow_dispatch:
schedule:
- cron: '0 */8 * * *'

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

- name: 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" --format json --os-compute-api-version 2.66
VM_LIST=$(openstack server list --name "^runner-*" --changes-before "$EARLY_TIME" --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_TENANT_NAME: ${{ secrets.OS_TENANT_NAME_RHOS_01 }}
OS_AUTH_URL: ${{ secrets.OS_AUTH_URL_RHOS_01 }}
OS_REGION_NAME: ${{ secrets.OS_REGION_NAME_RHOS_01 }}
42 changes: 42 additions & 0 deletions .github/workflows/clean-os.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Clean Openstack instances running over 8 hours
on:
workflow_dispatch:
schedule:
- cron: '0 */8 * * *'

jobs:
clean-rhos-01:
# 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: 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 }}

0 comments on commit bdd0208

Please sign in to comment.