Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1.62 KB

cloud-redhat-com.adoc

File metadata and controls

45 lines (34 loc) · 1.62 KB

cloud.redhat.com

Usefull CLI to manage cloud.redhat.com openshift clusters: https://github.com/openshift-online/uhc-cli

How to work with curl

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)

List clusters

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'

Delete a cluster

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