| #!/bin/bash |
| #D provides access to the CORD POD swtich identification service |
| |
| PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g') |
| |
| usage() { |
| echo "usage: $PROG <sub-command> [options]" |
| echo " list display the known switches" |
| echo " help this message" |
| } |
| |
| COMMAND=$1; shift |
| case $COMMAND in |
| list) |
| DO_JSON=0 |
| DO_MAP=0 |
| while [ $# -gt 0 ]; do |
| case $1 in |
| json|--json|-j) |
| DO_JSON=1 |
| ;; |
| help|--help|-h) |
| echo "usage: $PROG list [--json|-j]" |
| echo " json display output as JSON object" |
| exit 0 |
| ;; |
| *) |
| >&2 "Unknown option '$1'" |
| echo "usage: $PROG list [--json|-j]" |
| echo " json display output as JSON object" |
| exit 1 |
| ;; |
| esac |
| shift |
| done |
| if [ $DO_JSON -eq 1 ]; then |
| curl -sSL http://$CORD_HEAD_NODE:4244/switch/ |
| else |
| for LINE in "NAME,MAC,IP" $(curl -sSL http://$CORD_HEAD_NODE:4244/switch/ | jq '.[] | .name+","+.mac+","+.ip'); do |
| echo $LINE | sed -e 's/^"//;s/"$//' |
| done | column -s , -t |
| fi |
| ;; |
| help|-h|--help) |
| usage |
| exit 0 |
| ;; |
| *) |
| >&2 echo "Unknown subcommand '$COMMAND'" |
| usage |
| exit 1 |
| ;; |
| esac |