/etc/maas/templates/commissioning-user-data/user_data.template is in maas-region-controller-min 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 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 | #!/bin/sh
#
# This script carries inside it multiple files. When executed, it creates
# the files into a temporary directory, downloads and extracts commissioning
# scripts from the metadata service, and then processes the scripts.
#
# The commissioning scripts get run by a close equivalent of run-parts.
# For each, the main script calls home to maas with maas-signal, posting
# the script's output as a separate file.
#
#### IPMI setup ######
# If IPMI network settings have been configured statically, you can
# make them DHCP. If 'true', the IPMI network source will be changed
# to DHCP.
IPMI_CHANGE_STATIC_TO_DHCP="false"
# In certain hardware, the parameters for the ipmi_si kernel module
# might need to be specified. If you wish to send parameters, uncomment
# the following line.
#IPMI_SI_PARAMS="type=kcs ports=0xca2"
#### script setup ######
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX")
SCRIPTS_D="${TEMP_D}/commissioning.d"
IPMI_CONFIG_D="${TEMP_D}/ipmi.d"
BIN_D="${TEMP_D}/bin"
OUT_D="${TEMP_D}/out"
PATH="$BIN_D:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
trap cleanup EXIT
mkdir -p "$BIN_D" "$OUT_D" "$SCRIPTS_D" "$IPMI_CONFIG_D"
# Ensure that invocations of apt-get are not interactive by default,
# here and in all subprocesses.
export DEBIAN_FRONTEND=noninteractive
### some utility functions ####
aptget() {
apt-get --assume-yes -q "$@" </dev/null
}
add_bin() {
cat > "${BIN_D}/$1"
chmod "${2:-755}" "${BIN_D}/$1"
}
add_ipmi_config() {
cat > "${IPMI_CONFIG_D}/$1"
chmod "${2:-644}" "${IPMI_CONFIG_D}/$1"
}
cleanup() {
[ -n "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
}
find_creds_cfg() {
local config="" file="" found=""
# If the config location is set in environment variable, trust it.
[ -n "${COMMISSIONING_CREDENTIALS_URL}" ] &&
_RET="${COMMISSIONING_CREDENTIALS_URL}" && return
# Go looking for local files written by cloud-init.
for file in /etc/cloud/cloud.cfg.d/*cmdline*.cfg; do
[ -f "$file" ] && _RET="$file" && return
done
local opt="" cmdline=""
if [ -f /proc/cmdline ] && read cmdline < /proc/cmdline; then
# Search through /proc/cmdline arguments:
# cloud-config-url trumps url=
for opt in $cmdline; do
case "$opt" in
url=*)
found=${opt#url=};;
cloud-config-url=*)
_RET="${opt#*=}"
return 0;;
esac
done
[ -n "$found" ] && _RET="$found" && return 0
fi
return 1
}
# Invoke the "signal()" API call to report progress.
# Usage: signal <status> <message>
signal() {
maas-signal "--config=${CRED_CFG}" "$@"
}
# Report result of a commissioning script: output file, error output
# file if there was any error output, and return code.
# Usage: signal <return-value> <message> <stdout-file> <stderr-file>
signal_result() {
local result=$1 message="$2" stdout="$3" stderr="$4"
local files="--file=$stdout"
if [ -f "$stderr" -a -s "$stderr" ]
then
files="$files --file=$stderr"
fi
maas-signal \
"--config=${CRED_CFG}" \
"--script-result=$result" \
$files \
WORKING "$message"
}
fail() {
[ -z "$CRED_CFG" ] || signal FAILED "$1"
echo "FAILED: $1" 1>&2;
exit 1
}
write_poweroff_job() {
cat >/etc/init/maas-poweroff.conf <<EOF
description "poweroff when maas task is done"
start on stopped cloud-final
console output
task
script
[ ! -e /tmp/block-poweroff ] || exit 0
poweroff
end script
EOF
# reload required due to lack of inotify in overlayfs (LP: #882147)
initctl reload-configuration
}
main() {
write_poweroff_job
# Install tools and load modules.
aptget update
aptget install freeipmi-tools openipmi ipmitool
load_modules
# The main function, actually execute stuff that is written below.
local script total=0 creds=""
find_creds_cfg ||
fail "failed to find credential config"
creds="$_RET"
# Get remote credentials into a local file.
case "$creds" in
http://*|https://*)
wget "$creds" -O "${TEMP_D}/my.creds" ||
fail "failed to get credentials from $cred_cfg"
creds="${TEMP_D}/my.creds"
;;
esac
# Use global name read by signal() and fail.
CRED_CFG="$creds"
# Power settings.
local pargs=""
if $IPMI_CHANGE_STATIC_TO_DHCP; then
pargs="--dhcp-if-static"
fi
power_type=$(maas-ipmi-autodetect-tool)
case "$power_type" in
ipmi)
power_settings=$(maas-ipmi-autodetect --configdir "$IPMI_CONFIG_D" ${pargs})
;;
moonshot)
power_settings=$(maas-moonshot-autodetect)
;;
esac
if [ ! -z "$power_settings" ]; then
signal "--power-type=${power_type}" "--power-parameters=${power_settings}" WORKING "finished [maas-ipmi-autodetect]"
fi
# Download and extract commissioning scripts. It will contain a
# commissioning.d directory, so this is how $SCRIPTS_D is created.
maas-get --config="${CRED_CFG}" maas-commissioning-scripts | tar -C "${TEMP_D}" -x
# Just get a count of how many scripts there are for progress reporting.
for script in "${SCRIPTS_D}/"*; do
[ -x "$script" -a -f "$script" ] || continue
total=$(($total+1))
done
local cur=1 numfailed=0 name="" failed="" separator=""
for script in "${SCRIPTS_D}/"*; do
[ -f "$script" -a -f "$script" ] || continue
name=${script##*/}
signal WORKING "starting ${name} [$cur/$total]"
"$script" > "${OUT_D}/${name}.out" 2> "${OUT_D}/${name}.err"
ret=$?
signal_result \
"$ret" "finished $name [$cur/$total]: $ret" \
"${OUT_D}/${name}.out" \
"${OUT_D}/${name}.err"
if [ $ret -ne 0 ]; then
numfailed=$(($numfailed+1))
failed="${failed}${separator}${name}"
separator=", "
fi
cur=$(($cur+1))
done
if [ $numfailed -eq 0 ]; then
( cd "${OUT_D}" &&
signal OK "finished [$total/$total]" )
return 0
else
( cd "${OUT_D}" &&
signal FAILED "failed [$numfailed/$total] ($failed)" )
return $numfailed
fi
}
load_modules() {
modprobe ipmi_msghandler
modprobe ipmi_devintf
modprobe ipmi_si ${IPMI_SI_PARAMS}
udevadm settle
}
### begin writing files ###
# Example config: enable BMC remote access (on some systems.)
#add_ipmi_config "02-global-config.ipmi" <<"END_IPMI_CONFIG"
#Section Lan_Channel
# Volatile_Access_Mode Always_Available
# Volatile_Enable_User_Level_Auth Yes
# Volatile_Channel_Privilege_Limit Administrator
# Non_Volatile_Access_Mode Always_Available
# Non_Volatile_Enable_User_Level_Auth Yes
# Non_Volatile_Channel_Privilege_Limit Administrator
#EndSection
#END_IPMI_CONFIG
add_bin "maas-ipmi-autodetect-tool" <<"END_MAAS_IPMI_AUTODETECT_TOOL"
{{maas_ipmi_autodetect_tool_py}}
END_MAAS_IPMI_AUTODETECT_TOOL
add_bin "maas-ipmi-autodetect" <<"END_MAAS_IPMI_AUTODETECT"
{{maas_ipmi_autodetect_py}}
END_MAAS_IPMI_AUTODETECT
add_bin "maas-moonshot-autodetect" <<"END_MAAS_MOONSHOT_AUTODETECT"
{{maas_moonshot_autodetect_py}}
END_MAAS_MOONSHOT_AUTODETECT
add_bin "maas_api_helper.py" <<"END_MAAS_API_HELPER"
{{maas_api_helper_py}}
END_MAAS_API_HELPER
add_bin "maas-signal" <<"END_MAAS_SIGNAL"
{{maas_signal_py}}
END_MAAS_SIGNAL
add_bin "maas-get" <<END_MAAS_GET
{{maas_get_py}}
END_MAAS_GET
main
exit
|