-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflow: Add Openstack VM clean up job
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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
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 }} |
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
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 }} |