A script to show brief information of all service instances on TAS
search cancel

A script to show brief information of all service instances on TAS

book

Article ID: 298402

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

Sometimes the user might want to briefly list out all services instances on a TPCF foundation. This KB article provides some scripts to do the work.

Environment

TPCF with service tiles. 

Resolution

Installation

  • Copy/paste any of the following scripts and put it to some Linux machine with cf / jq utilities available 
    • get-si-info-v2.sh - CAPI V2
    • get-si-info-v3.sh - CAPI V3
  • Give execute permission to the script with "chmod +x" command

get-si-info-v2.sh

#!/bin/bash
printpage()
{
    {
      #read _; read _ # discard header and leading blank line
      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)
      service_name=$(cf curl $service_url | jq -r .entity.label)
      #echo "$siguid $siname $siorgname $sispacename" | awk '{ printf "%-40s|%-40s|%-40s|%-40s\n", $1, $2 , $3, $4}'
      printf "%-32s %-48s %-32s %-32s %-76s\n" "$siorgname" "$sispacename" "$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[]')

#echo "SI_GUID SI_NAME ORG SPACE" | awk '{ printf "%-40s|%-40s|%-40s|%-40s\n", $1, $2 , $3, $4}'
printf "%-32s %-48s %-32s %-32s %-76s\n" "ORG" "SPACE" "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

 

get-si-info-v3.sh

#!/bin/bash
printpage()
{
    {
      #read _; read _ # discard header and leading blank line
      while read -r siguid spaceguid siname planguid; do
      read -r sispacename orgurlref < <(cf curl "/v3/spaces/$spaceguid" | jq -r '"\(.name)  \(.links.organization.href)"' && printf '\0')
      orgurl=$(echo $orgurlref | sed -E 's|https?://[^/]+||')
      siorgname=$(cf curl $orgurl | jq -r .name)
      read -r service_offering_guid < <(cf curl "/v3/service_plans/$planguid" | jq -r '.relationships.service_offering.data.guid' && printf '\0')
      read -r service_offering_name service_broker_guid < <(cf curl "/v3/service_offerings/$service_offering_guid" | jq -r '"\(.name)  \(.relationships.service_broker.data.guid)"' && printf '\0')
      printf "%-48s %-48s %-48s %-48s %-76s\n" "$siname" "$siorgname" "$sispacename" "$service_offering_name" "$siguid"
      done
    } < <(echo $resources | jq -r '"\(.guid)  \(.relationships.space.data.guid)  \(.name) \(.relationships.service_plan.data.guid)"' && 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 "/v3/service_instances?order_by=name")

next_url=$(echo $onepage | jq -r '.pagination.next.href' | sed -E 's|https?://[^/]+||')
resources=$(echo $onepage | jq -r '.resources[]')

printf "%-48s %-48s %-48s %-48s %-76s\n" "SI_NAME" "ORG" "SPACE" "OFFERING" "SI_GUID"

echo $(yes - | head -n122)
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

 

Usage

  • Do "cf login" first with admin user
  • Run the script

Example

$ ./get-service-instances-info.sh 
ORG                              SPACE                                            SI_NAME                          SERVICE                          SI_GUID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
myorg                            myspace                                          my-config-server-1               p.config-server                  1be182b8-##-##-##-246ac9d29dc4
p-spring-cloud-services          1be182b8-##-##-##-246ac9d29dc4                   mirror-svc                       p.mirror-service                 2938e7d1-##-##-##-5fe265bf3517
myorg                            myspace                                          my-config-server-2               p.config-server                  7ef35451-##-##-##-b89dba4f2534


$ ./get-si-info-v3.sh

SI_NAME                                          ORG                                              SPACE                                            OFFERING                                         SI_GUID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
app-usage-server-metric-service                  system                                           system                                           null                                             69282378-##-##-##-27efa9cb2c93
config-server                                    test                                             test                                             p.config-server                                  1056728f-##-##-##-c9b219787801
mirror-svc                                       p-spring-cloud-services                          6b86fb12-##-##-##-1d6cafe0f35d             p.mirror-service                                 c64b7aa4-##-##-##-db2a3788e37f
mqtest                                           rabbittest                                       rabbittest                                       p.rabbitmq                                       8140cee8-##-##-##-b273db65f2df
my-autoscaler                                    alex                                             test                                             app-autoscaler                                   0526f710-##-##-##-6cc3740b5287
my-config-server                                 alex                                             test                                             p.config-server                                  6b86fb12-##-##-##-1d6cafe0f35d
service-registry                                 test                                             test                                             p.service-registry                               1828cc2d-##-##-##-acae365ae1fb