summaryrefslogtreecommitdiff
path: root/cloudinit/distros/alpine.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/distros/alpine.py')
-rw-r--r--cloudinit/distros/alpine.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/cloudinit/distros/alpine.py b/cloudinit/distros/alpine.py
index e42443fc..ca5bfe80 100644
--- a/cloudinit/distros/alpine.py
+++ b/cloudinit/distros/alpine.py
@@ -8,7 +8,6 @@
from cloudinit import distros
from cloudinit import helpers
-from cloudinit import log as logging
from cloudinit import subp
from cloudinit import util
@@ -16,8 +15,6 @@ from cloudinit.distros.parsers.hostname import HostnameConf
from cloudinit.settings import PER_INSTANCE
-LOG = logging.getLogger(__name__)
-
NETWORK_FILE_HEADER = """\
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
@@ -162,4 +159,30 @@ class Distro(distros.Distro):
return self._preferred_ntp_clients
+ def shutdown_command(self, mode='poweroff', delay='now', message=None):
+ # called from cc_power_state_change.load_power_state
+ # Alpine has halt/poweroff/reboot, with the following specifics:
+ # - we use them rather than the generic "shutdown"
+ # - delay is given with "-d [integer]"
+ # - the integer is in seconds, cannot be "now", and takes no "+"
+ # - no message is supported (argument ignored, here)
+
+ command = [mode, "-d"]
+
+ # Convert delay from minutes to seconds, as Alpine's
+ # halt/poweroff/reboot commands take seconds rather than minutes.
+ if delay == "now":
+ # Alpine's commands do not understand "now".
+ command += ['0']
+ else:
+ try:
+ command.append(str(int(delay) * 60))
+ except ValueError as e:
+ raise TypeError(
+ "power_state[delay] must be 'now' or '+m' (minutes)."
+ " found '%s'." % (delay,)
+ ) from e
+
+ return command
+
# vi: ts=4 expandtab