diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-03-24 17:30:57 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-03-24 17:30:57 -0400 |
commit | 18bf614ca1d9fbabdf83495e7675a2cacaf6c2f4 (patch) | |
tree | de2352926ea476abcafcdb14790ea21958973db9 /udev/cloud-init-wait | |
parent | 4f2065ad569355d5d0bc54176bde6b8e55047341 (diff) | |
parent | 20cc8113dde9e6849e8a692aea64cf81a266406d (diff) | |
download | vyos-cloud-init-18bf614ca1d9fbabdf83495e7675a2cacaf6c2f4.tar.gz vyos-cloud-init-18bf614ca1d9fbabdf83495e7675a2cacaf6c2f4.zip |
support network configuration in cloud-init --local
this allows 'cloud-init --local' to fully run before networking comes up.
By doing so, we can now cleanly apply networking to the new system.
This adds support for reading ConfigDrive network configuration
and also from NoCloud. The support is only present for ubuntu/debian
at the current time. Other distros will follow.
Also ability to specify network configuration on kernel command line
via either ip= or network-config=<base64>.
Diffstat (limited to 'udev/cloud-init-wait')
-rwxr-xr-x | udev/cloud-init-wait | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/udev/cloud-init-wait b/udev/cloud-init-wait new file mode 100755 index 00000000..7d53dee4 --- /dev/null +++ b/udev/cloud-init-wait @@ -0,0 +1,68 @@ +#!/bin/sh + +CI_NET_READY="/run/cloud-init/network-config-ready" +LOG="/run/cloud-init/${0##*/}.log" +LOG_INIT=0 +DEBUG=0 + +block_until_ready() { + local fname="$1" + local naplen="$2" max="$3" n=0 + while ! [ -f "$fname" ]; do + n=$(($n+1)) + [ "$n" -ge "$max" ] && return 1 + sleep $naplen + done +} + +log() { + [ -n "${LOG}" ] || return + [ "${DEBUG:-0}" = "0" ] && return + + if [ $LOG_INIT = 0 ]; then + if [ -d "${LOG%/*}" ] || mkdir -p "${LOG%/*}"; then + LOG_INIT=1 + else + echo "${0##*/}: WARN: log init to ${LOG%/*}" 1>&2 + return + fi + elif [ "$LOG_INIT" = "-1" ]; then + return + fi + local info="$$ $INTERFACE" + if [ "$DEBUG" -gt 1 ]; then + local up idle + read up idle < /proc/uptime + info="$$ $INTERFACE $up" + fi + echo "[$info]" "$@" >> "$LOG" +} + +main() { + local name="" readyfile="$CI_NET_READY" + local info="INTERFACE=${INTERFACE} ID_NET_NAME=${ID_NET_NAME}" + info="$info ID_NET_NAME_PATH=${ID_NET_NAME_PATH}" + info="$info MAC_ADDRESS=${MAC_ADDRESS}" + log "$info" + + ## Check to see if cloud-init.target is set. If cloud-init is + ## disabled we do not want to do anything. + if [ ! -f "/run/cloud-init/enabled" ]; then + log "cloud-init disabled" + return 0 + fi + + if [ "${INTERFACE#lo}" != "$INTERFACE" ]; then + return 0 + fi + + block_until_ready "$readyfile" .1 600 || + { log "failed waiting for ready on $INTERFACE"; return 1; } + + log "net config ready" +} + +main "$@" +exit + +# vi: ts=4 expandtab |