Merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7
- amt_wsman-1.7
- Merge into 1.7
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 3349 | ||||
Proposed branch: | lp:~rvb/maas/amt_wsman-1.7 | ||||
Merge into: | lp:maas/1.7 | ||||
Diff against target: |
278 lines (+180/-19) 1 file modified
etc/maas/templates/power/amt.template (+180/-19) |
||||
To merge this branch: | bzr merge lp:~rvb/maas/amt_wsman-1.7 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Review via email: mp+251618@code.launchpad.net |
Commit message
Backport revision 3567: AMT power template changes to use in place of for any AMT versions > 8.
Description of the change
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (503 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 4s (359 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (407 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Hit http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/amt_wsman-1.7 into lp:maas/1.7 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Get:7 http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,509 kB in 3s (405 kB/s)
Reading package lists...
sudo DEBIAN_
--
Preview Diff
1 | === modified file 'etc/maas/templates/power/amt.template' |
2 | --- etc/maas/templates/power/amt.template 2015-01-29 17:17:57 +0000 |
3 | +++ etc/maas/templates/power/amt.template 2015-03-03 15:50:25 +0000 |
4 | @@ -38,17 +38,27 @@ |
5 | exit $1 |
6 | } |
7 | |
8 | +# XXX: bladernr 2015-02-04 bug=1331214: AMT ver > 8 needs wsman not amttool |
9 | +# Check the version of AMT on node. |
10 | +check_amt_version() { |
11 | + amt_version=$(issue_amt_command info 2>&1 | grep version | awk '{print $NF}') |
12 | + major_version=$(echo $amt_version | awk -F'.' '{print $1}') |
13 | + return $major_version |
14 | +} |
15 | + |
16 | |
17 | # Perform a command using amttool. |
18 | issue_amt_command() { |
19 | LC_ALL='C' AMT_PASSWORD="$power_pass" amttool "$ip_address" "$@" |
20 | } |
21 | |
22 | + |
23 | # Check that amttool is present. |
24 | check_amt_command() { |
25 | command -v amttool >/dev/null 2>&1 || { fail 2 "Missing amttool (amtterm package)"; } |
26 | } |
27 | |
28 | + |
29 | # Check that a node host has been passed. |
30 | check_bmc_host() { |
31 | if [ -z "$ip_address" ]; then |
32 | @@ -59,11 +69,11 @@ |
33 | fi |
34 | } |
35 | |
36 | -# Ask for node's power state: 'on' or 'off'. |
37 | -query_state() { |
38 | + |
39 | +# Ask for node's power state: 'on' or 'off', via amttool. |
40 | +amt_query_state() { |
41 | # Retry the state if it fails because it often fails the first time. |
42 | local state= |
43 | - local count= |
44 | for attempts in $(seq 0 10) |
45 | do |
46 | state=$(issue_amt_command info | grep '^Powerstate:' | awk '{print $2}') |
47 | @@ -91,21 +101,20 @@ |
48 | } |
49 | |
50 | |
51 | -# Power-cycle the machine, and boot it using the requested boot mode. |
52 | -restart() { |
53 | +# Power-cycle the machine via amttool, and boot it using the requested boot mode. |
54 | +amt_restart() { |
55 | yes | issue_amt_command powercycle "$amt_boot_mode" |
56 | } |
57 | |
58 | |
59 | -# Power the machine on, and boot it using PXE. |
60 | -power_on() { |
61 | - local attempts= |
62 | +# Power the machine on via amttool, and boot it using PXE. |
63 | +amt_power_on() { |
64 | # Try several times. Power commands often fail the first time. |
65 | for attempts in $(seq 0 10) |
66 | do |
67 | # Issue the AMT command; amttool will prompt for confirmation. |
68 | yes | issue_amt_command powerup "$amt_boot_mode" |
69 | - if [ "$(query_state)" = 'on' ] |
70 | + if [ "$(amt_query_state)" = 'on' ] |
71 | then |
72 | # Success. Machine is on. |
73 | return 0 |
74 | @@ -116,13 +125,12 @@ |
75 | } |
76 | |
77 | |
78 | -# Power the machine off. |
79 | -power_off() { |
80 | - local attempts= |
81 | +# Power the machine off amttool. |
82 | +amt_power_off() { |
83 | # Try several times. Power commands often fail the first time. |
84 | for attempts in $(seq 0 10) |
85 | do |
86 | - if [ "$(query_state)" = 'off' ] |
87 | + if [ "$(amt_query_state)" = 'off' ] |
88 | then |
89 | # Success. Machine is off. |
90 | return 0 |
91 | @@ -135,28 +143,181 @@ |
92 | } |
93 | |
94 | |
95 | +# Check that wsman is present. |
96 | +check_wsman_command() { |
97 | + command -v wsman >/dev/null 2>&1 || { fail 2 "Missing wsman (wsmancli package)"; } |
98 | +} |
99 | + |
100 | +# Issue the wsman command. |
101 | +issue_wsman_command() { |
102 | + POWER_TEMPLATE_HEAD=' |
103 | +<p:RequestPowerStateChange_INPUT xmlns:p="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_PowerManagementService"> |
104 | + <p:PowerState>' |
105 | + POWER_TEMPLATE_TAIL='</p:PowerState> |
106 | + <p:ManagedElement xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" |
107 | + xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"> |
108 | + <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address> |
109 | + <wsa:ReferenceParameters> |
110 | + <wsman:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem</wsman:ResourceURI> |
111 | + <wsman:SelectorSet> |
112 | + <wsman:Selector Name="CreationClassName">CIM_ComputerSystem</wsman:Selector> |
113 | + <wsman:Selector Name="Name">ManagedSystem</wsman:Selector> |
114 | + </wsman:SelectorSet> |
115 | + </wsa:ReferenceParameters> |
116 | + </p:ManagedElement> |
117 | +</p:RequestPowerStateChange_INPUT> |
118 | +' |
119 | + # Usage: issue_wsman_command on|off|restart|query |
120 | + ACTION="invoke -a RequestPowerStateChange" |
121 | + SCHEMA_URI='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_PowerManagementService?SystemCreationClassName="CIM_ComputerSystem",SystemName="Intel(r) AMT",CreationClassName="CIM_PowerManagementService",Name="Intel(r) AMT Power Management Service"' |
122 | + OPTS="--port 16992 --hostname $ip_address --username admin -p $power_pass -V -v" |
123 | + case $1 in |
124 | + on) |
125 | + template=${POWER_TEMPLATE_HEAD}2${POWER_TEMPLATE_TAIL} |
126 | + echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - |
127 | + ;; |
128 | + off) |
129 | + template=${POWER_TEMPLATE_HEAD}8${POWER_TEMPLATE_TAIL} |
130 | + echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - |
131 | + ;; |
132 | + restart) |
133 | + template=${POWER_TEMPLATE_HEAD}10${POWER_TEMPLATE_TAIL} |
134 | + echo ${template} | wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} -J - |
135 | + ;; |
136 | + query) |
137 | + ACTION="enumerate" |
138 | + SCHEMA_URI='http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_AssociatedPowerManagementService' |
139 | + OPTS="${OPTS} -o -j utf-8" |
140 | + wsman ${ACTION} "${SCHEMA_URI}" ${OPTS} |
141 | + ;; |
142 | + *) |
143 | + fail 2 "Unknown command issued to wsman" |
144 | + ;; |
145 | + esac |
146 | +} |
147 | + |
148 | + |
149 | +# Ask for node's power state: 'on' or 'off', via wsman. |
150 | +wsman_query_state() { |
151 | + # Retry the state if it fails because it often fails the first time. |
152 | + local state= |
153 | + for attempts in $(seq 0 10) |
154 | + do |
155 | + state=$(issue_wsman_command query | grep "h:PowerState" | awk -F [\<\>] '{print $3}') |
156 | + if [ -n "$state" ] |
157 | + then |
158 | + break |
159 | + fi |
160 | + # Wait 1 second between retries. AMT controllers are generally very |
161 | + # light and may not be comfortable with more frequent queries. |
162 | + sleep 1 |
163 | + done |
164 | + case "$state" in |
165 | + # There are a LOT of possible power states |
166 | + # 1: Other 9: Power Cycle (Off - Hard) |
167 | + # 2: On 10: Master Bus Reset |
168 | + # 3: Sleep - Light 11: Diagnostic Interrupt (NMI) |
169 | + # 4: Sleep - Deep 12: Off - Soft Graceful |
170 | + # 5: Power Cycle (Off - Soft) 13: Off - Hard Graceful |
171 | + # 6: Off - Hard 14: Master Bus Reset Graceful |
172 | + # 7: Hibernate (Off - Soft) 15: Power Cycle (Off - Soft Graceful) |
173 | + # 8: Off - Soft 16: Power Cycle (Off - Hard Graceful |
174 | + # 17: Diagnostic Interrupt (INIT) |
175 | + |
176 | + # These are all power states that indicate that the system is either ON or |
177 | + # will resume function in an ON or Powered Up state (e.g. being power |
178 | + # cycled currently) |
179 | + [2,3,4,5,7,9,10,14,15,16]) |
180 | + echo 'on' |
181 | + ;; |
182 | + # These 4 states should leave system completely powered down |
183 | + [6,8,12,13]) |
184 | + echo 'off' |
185 | + ;; |
186 | + *) |
187 | + fail 1 "Got unknown power state from node: '$state'" |
188 | + ;; |
189 | + esac |
190 | +} |
191 | + |
192 | + |
193 | +# Power-cycle the machine via wsman, and boot it using the requested boot mode. |
194 | +wsman_restart() { |
195 | + issue_wsman_command restart |
196 | +} |
197 | + |
198 | + |
199 | +# Power the machine on via wsman, and boot it using PXE. |
200 | +wsman_power_on() { |
201 | + # Issue the wsman command to change power state |
202 | + issue_wsman_command on |
203 | + # Check power state several times. It usually takes a second or two to get |
204 | + # the correct state. |
205 | + for attempts in $(seq 0 10) |
206 | + do |
207 | + if [ "$(wsman_query_state)" = 'on' ] |
208 | + then |
209 | + # Success. Machine is on. |
210 | + return 0 |
211 | + fi |
212 | + sleep 1 |
213 | + done |
214 | + fail 1 "Machine is not powering on. Giving up." |
215 | +} |
216 | + |
217 | +# Power the machine off via wsman. |
218 | +# Currently commented out because we need a way to power query the machines |
219 | +wsman_power_off() { |
220 | + # Issue the wsman command to change power state |
221 | + issue_wsman_command off |
222 | + # Check power state several times. It usually takes a second or two to get |
223 | + # the correct state |
224 | + for attempts in $(seq 0 10) |
225 | + do |
226 | + if [ "$(wsman_query_state)" = 'off' ] |
227 | + then |
228 | + # Success. Machine is off. |
229 | + return 0 |
230 | + fi |
231 | + sleep 1 |
232 | + done |
233 | + fail 1 "Machine is not powering off. Giving up." |
234 | +} |
235 | + |
236 | main() { |
237 | check_bmc_host |
238 | check_amt_command |
239 | + # Check AMT version |
240 | + check_amt_version |
241 | + amt_version=$? |
242 | + if [ ${amt_version} -gt 8 ]; then |
243 | + # version > 8, use wsman |
244 | + check_wsman_command |
245 | + tool="wsman" |
246 | + else |
247 | + # Use amttool |
248 | + tool="amt" |
249 | + fi |
250 | + |
251 | case "${power_change}" in |
252 | 'on') |
253 | - if [ "$(query_state)" = 'on' ] |
254 | + if [ "${tool}_query_state" = 'on' ] |
255 | then |
256 | # The machine is already up, so powering it up will do nothing. |
257 | # Cycle the power instead. |
258 | - restart |
259 | + ${tool}_restart |
260 | else |
261 | - power_on |
262 | + ${tool}_power_on |
263 | fi |
264 | ;; |
265 | 'off') |
266 | - if [ "$(query_state)" != 'off' ] |
267 | + if [ "${tool}_query_state" != 'off' ] |
268 | then |
269 | - power_off |
270 | + ${tool}_power_off |
271 | fi |
272 | ;; |
273 | 'query') |
274 | - query_state |
275 | + ${tool}_query_state |
276 | ;; |
277 | *) |
278 | fail 1 "Unknown power command: '$1'" |
Simple backport: self-approving.