Skip to content

Fetch VM families from GCP for testing #2216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ virtual_machines:
rhel:
project: rhel-cloud
families:
- rhel-8
- rhel-9
"{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a X86_64 -p rhel-cloud') }}"
container_engine: podman

rhel-arm64:
project: rhel-cloud
arch: arm64
machine_type: t2a-standard-2
families:
- rhel-9-arm64
"{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a ARM64 -p rhel-cloud') }}"
container_engine: podman

rhel-s390x:
Expand All @@ -59,12 +58,8 @@ virtual_machines:
rhel-sap:
project: rhel-sap-cloud
families:
- rhel-8-4-sap-ha
- rhel-8-6-sap-ha
# RHEL SAP 8.4 seems to have an older version of podman that
# fails with our integration tests, so we stick with docker
# for now.
container_engine: docker
"{{ lookup('ansible.builtin.pipe', 'scripts/fetch_gcp_families.sh -a X86_64 -p rhel-sap-cloud') }}"
container_engine: podman

rhcos:
project: rhcos-cloud
Expand Down Expand Up @@ -140,16 +135,14 @@ virtual_machines:
ubuntu-os:
project: ubuntu-os-cloud
families:
- ubuntu-2204-lts
- ubuntu-2404-lts-amd64
"{{ lookup('ansible.builtin.pipe', \"scripts/fetch_gcp_families.sh -f '^ubuntu-\\d+-lts(-amd64)?$'\") }}"

ubuntu-arm:
project: ubuntu-os-cloud
arch: arm64
machine_type: t2a-standard-2
families:
- ubuntu-2204-lts-arm64
- ubuntu-2404-lts-arm64
"{{ lookup('ansible.builtin.pipe', \"scripts/fetch_gcp_families.sh -f '^ubuntu-\\d+-lts-arm64$'\") }}"

ubuntu-os-pro:
project: ubuntu-os-pro-cloud
Expand Down
86 changes: 86 additions & 0 deletions ansible/scripts/fetch_gcp_families.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

set -euo pipefail

function usage() {
echo "$0 [OPTIONS]"
echo ""
echo "[OPTIONS]"
echo " -a, --arch"
echo " Architecture wanted for the listed images"
echo " -p, --project"
echo " Project the image is hosted in"
echo " -f, --family"
echo " Regular expression for the image family to be listed"
}

TEMP=$(getopt -o 'ha:p:f:' -l 'help,arch,project,family' -n "$0" -- "$@")

# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
exit 1
fi

eval set -- "$TEMP"
unset TEMP

arch=""
family=""
project=""
filter=""
using_regex=0
using_aip=0

while true; do
case "${1:-}" in
'-h' | '--help')
usage
exit 0
;;

'-a' | '--arch')
arch="architecture=$2"
using_aip=1
shift 2
;;

'-p' | '--project')
project="selfLink=/$2/"
using_aip=1
shift 2
;;

'-f' | '--family')
family="family ~ \"$2\""
using_regex=1
shift 2
;;

'--')
shift
break
;;
esac
done

if ((using_regex != 0 && using_aip != 0)); then
echo >&2 "Mixing regex and AIP-160 is not supported in gcloud filters"
echo >&2 "see: https://cloud.google.com/compute/docs/reference/rest/v1/images/list"
exit 1
elif ((using_regex != 0)); then
filter="$family"
elif ((using_aip != 0)); then
if [[ -n "$project" ]]; then
filter="$project"
if [[ -n "$arch" ]]; then
filter="$filter AND $arch"
fi
elif [[ -n "$arch" ]]; then
filter="$arch"
fi
fi

gcloud compute images list \
--format='json(family)' \
--filter="$filter" \
--limit 10 | jq -cM '[ .[].family ]'
Loading