-
-
Save Molter/0cfd5578f2ea85ffe5bb9d7b02cd8771 to your computer and use it in GitHub Desktop.
How to iterate over all orgs and spaces on a Cloud Foundry endpoint (cf, cf routes, cf orgs, cf spaces, CloudFoundry)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
timeout=gtimeout | |
action() { | |
echo "cf_routes $1 $2" 1>&2 ; | |
local x=`cf_routes $1 $2 | egrep -v '^( *$|space *|name *|Getting routes|FAILED|No space targeted|No routes found)' | egrep '.' | perl -ne 'print " $_"'` ; | |
[[ -z $x ]] || echo -e " Found it:\n$x." ; | |
echo "" 1>&2 ; | |
} | |
main() { | |
for o in `cf_ls_orgs` ; do | |
echo "Org: $o" ; | |
action -o $o ; | |
for s in `cf_ls_spaces $o` ; do | |
echo " Space: $s" ; | |
action -s $s ; | |
# echo ; | |
done | |
# echo ; | |
done ; | |
} | |
cf_ls_orgs() { | |
$timeout 5 cf orgs | egrep -v '^( *$|name *$|Getting orgs)' ; | |
} | |
cf_ls_spaces() { | |
[[ -z $1 ]] || $timeout 5 cf target -o $1 | perl -ne 'print " $_"' 1>&2 ; | |
cf spaces | egrep -v '^( *$|name *$|Getting spaces|No spaces found)' ; | |
} | |
cf_routes() { # optional args: [-o $org] [-s $space] | |
local org='' ; | |
local space='' ; | |
while [[ $* ]] ; do | |
[[ $1 == "-o" ]] && { shift ; org=$1 ; shift ; } | |
[[ $1 == "-s" ]] && { shift ; space=$1 ; shift ; } | |
done ; | |
[[ -z $org ]] || $timeout 5 cf target -o $org | perl -ne 'print " $_"' 1>&2 ; | |
[[ -z $space ]] || $timeout 5 cf target -s $space 1>&2; | |
$timeout 5 cf routes ; | |
} | |
# main 2> /dev/null ; | |
main ; | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment