-
Notifications
You must be signed in to change notification settings - Fork 3
/
ilom-snapshot
executable file
·178 lines (142 loc) · 5.11 KB
/
ilom-snapshot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#! /bin/sh
#
# WARNING: This utility depends on the `ilom-address` script, which
# you MUST customize to your cluster environment.
#
PROG="$(basename $0)"
## defaults
ILOM_SNAPSHOT_TYPE=${ILOM_SNAPSHOT_TYPE:-normal}
action="download"
serv='SP'
## usage and version text
usage () {
cat <<EOF
Usage: $PROG [-d|--download] [options] [HOST ...]
$PROG -s|--status [options] [HOST ...]
Command that an ILOM snapshot be saved to a download URL, or report on
the snapshot progress status.
Action options:
--download, -d Start downloading a snapshot to the given download URL.
--status, -s Report on the download status. Only one download per host
may be active at a given time.
Snapshot-related options:
--cmm Alias for '--kind CMM'.
--kind, -k SERV Tell the command that is has to talk to a
blade/server service processor (SERV is 'SP',
default), or to a chassis management module (SERV is 'CMM').
--sp Alias for '--kind SP'.
--type, -t TYPE Set snapshot type. TYPE must be one of the following words:
* "normal": Normal ILOM snapshot. This is the default.
* "fruid": Extended ILOM snapshot, including information
about the FRUs configured on the server.
* "full": Most comprehensive snapshot type. WARNING:
may reset the OS!
* "normal-logonly", "fruid-logonly", "full-logonly":
Like "normal", "fruid", "full", but the snapshot
will contain only the log files.
--download-url, -u URL
Save the snapshot file to this URL. The URL has the form
'protocol://USERNAME:PASSWORD@HOST/DIR', where
protocol is either 'sftp' or 'ftp'.
Note that for sftp:// URLs, DIR is an absolute path from
the root of the filesystem (contrary to what Oracle docs state).
Other options:
--help, -h Print this help text.
EOF
}
## helper functions
die () {
rc="$1"
shift
(echo -n "$PROG: ERROR: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
exit $rc
}
warn () {
(echo -n "$PROG: WARNING: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
}
have_command () {
type "$1" >/dev/null 2>/dev/null
}
require_command () {
if ! have_command "$1"; then
die 1 "Could not find required command '$1' in system PATH. Aborting."
fi
}
is_absolute_path () {
expr match "$1" '/' >/dev/null 2>/dev/null
}
## parse command-line
short_opts='dhk:st:u:'
long_opts='cmm,download,download-url:,kind:,sp,status,type:,help'
if [ "x$(getopt -T)" != 'x--' ]; then
# GNU getopt
args=$(getopt --name "$PROG" --shell sh -l "$long_opts" -o "$short_opts" -- "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$PROG --help' to get usage information."
fi
# use 'eval' to remove getopt quoting
eval set -- $args
else
# old-style getopt, use compatibility syntax
args=$(getopt "$short_opts" "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$PROG --help' to get usage information."
fi
set -- $args
fi
while [ $# -gt 0 ]; do
case "$1" in
--cmm) serv='CMM' ;;
--download-url|-u) ILOM_DOWNLOAD_URL="$2"; shift ;;
--download|-d) action='download' ;;
--kind|-k) serv="$2"; shift ;;
--sp) serv='SP' ;;
--status|-s) action='status' ;;
--type|-t) ILOM_SNAPSHOT_TYPE="$2"; shift ;;
--help|-h) usage; exit 0 ;;
--) shift; break ;;
esac
shift
done
## sanity checks
require_command ssh
case "$ILOM_SNAPSHOT_TYPE" in
normal|normal-logonly) ;;
fruid|fruid-logonly) ;;
full|full-logonly) ;;
*) die 1 "Invalid snapshot type '$ILOM_SNAPSHOT_TYPE'. Valid values are: 'normal', 'fruid', 'full', 'normal-logonly', 'fruid-logonly', 'full-logonly'." ;;
esac
# allow SERV to be case-insensitive
case "$serv" in
[Cc]*) serv='CMM' ;;
[Ss]*) serv='SP' ;;
esac
## main
for host in "$@"; do
case "$action" in
download)
if [ -z "$ILOM_DOWNLOAD_URL" ]; then
die 1 "No download URL specified. Plase set one with the '--download-url' command-line option or the ILOM_DOWNLOAD_URL environment variable."
fi
echo "==== ${host} ===="
echo -e "set /${serv}/diag/snapshot dataset=${ILOM_SNAPSHOT_TYPE}\nset /${serv}/diag/snapshot dump_uri=${ILOM_DOWNLOAD_URL}\nexit" \
| ssh -T $(ilom-address "$host")
;;
status)
echo -n "${host}: "
echo -e "show /${serv}/diag/snapshot\nexit" \
| ssh -T $(ilom-address "$host") \
| grep -F -A1 'result' \
| sed -r -e 's/^\s*result =\s+//' \
| tr '\n' '^' \
| sed -r -e 's/\^/: /g' \
| sed -r -e 's/:\s*$//'
echo
;;
*)
die 1 "Invalid action $action. Please re-run with '--download' or '--status' option."
;;
esac
done