summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_power_state_change.py
diff options
context:
space:
mode:
authorHarm Weites <harm@weites.com>2013-12-06 21:25:04 +0000
committerHarm Weites <harm@weites.com>2013-12-06 21:25:04 +0000
commit53f1938a1c33b4d9e333101d1d614803373a6bc5 (patch)
tree2b5821cd905fb9034e6cb1edac6e70c7285b175b /cloudinit/config/cc_power_state_change.py
parentee9fbafae1abfd7ba3f4bece11f722519116ca81 (diff)
downloadvyos-cloud-init-53f1938a1c33b4d9e333101d1d614803373a6bc5.tar.gz
vyos-cloud-init-53f1938a1c33b4d9e333101d1d614803373a6bc5.zip
new: FreeBSD module to support cloud-init on the FBSD10 platform. In its
current form its still missing some modules though. Supported: -SSH-keys -growpart -growfs -adduser -powerstate
Diffstat (limited to 'cloudinit/config/cc_power_state_change.py')
-rw-r--r--cloudinit/config/cc_power_state_change.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index e3150808..46ce5ba5 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -23,12 +23,34 @@ import errno
import os
import re
import subprocess
+import sys
import time
frequency = PER_INSTANCE
EXIT_FAIL = 254
+#
+# Returns the cmdline for the given process id.
+#
+
+def givecmdline(pid):
+ # Check if this pid still exists by sending it the harmless 0 signal.
+ try:
+ os.kill(pid, 0)
+ except OSError:
+ return None
+ else:
+ # Example output from procstat -c 16357
+ # PID COMM ARGS
+ # 1 init /bin/init --
+ if sys.platform.startswith('freebsd'):
+ (output, _err) = util.subp(['procstat', '-c', str(pid)])
+ line = output.splitlines()[1]
+ m = re.search('\d+ (\w|\.|-)+\s+(/\w.+)', line)
+ return m.group(2)
+ else:
+ return util.load_file("/proc/%s/cmdline" % pid)
def handle(_name, cfg, _cloud, log, _args):
@@ -42,8 +64,8 @@ def handle(_name, cfg, _cloud, log, _args):
return
mypid = os.getpid()
- cmdline = util.load_file("/proc/%s/cmdline" % mypid)
+ cmdline = givecmdline(mypid)
if not cmdline:
log.warn("power_state: failed to get cmdline of current process")
return
@@ -119,8 +141,6 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args):
msg = None
end_time = time.time() + timeout
- cmdline_f = "/proc/%s/cmdline" % pid
-
def fatal(msg):
if log:
log.warn(msg)
@@ -134,16 +154,14 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args):
break
try:
- cmdline = ""
- with open(cmdline_f) as fp:
- cmdline = fp.read()
+ cmdline = givecmdline(pid)
if cmdline != pidcmdline:
msg = "cmdline changed for %s [now: %s]" % (pid, cmdline)
break
except IOError as ioerr:
if ioerr.errno in known_errnos:
- msg = "pidfile '%s' gone [%d]" % (cmdline_f, ioerr.errno)
+ msg = "pidfile gone [%d]" % ioerr.errno
else:
fatal("IOError during wait: %s" % ioerr)
break