Usefull CLI to manage cloud.redhat.com openshift clusters: https://github.com/openshift-online/uhc-cli
-
API behind desciption https://api.openshift.com/
-
Get a API token: https://cloud.redhat.com/openshift/token
Store bearer token in $TOKEN
:
OFFLINE_ACCESS_TOKEN="\
[..snipped..]
"
export TOKEN=$(curl \
--silent \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "client_id=cloud-services" \
--data-urlencode "refresh_token=${OFFLINE_ACCESS_TOKEN}" \
https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token | \
jq -r .access_token)
curl -X GET "https://api.openshift.com/api/clusters_mgmt/v1/clusters" -H "accept: application/json" -H "Authorization: Bearer $TOKEN"
CSV:
curl -s -X GET "https://api.openshift.com/api/clusters_mgmt/v1/clusters" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq -r ' .items[] | [.creation_timestamp,.name,.id]|@csv'
curl -X DELETE "https://api.openshift.com/api/clusters_mgmt/v1/clusters/$CLUSTER-ID$?deprovision=false" -H "accept: application/json" -H "Authorization: Bearer $TOKEN"
Delete several clusters:
curl -s -X GET "https://api.openshift.com/api/clusters_mgmt/v1/clusters" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq -r ' .items[] | [.creation_timestamp,.id]|@csv' | grep '"2019-07-'| tr -d '"' | while read line ; do curl -v -X DELETE "https://api.openshift.com/api/clusters_mgmt/v1/clusters/${line#*,}?deprovision=false" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" ; done