summaryrefslogtreecommitdiff
path: root/systemd/cloud-init-generator
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2017-02-04 02:24:55 +0000
committerScott Moser <smoser@brickies.net>2017-02-03 21:24:55 -0500
commit9698b0ded3d7e72f54513f248d8da41e08472f68 (patch)
treeb6640cfdf3521d43970559b3fd4e36ad421e18aa /systemd/cloud-init-generator
parent9a061c1838c3e9d2ed3f3d73e30248f7a79af7da (diff)
downloadvyos-cloud-init-9698b0ded3d7e72f54513f248d8da41e08472f68.tar.gz
vyos-cloud-init-9698b0ded3d7e72f54513f248d8da41e08472f68.zip
Add tools/ds-identify to identify datasources available.
ds-identify is run here from the generator. If ds-identify does not see any datasources, it can completely disable cloud-init. The big value in this is that if there is no datasource, no python will ever be loaded, and cloud-init will be disabled.o The default policy being added here is: search,found=all,maybe=all,notfound=disabled That means: - enable (in 'datasource_list') all sources that are found. - if none are found, enable all 'maybe'. - if no maybe are found, then disable cloud-init. On platforms without DMI (everything except for aarch64 and x86), the default 'notfound' setting is 'enabled'. This is because many of the detection mechanisms rely on dmi data, which is present only on x86 and aarch64.
Diffstat (limited to 'systemd/cloud-init-generator')
-rwxr-xr-xsystemd/cloud-init-generator39
1 files changed, 37 insertions, 2 deletions
diff --git a/systemd/cloud-init-generator b/systemd/cloud-init-generator
index fedb6309..bd9f2678 100755
--- a/systemd/cloud-init-generator
+++ b/systemd/cloud-init-generator
@@ -6,6 +6,8 @@ DEBUG_LEVEL=1
LOG_D="/run/cloud-init"
ENABLE="enabled"
DISABLE="disabled"
+FOUND="found"
+NOTFOUND="notfound"
RUN_ENABLED_FILE="$LOG_D/$ENABLE"
CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
CLOUD_TARGET_NAME="cloud-init.target"
@@ -74,10 +76,30 @@ default() {
_RET="$ENABLE"
}
+check_for_datasource() {
+ local ds_rc="" dsidentify="/usr/lib/cloud-init/ds-identify"
+ if [ ! -x "$dsidentify" ]; then
+ debug 1 "no ds-identify in $dsidentify. _RET=$FOUND"
+ return 0
+ fi
+ $dsidentify
+ ds_rc=$?
+ debug 1 "ds-identify rc=$ds_rc"
+ if [ "$ds_rc" = "0" ]; then
+ _RET="$FOUND"
+ debug 1 "ds-identify _RET=$_RET"
+ return 0
+ fi
+ _RET="$NOTFOUND"
+ debug 1 "ds-identify _RET=$_RET"
+ return 1
+}
+
main() {
local normal_d="$1" early_d="$2" late_d="$3"
local target_name="multi-user.target" gen_d="$early_d"
local link_path="$gen_d/${target_name}.wants/${CLOUD_TARGET_NAME}"
+ local ds="$NOTFOUND"
debug 1 "$0 normal=$normal_d early=$early_d late=$late_d"
debug 2 "$0 $*"
@@ -93,7 +115,20 @@ main() {
debug 0 "search $search returned $ret"
fi
done
-
+
+ # enable AND ds=found == enable
+ # enable AND ds=notfound == disable
+ # disable || <any> == disabled
+ if [ "$result" = "$ENABLE" ]; then
+ debug 1 "checking for datasource"
+ check_for_datasource
+ ds=$_RET
+ if [ "$ds" = "$NOTFOUND" ]; then
+ debug 1 "cloud-init is enabled but no datasource found, disabling"
+ result="$DISABLE"
+ fi
+ fi
+
if [ "$result" = "$ENABLE" ]; then
if [ -e "$link_path" ]; then
debug 1 "already enabled: no change needed"
@@ -124,7 +159,7 @@ main() {
rm -f "$RUN_ENABLED_FILE"
fi
else
- debug 0 "unexpected result '$result'"
+ debug 0 "unexpected result '$result' 'ds=$ds'"
ret=3
fi
return $ret