-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlc-setfirstboottoharddisk
executable file
·429 lines (365 loc) · 17.2 KB
/
lc-setfirstboottoharddisk
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/bin/bash
# ###########################################################################
# Copyright (c) 2011, Dell Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Dell Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL DELL INC. BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ###########################################################################
# Authors: Chris A. Poblete
# Version: 1.0.0
# ###########################################################################
MYNAME=`basename $0`
MYPATH=${0%/*}
WSLNOINIT=1
. wsl-functions
export WSENUMOPTIMIZE=1
export WSENUMMAXELEM=512
fTimerInit
usage() {
${WSCOLORERR}
cat <<EOF
iDRAC Remote Services Workflow client, version 0.1.0
USAGE: ${MYNAME} IPAddress Username [Password] [OPTIONS]
[OPTIONS]
-express quiet mode and select defaults for options, default is ask.
-nocsior disable CSIOR at the end of workflow, default is keep enabled.
-resetidrac reset iDRAC prior to configuration, default is no reset.
-offhard power off the system with timeout, default is to wait for OS.
Using the web services interface of iDRAC with Lifecycle Controller
this script configures the first BIOS boot device to Hard Disk. To ensure
proper configuration that apply to different situations, the workflow
includes power down, reboot, enabling CSIOR and clearing iDRAC job
objects.
Before running this script, ensure you have saved your work on the host OS.
The entire process may take several minutes to complete in which
during this time, the system should not be used (i.e. downtime).
Requires: wsl.
EOF
${WSCOLORNORM}
exit 1
}
unset vExpress vResetMC vNocsior vOffhard
#[ ! -e "wsl" ] && [ ! -e "${MYPATH}/wsl" ] && echo "ERROR: failed to find wsl toolset!!!" && usage
fCheckReqOrUsage wsl
fCheckReqsOrUsage curl
fCheckReqsOrUsage xmllint
fCheckReqsOrUsage awk
fCheckReqsOrUsage sed
[ $# -lt 2 ] && usage
while [ ! -z "$1" ]; do
case "$1" in
-h|-help|--help ) usage
;;
-e|-express ) vExpress=1
;;
-resetidrac ) vResetMC=1
;;
-nocsior ) vNocsior=1
;;
-offhard ) vOffhard=8
;;
* )
[ -z "${WSENDPOINT}" ] && export WSENDPOINT="$1" && shift && continue
[ -z "${WSUSER}" ] && export WSUSER="$1" && shift && continue
[ -z "${WSPASS}" ] && export WSPASS="$1" && shift && continue
;;
esac
shift
done
vWorkingdir="${WSENDPOINT}-report"
saveresponse() {
name=$1
lookfor=$2
lookfor2=$3
export CURRENTXML="${name}.xml"
# [ -e "${CURRENTXML}" ] && warning "${CURRENTXML} exist and to be overwritten"
/bin/mv -f "${RETURNFILE}" "${CURRENTXML}"
note "response file is ${CURRENTXML}"
[ ! -z "${lookfor}" ] && fGetValueOf ${CURRENTXML} "${lookfor}" "${lookfor2}"
}
error() {
echo -e "\n#ERROR: $1\n"
cd -
fTimerPrint
exit 1
}
warning() {
echo -e "\n#WARNING: $1\n"
}
note() {
echo -e "\n### $1\n"
}
checkjobdone() {
statusval="$1"
export JDONE=1
llower=$(echo "${statusval}" | awk '{print tolower($0)}')
[[ "${llower}" =~ "new" ]] && return
[[ "${llower}" =~ "scheduled" ]] && return
[[ "${llower}" =~ "ready" ]] && return
[[ "${llower}" =~ "running" ]] && return
[[ "${llower}" =~ "downloading" ]] && return
[[ "${llower}" =~ "pending" ]] && return
export JDONE=0
}
vRunJobIdx=1
pollforjobdone() {
vSrcLineNo=$1
vJobID="$2"
vPollInterval=$3
count=0
while true; do
note "$LINENO: Polling for Job ${vJobID} completion" ; wsl get DCIM_LifecycleJob InstanceID=${vJobID}
saveresponse "runjob-${vRunJobIdx}" 'JobStatus'
checkjobdone "${PVALUE}"
[ ${JDONE} -eq 0 ] && note "$LINENO: Job done." && break
count=$((count + 1)) ; [ ${count} -gt ${vPollInterval} ] && error "${vSrcLineNo}: Wait for Job ${vJobID} completion timeout, check logs"
read -t 60 -n 1 -p "# ${vSrcLineNo}: Operation repeats until Job status becomes complete, press ENTER to stop wait..."
echo
done
count=0
while true; do
note "$LINENO: Polling RSStatus until ready" ; wsl invoke DCIM_LCService GetRSStatus
saveresponse "runstat-${vRunJobIdx}"
fGetValueOf ${CURRENTXML} "Status"
[ -z "${PVALUE}" ] && fGetValueOf ${CURRENTXML} "DMStatus"
echo "${PVALUE}" | grep -i "^ready" >/dev/null 2>&1
[ $? -eq 0 ] && note "$LINENO: RSStatus is Ready." && break
count=$((count + 1)) ; [ ${count} -gt 6 ] && error "${vSrcLineNo}: Wait for RSStatus response timeout, check logs"
read -t 60 -n 1 -p "# ${vSrcLineNo}: Operation repeats until status is Ready, press ENTER to stop wait..."
echo
done
vRunJobIdx=$((vRunJobIdx + 1))
return
}
${WSCOLORERR}
cat <<EOF
**************************************************************************
This script configures the first boot device of the server to HardDisk
using the Web Services interface (WSMAN) of Lifecycle Controller in iDRAC.
See the LICENSE file for license and agreement about running this script.
The following steps will be performed:
1. Check first boot device setting, If set to Harddrive then stop.
2. Get basic system inventory for analysis if needed later.
3. Check system health. If in bad state then stop.
4. Power off the system to stage CSIOR.
4b. (Optionally reset iDRAC to get to clean state.)
5. Clears all iDRAC jobs.
6. Enable CSIOR and power on the system for CSIOR to run.
7. Set first boot device to Harddisk
8. System reboot for changes to apply in System Services.
9. Changes should be applied and verified.
9b. (Optionally Disable CSIOR and schedule a reboot.)
10. Done
CSIOR runs during POST allowing iDRAC to collect system inventory.
The following tools are required for this script to run:
curl, xmllint, awk, sed
The entire process may take several minutes to complete in which
during this time, the system should not be used (i.e. downtime).
Ensure you have saved your work on the host OS!
For non-interactive execution, use -express option.
**************************************************************************
EOF
${WSCOLORNORM}
if [ -z "${vExpress}" ]; then
unset response
read -t 300 -n 1 -p "Do you wish to proceed? [y|N] " response
[ ! "${response}" = "y" -a ! "${response}" = "Y" ] && echo -e "\nAbort." && exit 1
fi
[ ! -d ${vWorkingdir} ] && /bin/mkdir ${vWorkingdir}
echo "${WSUSER}" | grep "^FILE:" >/dev/null 2>&1
if [ $? -eq 0 ]; then
credfile=$(echo "${WSUSER}" | sed 's/^FILE://')
/bin/cp "${credfile}" ${vWorkingdir}
fi
echo "CAP: ${vOffhard}"
cd ${vWorkingdir}
date >${LOGFILE}
note "$LINENO: Checking for boot order setting"
wsl enum DCIM_BootConfigSetting -mode epr && saveresponse "bootcfg-1a"
fSearchValueOf ${CURRENTXML} 1 Selector InstanceID IPL ; vIPLID=${PVALUE}
[ -z "${vIPLID}" ] && error "$LINENO: failed to get IPL key from instance, check logs"
wsl get DCIM_BootConfigSetting InstanceID=${vIPLID} && saveresponse "bootcfg-1b"
wsl enum DCIM_BootSourceSetting -mode epr && saveresponse "bootsrc-1a"
fSearchValueOf ${CURRENTXML} 1 Selector InstanceID HardDisk ; vHDID=${PVALUE}
[ -z "${vHDID}" ] && error "$LINENO: failed to get HDD key from instance, check logs"
wsl get DCIM_BootSourceSetting InstanceID=${vHDID} && saveresponse "bootsrc-1b"
fGetValueOf ${CURRENTXML} "CurrentAssignedSequence" ; vSeq=${PVALUE}
fGetValueOf ${CURRENTXML} "CurrentEnabledStatus" ; vEnabled=${PVALUE}
if [ -z "${vSeq}" ] || [ -z "${vEnabled}" ]; then
error "$LINENO: failed to get Sequence or EnabledStatus keys from instance, check logs"
fi
wsl enum DCIM_BIOSEnumeration -filter "select * from DCIM_BIOSEnumeration where AttributeName='BootMode'"
saveresponse "bootmode-1a" "CurrentValue" ; vBootMode=${PVALUE}
echo "${vBootMode}" | grep -i "bios" >/dev/null 2>&1 ; vBootMode=$?
if [ ${vSeq} -eq 0 ] && [ ${vEnabled} -eq 1 ] && [ ${vBootMode} -eq 0 ]; then
echo; note "$LINENO: IPL:HardDisk is already configured as first boot device, and Boot mode is BIOS.\n"
cd -
fTimerPrint
exit 0
fi
note "$LINENO: Proceeding to set boot order to ${vHDID}"
if [ -z "${vExpress}" ]; then
unset response
read -t 60 -n 1 -p "Do you wish to proceed? [y|N] " response
echo -e "\n"
[ ! "${response}" = "y" -a ! "${response}" = "Y" ] && echo -e "\nAbort." && exit 1
fi
note "$LINENO: Getting RSStatus" ; wsl invoke DCIM_LCService GetRSStatus && saveresponse "rsstatus-1"
note "$LINENO: Getting SystemView" ; wsl enum DCIM_SystemView && saveresponse "systemview-1"
note "$LINENO: Getting iDRACView" ; wsl enum DCIM_iDRACCardView && saveresponse "idracview-1"
note "$LINENO: Getting SWInventory" ; wsl enum DCIM_SoftwareIdentity && saveresponse "swinventory-1"
note "$LINENO: Getting HealthState"
wsl enum CIM_ComputerSystem -filter "select * from CIM_ComputerSystem where Name='srv:system'" ; STAT=$?
[ ${STAT} -ne 0 ] && error "$LINENO: Failed to get Host ComputerSystem instance"
saveresponse "hostcs-1" "HealthState"
fGetValueOf ${CURRENTXML} "EnabledState" ; vEnabled=${PVALUE}
[ -z "${vEnabled}" ] && error "$LINENO: failed to get HealthState key from instance, check logs"
[ ${vEnabled} -gt 15 ] && warning "$LINENO: Bad system health ${vEnabled} reported - may prevent normal operation, check logs"
note "$LINENO: System power off"
if [ ${vEnabled} -eq 2 ]; then
wsl enum CIM_ComputerSystem -mode epr -filter "select * from CIM_ComputerSystem where Name='srv:system'"
saveresponse "poweroff-1a"
[ -z "${vOffhard}" ] && vOffhard=12
wsl invoke CIM_PowerManagementService RequestPowerStateChange PowerState=${vOffhard} ManagedElement=FILE:${CURRENTXML}
saveresponse "poweroff-1b" "ReturnValue"
#wsl invoke CIM_ComputerSystem -filter "select * from CIM_ComputerSystem where Name='srv:system'" RequestStateChange RequestedState=3
#saveresponse "poweroff-1a" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && error "$LINENO: Failed to power off the system, check logs"
read -t 180 -n 1 -p "# $LINENO: Waiting 180 secs for OS to shutdown, press ENTER to stop wait..."
else
echo "system is not enabled."
read -t 60 -n 1 -p "# $LINENO: system not enabled, pausing 60 secs or press ENTER to stop wait..."
fi
echo
if [ "1" = "${vResetMC}" ]; then
note "$LINENO: iDRAC reset"
wsl invoke CIM_ComputerSystem -filter "select * from CIM_ComputerSystem where Name='systemmc'" RequestStateChange RequestedState=11
saveresponse "poweroff-1b" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && error "$LINENO: Failed to reset iDRAC, check logs"
read -t 180 -n 1 -p "# $LINENO: Waiting 180 secs for iDRAC reset to complete, press ENTER to stop wait..."
echo
count=0
while true; do
note "$LINENO: Getting RSStatus" ; wsl invoke DCIM_LCService GetRSStatus ; STAT=$?
[ ${STAT} -eq 0 ] && break
count=$((count + 1)) ; [ ${count} -gt 6 ] && error "$LINENO: Wait for RSStatus response timeout, check logs"
read -t 60 -n 1 -p "# $LINENO: Operation repeats until iDRAC responds, press ENTER to stop wait..."
echo
done
fi
note "$LINENO: Delete all jobs"
wsl invoke DCIM_JobService DeleteJobQueue JobID=JID_CLEARALL
saveresponse "deletejobs" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && error "$LINENO: Failed to delete all jobs, check logs"
note "$LINENO: Delete pending BIOS config"
wsl invoke DCIM_BIOSService DeletePendingConfiguration Target="BIOS.Setup.1-1"
saveresponse "deletebiosconfig"
note "$LINENO: Enable CSIOR"
wsl invoke DCIM_LCService SetAttribute AttributeName="Collect System Inventory on Restart" AttributeValue=Enabled
saveresponse "csior-1"
wsl invoke DCIM_LCService CreateConfigJob ScheduledStartTime='00000000000000.000000:000' RebootIfRequired=false
saveresponse "lcjob-1" "Selector" "InstanceID" ; vCsiorJob=${PVALUE}
wsl get DCIM_LifecycleJob InstanceID=${vCsiorJob}
[ $? -ne 0 ] && error "$LINENO: Failed to enable CSIOR, check logs"
note "$LINENO: System power on"
wsl invoke CIM_ComputerSystem -filter "select * from CIM_ComputerSystem where Name='srv:system'" RequestStateChange RequestedState=2
saveresponse "poweron-1a" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && error "$LINENO: Failed to power on the system, check logs"
# wait for job done and rsstatus ready
pollforjobdone $LINENO "${vCsiorJob}" 15
note "$LINENO: Getting BIOS attributes and BootSource setting"
wsl enum DCIM_BIOSEnumeration && saveresponse "bios-1a"
wsl enum DCIM_BIOSString && saveresponse "bios-1b"
wsl enum DCIM_BIOSInteger && saveresponse "bios-1c"
note "$LINENO: Setting boot order to ${vHDID}"
wsl invoke DCIM_BootConfigSetting ChangeBootOrderByInstanceID source=${vHDID}
saveresponse "chgboot-1a" "ReturnValue" ; note "$LINENO: ChangeBootOrderByInstanceID status=${PVALUE}"
wsl invoke DCIM_BootConfigSetting ChangeBootSourceState source=${vHDID} EnabledState=1
saveresponse "chgboot-1b" "ReturnValue" ; note "$LINENO: ChangeBootSourceState status=${PVALUE}"
note "$LINENO: Setting boot mode to BIOS"
wsl invoke DCIM_BIOSService SetAttribute Target="BIOS.Setup.1-1" AttributeName=BootMode AttributeValue=Bios
saveresponse "chgbootbios-1a" "Message" ; note "$LINENO: SetAttribute status=${PVALUE}"
note "$LINENO: Creating BIOS config job"
count=0
while true; do
wsl invoke DCIM_BIOSService CreateTargetedConfigJob Target="BIOS.Setup.1-1"
saveresponse "cfgjob-1a" "Selector" "InstanceID"
[ ! -z "${PVALUE}" ] && break
count=$((count + 1)) ; [ ${count} -gt 12 ] && error "$LINENO: Failed to create job - system services may still be unavailable, check logs"
read -t 60 -n 1 -p "# $LINENO: Operation repeats until job could be created, press ENTER to stop wait..."
echo
done
wsl get DCIM_LifecycleJob InstanceID=${PVALUE}
[ $? -ne 0 ] && error "$LINENO: Failed to create configjob for BIOS, check logs"
vCfgJob=${PVALUE}
note "$LINENO: Create reboot job"
# 1=powercycle, 2=gracefulreboot, 3=gracefulrebootforced
wsl invoke DCIM_SoftwareInstallationService CreateRebootJob RebootJobType=1
saveresponse "cfgjob-1b" "Selector" "InstanceID"
wsl get DCIM_LifecycleJob InstanceID=${PVALUE}
[ $? -ne 0 ] && error "$LINENO: Failed to create reboot job, check logs"
vReboot=${PVALUE}
note "$LINENO: Set config and reboot job to run now"
wsl invoke DCIM_JobService SetupJobQueue StartTimeInterval=TIME_NOW JobArray=${vCfgJob} JobArray=${vReboot}
saveresponse "cfgjob-1c" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && error "$LINENO: Failed to schedule jobs ${vCfgJob} ${vReboot}, check logs"
# wait for job done and rsstatus ready
pollforjobdone $LINENO "${vCfgJob}" 15
read -t 120 -n 1 -p "# $LINENO: Waiting 120 secs for iDRAC database initialization, press ENTER to stop wait..."
echo
wsl enum DCIM_BootConfigSetting && saveresponse "bootcfg-2a"
wsl enum DCIM_BootSourceSetting -mode epr && saveresponse "bootsrc-2a"
fSearchValueOf ${CURRENTXML} 1 Selector InstanceID HardDisk ; vHDID=${PVALUE}
wsl get DCIM_BootSourceSetting InstanceID=${vHDID} && saveresponse "bootsrc-2b"
fGetValueOf ${CURRENTXML} "CurrentAssignedSequence" ; vSeq=${PVALUE}
fGetValueOf ${CURRENTXML} "CurrentEnabledStatus" ; vEnabled=${PVALUE}
if [ ! -z "${vNocsior}" ]; then
note "$LINENO: Disable CSIOR"
wsl invoke DCIM_LCService SetAttribute AttributeName="Collect System Inventory on Restart" AttributeValue=Disabled
saveresponse "csior-2"
wsl invoke DCIM_LCService CreateConfigJob ScheduledStartTime='00000000000000.000000:000' RebootIfRequired=false
saveresponse "lcjob-2" "Selector" "InstanceID"
wsl get DCIM_LifecycleJob InstanceID=${PVALUE}
if [ $? -ne 0 ]; then
warning "$LINENO: Failed to disable CSIOR, check logs"
else
note "$LINENO: Reset the system to disable CSIOR"
wsl invoke CIM_ComputerSystem -filter "select * from CIM_ComputerSystem where Name='srv:system'" RequestStateChange RequestedState=11
saveresponse "powerreset-3" "ReturnValue"
[ -z "${PVALUE}" ] || [ ${PVALUE} -ne 0 ] && warning "$LINENO: Failed to reset the system, check logs"
fi
fi
if [ ${vSeq} -eq 0 ] && [ ${vEnabled} -eq 1 ]; then
echo; note "$LINENO: Set HardDisk as first boot device is complete, check logs for more information"
else
echo; error "$LINENO: Failed to set IPL:HardDisk as first boot device, check logs"
fi
cd -
fTimerPrint
exit 0
# ###########################################################################
# End of Code
# ###########################################################################