This file is indexed.

/etc/maas/templates/power/amt.template is in maas-cluster-controller 1.5+bzr2252-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
#!/bin/sh
# -*- mode: shell-script -*-
#
# Control a system via amttool
power_change='{{power_change}}'
power_pass='{{power_pass}}'
ip_address='{{ip_address}}'

echo amt.template starting $*

echo ip_address $ip_address
echo power_change $power_change
echo power_pass $power_pass

amt() {
  echo running amttool "$ip_address" $*
  AMT_PASSWORD="$power_pass" amttool "$ip_address" "$@"
}

state() {
  state=`{
    # Retry the state if it fails because it often fails the first time.
    amt 2> /dev/null || amt
  } | grep '^Powerstate:' | awk '{print $2}'`
  echo $state
}

is_power_on() {
  [ "$power_change" '=' on ]
}


if is_power_on; then
  desired_state=S0
else
  desired_state=S5
fi

echo desired $desired_state

current_state=`state`
for i in `seq 0 1`; do
  echo found current_state $current_state
  if [ "$current_state" '=' "" ]; then
    echo Cannot get current state
    exit 2
  fi
  if is_power_on; then
    if [ "$current_state" '=' S0 ]; then
      # If the machine is already up, the powerup command will
      # not work - we need to powercycle instead.
      args='powercycle pxe'
    else
      args='powerup pxe'
    fi
  else
    if [ "$current_state" '=' S5 ]; then
       # Machine is already off, so no need to do anything.
       exit 0
    fi
    args='powerdown'
  fi
  yes | amt $args
  current_state=`state`
  if [ "$current_state" '=' $desired_state ]; then
    exit 0
  fi
  echo retrying
done
echo Failed after several attempts
exit 1