|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +DEPLOYMENT_ID="" |
| 4 | +CONTAINER_ID="" |
| 5 | + |
| 6 | +help() { |
| 7 | + echo -e "\nGaol Basher: A tool that makes connecting to bosh-lite Garden containers easy!" |
| 8 | + echo -e "\nUSAGE:" |
| 9 | + echo -e "------" |
| 10 | + echo -e "$0 <command> <parameter>" |
| 11 | + echo -e "\nCommands:" |
| 12 | + echo -e "---------" |
| 13 | + echo -e "help Displays this message." |
| 14 | + echo -e "deployments Prints the list of deployments." |
| 15 | + echo -e "jobs <deployment name> Prints the list of jobs for the deployment." |
| 16 | + echo -e "bash <job number> Initiates a bash session with the Garden container using Gaol.\n" |
| 17 | + echo -e "Go directly to Gaol. Do not pass Go, do not collect \$200.\n" |
| 18 | +} |
| 19 | + |
| 20 | +get_deployments() { |
| 21 | + echo -e "\nDeployments:" |
| 22 | + echo -e "------------" |
| 23 | + /var/vcap/packages/postgres/bin/psql -c "select id, name from deployments;" bosh |
| 24 | +} |
| 25 | + |
| 26 | +get_jobs() { |
| 27 | + echo -e "\nJobs:" |
| 28 | + echo -e "------" |
| 29 | + /var/vcap/packages/postgres/bin/psql -c "select id as job_number, job || '/' || index as job, vm_cid as container_uuid from instances WHERE vm_cid IS NOT NULL AND deployment_id = $1;" bosh |
| 30 | +} |
| 31 | + |
| 32 | +get_job_container_uuid () { |
| 33 | + CONTAINER_ID=$(/var/vcap/packages/postgres/bin/psql -t -c "select vm_cid from instances WHERE id = '$1';" bosh | awk '$1=$1') |
| 34 | +} |
| 35 | + |
| 36 | +get_deployment_id() { |
| 37 | + DEPLOYMENT_ID=$(/var/vcap/packages/postgres/bin/psql -t -c "select id from deployments where name = '$1';" bosh | awk '$1=$1') |
| 38 | +} |
| 39 | + |
| 40 | +if [[ "$1" = "deployments" ]]; then |
| 41 | + get_deployments |
| 42 | + exit 0 |
| 43 | +fi |
| 44 | + |
| 45 | +if [[ "$1" = "jobs" && "$2" != "" ]]; then |
| 46 | + get_deployment_id $2 |
| 47 | + if [[ -z "$DEPLOYMENT_ID" ]]; then |
| 48 | + echo "Deployment name "$2" not found." |
| 49 | + exit 0 |
| 50 | + fi |
| 51 | + get_jobs $DEPLOYMENT_ID |
| 52 | + exit 0 |
| 53 | +fi |
| 54 | + |
| 55 | +if [[ "$1" = "bash" && "$2" != "" ]]; then |
| 56 | + get_job_container_uuid $2 |
| 57 | + if [[ -z "$CONTAINER_ID" ]]; then |
| 58 | + echo "Job number "$2" not found." |
| 59 | + exit 0 |
| 60 | + fi |
| 61 | + /var/vcap/packages/toolbelt-gaol/bin/gaol shell $CONTAINER_ID |
| 62 | + exit 0 |
| 63 | +fi |
| 64 | + |
| 65 | +help |
0 commit comments