blob: f7136cc2ca9346c36fc3026751e6f55a6ab509fc [file] [log] [blame]
David K. Bainbridge7ae4f192016-09-29 09:01:38 -07001#!/bin/bash
2#D provides access to the CORD POD base metal provisioning service
3
4PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g')
5
6usage() {
7 echo "usage: $PROG <sub-command> [options]"
8 echo " list display the provisioning status of all nodes"
Jonathan Hart1728fc82017-08-22 12:47:10 -07009 echo " show display the provisioning status of a single node"
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070010 echo " delete delete node(s) provisioning state"
11 echo " help this message"
12}
13
14COMMAND=$1; shift
15case $COMMAND in
16 list)
17 DO_JSON=0
18 DO_MAP=0
19 while [ $# -gt 0 ]; do
20 case $1 in
21 json|--json|-j)
22 DO_JSON=1
23 ;;
24 map|--map|-m)
25 DO_MAP=1
26 ;;
27 help|--help|-h)
28 echo "usage: $PROG list [--json|-j] [--map|-m]"
29 echo " json display output as JSON object"
30 echo " map map node provisioning status to state name"
31 exit 0
32 ;;
33 *)
34 >&2 "Unknown option '$1'"
35 echo "usage: $PROG list [--json|-j] [--map|-m]"
36 echo " json display output as JSON object"
37 echo " map map node provisioning status to state name"
38 exit 1
39 ;;
40 esac
41 shift
42 done
David K. Bainbridge2ade18e2016-09-30 16:08:04 -070043 if [ $DO_JSON -eq 1 ]; then
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070044 if [ $DO_MAP -eq 1 ]; then
David K. Bainbridgef757bc72016-11-16 21:45:52 -080045 curl -sSL http://$CORD_HEAD_NODE:4243/provision/ | jq -c -M 'def STATUS: ["Pending","Processing","Complete","Error"]; [ .[] | . | .status|=STATUS[.] ]'
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070046 else
47 curl -sSL http://$CORD_HEAD_NODE:4243/provision/
48 fi
49 else
David K. Bainbridgef757bc72016-11-16 21:45:52 -080050 for LINE in "ID,NAME,MAC,IP,STATUS,MESSAGE" $(curl -sSL http://$CORD_HEAD_NODE:4243/provision/ | jq 'def STATUS: ["Pending","Processing","Complete","Error"]; .[] | . | .status|=STATUS[.] | .request.Info.id+","+.request.Info.name+","+.request.Info.mac+","+.request.Info.ip+","+.status+","+.message' | sed -e 's/ /__SPACE__/g'); do
David K. Bainbridge2ade18e2016-09-30 16:08:04 -070051 echo $LINE | sed -e 's/__SPACE__/ /g' -e 's/^"//;s/"$//'
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070052 done | column -s , -t
53 fi
54 ;;
55 show)
56 DO_JSON=0
57 DO_MAP=0
58 ID=
59 while [ $# -gt 0 ]; do
60 case $1 in
61 json|--json|-j)
62 DO_JSON=1
63 ;;
64 map|--map|-m)
65 DO_MAP=1
66 ;;
67 help)
68 echo "usage: $PROG show [--json|-j] [--map|-m] <id>"
69 echo " json display output as JSON object"
70 echo " map map node provisioning status to state name"
71 exit 0
72 ;;
73 *)
74 ID="$ID $1"
David K. Bainbridgef757bc72016-11-16 21:45:52 -080075 ;;
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070076 esac
77 shift
78 done
79 if [ $DO_JSON -eq 1 ]; then
80 if [ $DO_MAP -eq 1 ]; then
81 echo -n "["
82 for i in $ID; do
David K. Bainbridgef757bc72016-11-16 21:45:52 -080083 curl -sSL http://$CORD_HEAD_NODE:4243/provision/$i | jq -c -M 'def STATUS: ["Pending","Processing","Complete","Error"]; . | .status|=STATUS[.]'
David K. Bainbridge7ae4f192016-09-29 09:01:38 -070084 done | awk -vORS=, '{ print }' | sed 's/,$//'
85 echo -n "]"
86 else
87 echo -n "["
88 for i in $ID; do
89 curl -sSL http://$CORD_HEAD_NODE:4243/provision/$i | jq -c -M .
90 done | awk -vORS=, '{ print }' | sed 's/,$//'
91 echo -n "]"
92 fi
93 else
94 for i in "__TITLE__" $ID; do
95 if [ $i == "__TITLE__" ]; then
96 echo "ID,NAME,MAC,IP,STATUS,MESSAGE"
97 else
98 VALUE=$(curl --fail -sSL http://$CORD_HEAD_NODE:4243/provision/$i)
99 if [ $? -ne 0 ]; then
100 echo "$i, , , ,Not Found"
101 else
David K. Bainbridgef757bc72016-11-16 21:45:52 -0800102 echo "$VALUE" | jq 'def STATUS: ["Pending","Processing","Complete","Error"]; . | .status|=STATUS[.] | .request.Info.id+","+.request.Info.name+","+.request.Info.mac+","+.request.Info.ip+","+.status+","+.message'| sed -e 's/^"//;s/"$//'
David K. Bainbridge7ae4f192016-09-29 09:01:38 -0700103 fi
104 fi
105 done | column -s , -t
106 fi
107 ;;
108 delete)
109 ID=
110 while [ $# -gt 0 ]; do
111 case $1 in
112 all|-a|--all)
113 ID=$(curl -sSL http://$CORD_HEAD_NODE:4243/provision/ | jq '.[] | .request.Info.id' | sed -e 's/^"//;s/"$//')
114 ;;
115 help|-h|--help)
116 echo "$PROG delete [--all|-a] [<id> ...]"
117 exit 0
118 ;;
119 *)
120 ID="$ID $1"
121 ;;
122 esac
123 shift
124 done
125 for i in $ID; do
126 curl --fail -sSL -XDELETE http://$CORD_HEAD_NODE:4243/provision/$i
127 if [ $? -eq 0 ]; then
128 echo "$i DELETED"
129 else
130 echo "$i FAILED"
131 fi
132 done | column -s , -t
133 ;;
134 help|-h|--help)
135 usage
136 exit 0
137 ;;
138 *)
139 >&2 echo "Unknown subcommand '$COMMAND'"
140 usage
141 exit 1
142 ;;
143esac