From b3b8de6f9cc81dd51a82cacff04fdbc53632eaa5 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 9 Oct 2013 10:03:03 -0400 Subject: [PATCH] power_state_change: convert an int input for delay to string, improve doc this adds 'timeout' to the documentation for power_state_change, and supports delay being an integer or a string. This is so that yaml can contain: delay: 30 rather than delay: "+30" or dealy: "30" --- cloudinit/config/cc_power_state_change.py | 6 ++++++ doc/examples/cloud-config-power-state.txt | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py index 188047e5..e3150808 100644 --- a/cloudinit/config/cc_power_state_change.py +++ b/cloudinit/config/cc_power_state_change.py @@ -75,6 +75,12 @@ def load_power_state(cfg): ','.join(opt_map.keys())) delay = pstate.get("delay", "now") + # convert integer 30 or string '30' to '+30' + try: + delay = "+%s" % int(delay) + except ValueError: + pass + if delay != "now" and not re.match(r"\+[0-9]+", delay): raise TypeError("power_state[delay] must be 'now' or '+m' (minutes).") diff --git a/doc/examples/cloud-config-power-state.txt b/doc/examples/cloud-config-power-state.txt index 59f062d0..8df14366 100644 --- a/doc/examples/cloud-config-power-state.txt +++ b/doc/examples/cloud-config-power-state.txt @@ -12,11 +12,20 @@ # that may go to the console as a result of system services like # syslog being taken down while cloud-init is running. # +# If you delay '+5' (5 minutes) and have a timeout of +# 120 (2 minutes), then the max time until shutdown will be 7 minutes. +# cloud-init will invoke 'shutdown +5' after the process finishes, or +# when 'timeout' seconds have elapsed. +# # delay: form accepted by shutdown. default is 'now'. other format # accepted is +m (m in minutes) # mode: required. must be one of 'poweroff', 'halt', 'reboot' # message: provided as the message argument to 'shutdown'. default is none. +# timeout: the amount of time to give the cloud-init process to finish +# before executing shutdown. +# power_state: - delay: 30 + delay: "+30" mode: poweroff message: Bye Bye + timeout: 30