A script to retrieve metadata of all service instances
search cancel

A script to retrieve metadata of all service instances

book

Article ID: 298201

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

Sometimes there is the need to find out organization and space info of some/all service instances in TAS environment. This can be done with command cf curl /v2/service_instances, then retrieve org/space info individually for each service instance. 
This article provides a BASH script to retrieve org/space info of all service instances on the platform.

Environment

Product Version: 2.10

Resolution

1) Just put the following content into a script on a box where you want to run it. It requires cf and jq utility to be available through PATH environment variable

#!/bin/bash
printpage()
{
{
while read -r siguid spaceurl siname service_url; do
read -r sispacename orgurl < <(cf curl $spaceurl | jq -r '"\(.entity.name) \(.entity.organization_url)"' && printf '\0')
siorgname=$(cf curl $orgurl | jq -r .entity.name)
read -r service_name broker_name < <(cf curl $service_url | jq -r '"\(.entity.label) \(.entity.service_broker_name)"' && printf '\0')
printf "%-32s %-48s %-32s %-32s %-32s %-76s\n" "$siorgname" "$sispacename" "$broker_name" "$siname" "$service_name" "$siguid"
done
} < <(echo $resources | jq -r '"\(.metadata.guid) \(.entity.space_url) \(.entity.name) \(.entity.service_url)"' && printf '\0')
}

## main
# check if cf/jq exist
which cf > /dev/null 2>&1 ; existing=$?;
if [ $existing -ne 0 ]; then
echo "cf CLI not available. Please install it or set PATH env variable properly!"
exit 1
fi

which jq > /dev/null 2>&1 ; existing=$?;
if [ $existing -ne 0 ]; then
echo "jq utility not available. Please install it or set PATH env variable properly!"
exit 1
fi

# check if cf logged in
cf orgs > /dev/null 2>&1 ; login_status=$?;
if [ $login_status -ne 0 ]; then
echo "Not logged in yet. Please do 'cf login' first!"
exit 1
fi
## get first page
onepage=$(cf curl /v2/service_instances)
next_url=$(echo $onepage | jq -r '.next_url')
resources=$(echo $onepage | jq -r '.resources[]')
 
printf "%-32s %-48s %-32s %-32s %-32s %-76s\n" "ORG" "SPACE" "BROKER" "SI_NAME" "SERVICE" "SI_GUID"

echo $(yes - | head -n96)
printpage

## get remaining pages
while [ $next_url != "null" ]; do
onepage=$(cf curl $next_url)
next_url=$(echo $onepage | jq -r '.next_url')
resources=$(echo $onepage | jq -r '.resources[]')
printpage
done

2) Add execute permission to the script and run it. For example,

$ ./si.sh
ORG                              SPACE                                            BROKER                           SI_NAME                          SERVICE                          SI_GUID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
system                           system                                           scs-service-broker               my-config-server                 p.config-server                  08803f32-5ac0-4aef-85df-d998bfd5e0f2
p-spring-cloud-services          08803f32-5ac0-4aef-85df-d998bfd5e0f2             scs-mirror-service               mirror-svc                       p.mirror-service                 5c9bcd5a-8ad9-4dfd-a8c2-89612b33a504
system                           system                                           scs-service-broker               my-config-server1                p.config-server                  b7d1320d-7a67-4ac7-8a66-24589166ec94
p-spring-cloud-services          b7d1320d-7a67-4ac7-8a66-24589166ec94             scs-mirror-service               mirror-svc                       p.mirror-service                 69ac3c0e-1695-4066-b29d-1849cd83daaf



Attachments

get-service-instances-info.sh get_app