blob: 859e527376dfec55af44e9f974f59ddc260c43b9 [file] [log] [blame]
David K. Bainbridge7ae4f192016-09-29 09:01:38 -07001#!/bin/bash
Jonathan Hart1728fc82017-08-22 12:47:10 -07002#D provides access to the CORD POD switch identification service
David K. Bainbridge7ae4f192016-09-29 09:01:38 -07003
4PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g')
5
6usage() {
7 echo "usage: $PROG <sub-command> [options]"
8 echo " list display the known switches"
9 echo " help this message"
10}
11
12COMMAND=$1; shift
13case $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 ;;
53esac