David K. Bainbridge | 7ae4f19 | 2016-09-29 09:01:38 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #D provides access to the CORD POD swtich identification service |
| 3 | |
| 4 | PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g') |
| 5 | |
| 6 | usage() { |
| 7 | echo "usage: $PROG <sub-command> [options]" |
| 8 | echo " list display the known switches" |
| 9 | echo " help this message" |
| 10 | } |
| 11 | |
| 12 | COMMAND=$1; shift |
| 13 | case $COMMAND in |
| 14 | list) |
| 15 | DO_JSON=0 |
| 16 | DO_MAP=0 |
| 17 | while [ $# -gt 0 ]; do |
| 18 | case $1 in |
| 19 | json|--json|-j) |
| 20 | DO_JSON=1 |
| 21 | ;; |
| 22 | help|--help|-h) |
| 23 | echo "usage: $PROG list [--json|-j]" |
| 24 | echo " json display output as JSON object" |
| 25 | exit 0 |
| 26 | ;; |
| 27 | *) |
| 28 | >&2 "Unknown option '$1'" |
| 29 | echo "usage: $PROG list [--json|-j]" |
| 30 | echo " json display output as JSON object" |
| 31 | exit 1 |
| 32 | ;; |
| 33 | esac |
| 34 | shift |
| 35 | done |
| 36 | if [ $DO_JSON -eq 1 ]; then |
| 37 | curl -sSL http://$CORD_HEAD_NODE:4244/switch/ |
| 38 | else |
| 39 | for LINE in "NAME,MAC,IP" $(curl -sSL http://$CORD_HEAD_NODE:4244/switch/ | jq '.[] | .name+","+.mac+","+.ip'); do |
| 40 | echo $LINE | sed -e 's/^"//;s/"$//' |
| 41 | done | column -s , -t |
| 42 | fi |
| 43 | ;; |
| 44 | help|-h|--help) |
| 45 | usage |
| 46 | exit 0 |
| 47 | ;; |
| 48 | *) |
| 49 | >&2 echo "Unknown subcommand '$COMMAND'" |
| 50 | usage |
| 51 | exit 1 |
| 52 | ;; |
| 53 | esac |