diff options
author | Scott Moser <smoser@brickies.net> | 2017-03-03 20:52:32 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-03-06 14:25:08 -0500 |
commit | 1c795b974d13ba269763bb6016ecdbcaa9c7269d (patch) | |
tree | 0db83b88bca95390b1cf166d9fa27104e677dcf5 /tools/ds-identify | |
parent | c81ea53bbdc4ada9d2b52430e106aeb3c38b4e0a (diff) | |
download | vyos-cloud-init-1c795b974d13ba269763bb6016ecdbcaa9c7269d.tar.gz vyos-cloud-init-1c795b974d13ba269763bb6016ecdbcaa9c7269d.zip |
ds-identify: report cleanups for config and exit value.
Change policy so that 'report' can be overridden.
In xenial we had set the builtin default to be 'report', expecting
that Ubuntu core would install config that changed it to 'search'.
However, if report was already set, there was no way to unset it.
The change here is to make 'report' basically 'search-dryrun', so
that one or the other can be set.
The other change here is that report would actually exit disabled
if it did not find a datasource and notfound=disabled. That was
unexpected and would turn cloud-init off, which is not what we wanted.
Additionally, consistently use 'enabled' or 'disabled' versus
'enable' and 'disable'.
LP: #1669949
Diffstat (limited to 'tools/ds-identify')
-rwxr-xr-x | tools/ds-identify | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/tools/ds-identify b/tools/ds-identify index d7b2a0b2..e138d780 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -7,20 +7,27 @@ # # policy: a string that indicates how ds-identify should operate. # kernel command line option: ci.di.policy=<policy> +# The format is: +# <mode>,found=value,maybe=value,notfound=value # default setting is: # search,found=all,maybe=all,notfound=disable # -# report: write config to /run/cloud-init/cloud.cfg, but -# namespaced under 'di_report'. Thus cloud-init can still see -# the result, but has no affect. -# enable: do nothing -# ds-identify writes no config and just exits success -# the caller (cloud-init-generator) then enables cloud-init to run -# just without any aid from ds-identify. -# disable: disable cloud-init +# Mode: +# disabled: disable cloud-init +# enabled: enable cloud-init. +# ds-identify writes no config and just exits success. +# the caller (cloud-init-generator) then enables cloud-init to +# run just without any aid from ds-identify. +# search: determine which source or sources should be used +# and write the result (datasource_list) to +# /run/cloud-init/cloud.cfg +# report: basically 'dry run' for search. results are still written +# to the file, but are namespaced under the top level key +# 'di_report' Thus cloud-init is not affected, but can still +# see the result. # -# [report,]found=value,maybe=value,notfound=value -# found: (default=first) +# found,maybe,notfound: +# found: (default=all) # first: use the first found do no further checking # all: enable all DS_FOUND # @@ -104,7 +111,6 @@ DI_DSLIST_DEFAULT="MAAS ConfigDrive NoCloud AltCloud Azure Bigstep \ CloudSigma CloudStack DigitalOcean Ec2 OpenNebula OpenStack OVF SmartOS" DI_DSLIST="" DI_MODE="" -DI_REPORT="" DI_ON_FOUND="" DI_ON_MAYBE="" DI_ON_NOTFOUND="" @@ -859,7 +865,7 @@ _print_info() { vars="$vars UNAME_KERNEL_NAME UNAME_KERNEL_RELEASE UNAME_KERNEL_VERSION" vars="$vars UNAME_MACHINE UNAME_NODENAME UNAME_OPERATING_SYSTEM" vars="$vars DSNAME DSLIST" - vars="$vars MODE REPORT ON_FOUND ON_MAYBE ON_NOTFOUND" + vars="$vars MODE ON_FOUND ON_MAYBE ON_NOTFOUND" for v in ${vars}; do eval n='${DI_'"$v"'}' echo "$v=$n" @@ -871,7 +877,7 @@ _print_info() { write_result() { local runcfg="${PATH_RUN_CI_CFG}" ret="" line="" pre="" { - if [ "$DI_REPORT" = "true" ]; then + if [ "$DI_MODE" = "report" ]; then echo "di_report:" pre=" " fi @@ -892,11 +898,11 @@ record_notfound() { # if not report mode: only report the negative result. # reporting an empty list would mean cloud-init would not search # any datasources. - if [ "$DI_REPORT" = "true" ]; then + if [ "$DI_MODE" = "report" ]; then found -- - else + elif [ "$DI_MODE" = "search" ]; then local msg="# reporting not found result. notfound=${DI_ON_NOTFOUND}." - local DI_REPORT="true" + local DI_MODE="report" found -- "$msg" fi } @@ -998,11 +1004,11 @@ parse_def_policy() { parse_policy() { # parse_policy(policy, default) # parse a policy string. sets - # _rc_mode (enable|disable,search) + # _rc_mode (enabled|disabled|search|report) # _rc_report true|false # _rc_found first|all # _rc_maybe all|none - # _rc_notfound enable|disable + # _rc_notfound enabled|disabled local def="" case "$DI_UNAME_MACHINE" in # these have dmi data @@ -1025,8 +1031,7 @@ parse_policy() { for tok in "$@"; do val=${tok#*=} case "$tok" in - report) report=true;; - $DI_ENABLED|$DI_DISABLED|search) mode=$tok;; + $DI_ENABLED|$DI_DISABLED|search|report) mode=$tok;; found=all|found=first) found=$val;; maybe=all|maybe=none) maybe=$val;; notfound=$DI_ENABLED|notfound=$DI_DISABLED) notfound=$val;; @@ -1075,7 +1080,6 @@ read_config() { debug 1 "policy loaded: mode=${_rc_mode} report=${_rc_report}" \ "found=${_rc_found} maybe=${_rc_maybe} notfound=${_rc_notfound}" DI_MODE=${_rc_mode} - DI_REPORT=${_rc_report} DI_ON_FOUND=${_rc_found} DI_ON_MAYBE=${_rc_maybe} DI_ON_NOTFOUND=${_rc_notfound} @@ -1118,7 +1122,7 @@ _main() { $DI_ENABLED) debug 1 "mode=$DI_ENABLED. returning $ret_en" return $ret_en;; - search) :;; + search|report) :;; esac if [ -n "${DI_DSNAME}" ]; then @@ -1191,18 +1195,26 @@ _main() { # record the empty result. record_notfound - case "$DI_ON_NOTFOUND" in - $DI_DISABLED) - debug 1 "No result. notfound=$DI_DISABLED. returning $ret_dis." - return $ret_dis - ;; - $DI_ENABLED) - debug 1 "No result. notfound=$DI_ENABLED. returning $ret_en" - return $ret_en;; - esac - error "Unexpected result" - return 3 + local basemsg="No ds found [mode=$DI_MODE, notfound=$DI_ON_NOTFOUND]." + local msg="" ret=3 + case "$DI_MODE:$DI_ON_NOTFOUND" in + report:$DI_DISABLED) + msg="$basemsg Would disable cloud-init [$ret_dis]" + ret=$ret_en;; + report:$DI_ENABLED) + msg="$basemsg Would enable cloud-init [$ret_en]" + ret=$ret_en;; + search:$DI_DISABLED) + msg="$basemsg Disabled cloud-init [$ret_dis]" + ret=$ret_dis;; + search:$DI_ENABLED) + msg="$basemsg Enabled cloud-init [$ret_en]" + ret=$ret_en;; + *) error "Unexpected result";; + esac + debug 1 "$msg" + return $ret } main() { |