Wednesday, January 27, 2021

OCI CLI to List all the Hosts Lifecycle

OCI CLI to List all the Hosts Lifecycle

This bash scripts needs the tenancy ID to be updated. It loops through all the compartments and then fetches the life cycle of each hosts. 

ociCompartmentList=$(oci iam compartment list --compartment-id ocid1.tenancy.oc1..aaaa1111222334)
for c in $(echo "$ociCompartmentList" | jq '.data | keys | .[]')
do
 compartment_ocid=$(echo "$ociCompartmentList" | jq -r ".data[$c].\"id\"")
 ociinstanceList=$(oci compute instance list -c $compartment_ocid)
 for i in $(echo "$ociinstanceList" | jq '.data | keys | .[]')
 do
   hostname=$(echo "$ociinstanceList" | jq -r ".data[$i].\"display-name\"")
   lifecycle=$(echo "$ociinstanceList" | jq -r ".data[$i].\"lifecycle-state\"")
   echo "Hostname: $hostname | LifeCycle: $lifecycle"
 done
done

Hostname: ebstestserver-001| LifeCycle: RUNNING
Hostname: ebstestserver-002| LifeCycle: RUNNING
Hostname: ebstestserver-003| LifeCycle: RUNNING
Hostname: ebstestserver-004| LifeCycle: RUNNING
Hostname: ebstestserver-005| LifeCycle: RUNNING
Hostname: ebstestserver-006| LifeCycle: RUNNING
Hostname: ebstestserver-007| LifeCycle: RUNNING
Hostname: ebstestserver-008| LifeCycle: RUNNING
Hostname: ebstestserver-009| LifeCycle: RUNNING
Hostname: ebstestserver-010| LifeCycle: RUNNING
Hostname: ebstestserver-011| LifeCycle: RUNNING
Hostname: ebstestserver-012| LifeCycle: RUNNING
Hostname: ebstestserver-013| LifeCycle: RUNNING
Hostname: ebstestserver-014| LifeCycle: RUNNING
Hostname: ebstestserver-015| LifeCycle: RUNNING
Hostname: ebstestserver-016| LifeCycle: RUNNING
Hostname: ebstestserver-017| LifeCycle: RUNNING
Hostname: ebstestserver-018| LifeCycle: RUNNING
Hostname: ebstestserver-019| LifeCycle: RUNNING
Hostname: ebstestserver-020| LifeCycle: RUNNING

Hope it helps.

Popular Posts