/usr/lib/python2.6/site-packages/cloudinit/config
NameSizeModeActions
cc_apt_configure.py96000644editdlrm
cc_apt_configure.pyc90130644editdlrm
cc_apt_configure.pyo90130644editdlrm
cc_apt_pipelining.py21110644editdlrm
cc_apt_pipelining.pyc16430644editdlrm
cc_apt_pipelining.pyo16430644editdlrm
cc_bootcmd.py17820644editdlrm
cc_bootcmd.pyc12950644editdlrm
cc_bootcmd.pyo12950644editdlrm
cc_byobu.py28860644editdlrm
cc_byobu.pyc21850644editdlrm
cc_byobu.pyo21850644editdlrm
cc_ca_certs.py38720644editdlrm
cc_ca_certs.pyc33960644editdlrm
cc_ca_certs.pyo33960644editdlrm
cc_chef.py57180644editdlrm
cc_chef.pyc40270644editdlrm
cc_chef.pyo40270644editdlrm
cc_debug.py28690644editdlrm
cc_debug.pyc24440644editdlrm
cc_debug.pyo24440644editdlrm
cc_disable_ec2_metadata.py13120644editdlrm
cc_disable_ec2_metadata.pyc8730644editdlrm
cc_disable_ec2_metadata.pyo8730644editdlrm
cc_disk_setup.py252740644editdlrm
cc_disk_setup.pyc225600644editdlrm
cc_disk_setup.pyo225600644editdlrm
cc_emit_upstart.py17070644editdlrm
cc_emit_upstart.pyc11430644editdlrm
cc_emit_upstart.pyo11430644editdlrm
cc_final_message.py23480644editdlrm
cc_final_message.pyc18600644editdlrm
cc_final_message.pyo18600644editdlrm
cc_foo.py24530644editdlrm
cc_foo.pyc4880644editdlrm
cc_foo.pyo4880644editdlrm
cc_growpart.py96020644editdlrm
cc_growpart.pyc89280644editdlrm
cc_growpart.pyo89280644editdlrm
cc_grub_dpkg.py23440644editdlrm
cc_grub_dpkg.pyc15430644editdlrm
cc_grub_dpkg.pyo15430644editdlrm
cc_keys_to_console.py19430644editdlrm
cc_keys_to_console.pyc13000644editdlrm
cc_keys_to_console.pyo13000644editdlrm
cc_landscape.py29910644editdlrm
cc_landscape.pyc24760644editdlrm
cc_landscape.pyo24760644editdlrm
cc_locale.py13580644editdlrm
cc_locale.pyc8010644editdlrm
cc_locale.pyo8010644editdlrm
cc_mcollective.py37600644editdlrm
cc_mcollective.pyc18400644editdlrm
cc_mcollective.pyo18400644editdlrm
cc_migrator.py31190644editdlrm
cc_migrator.pyc27490644editdlrm
cc_migrator.pyo27490644editdlrm
cc_mounts.py84830644editdlrm
cc_mounts.pyc61530644editdlrm
cc_mounts.pyo61530644editdlrm
cc_package_update_upgrade_install.py35230644editdlrm
cc_package_update_upgrade_install.pyc29370644editdlrm
cc_package_update_upgrade_install.pyo29370644editdlrm
cc_phone_home.py36660644editdlrm
cc_phone_home.pyc24790644editdlrm
cc_phone_home.pyo24790644editdlrm
cc_power_state_change.py51210644editdlrm
cc_power_state_change.pyc49340644editdlrm
cc_power_state_change.pyo49340644editdlrm
cc_puppet.py51660644editdlrm
cc_puppet.pyc30550644editdlrm
cc_puppet.pyo30550644editdlrm
cc_resizefs.py56970644editdlrm
cc_resizefs.pyc47680644editdlrm
cc_resizefs.pyo47680644editdlrm
cc_resolv_conf.py36810644editdlrm
cc_resolv_conf.pyc22130644editdlrm
cc_resolv_conf.pyo22130644editdlrm
cc_rightscale_userdata.py35750644editdlrm
cc_rightscale_userdata.pyc20740644editdlrm
cc_rightscale_userdata.pyo20740644editdlrm
cc_rsyslog.py34120644editdlrm
cc_rsyslog.pyc18480644editdlrm
cc_rsyslog.pyo18480644editdlrm
cc_runcmd.py13480644editdlrm
cc_runcmd.pyc8420644editdlrm
cc_runcmd.pyo8420644editdlrm
cc_salt_minion.py23150644editdlrm
cc_salt_minion.pyc14130644editdlrm
cc_salt_minion.pyo14130644editdlrm
cc_scripts_per_boot.py13690644editdlrm
cc_scripts_per_boot.pyc8060644editdlrm
cc_scripts_per_boot.pyo8060644editdlrm
cc_scripts_per_instance.py13770644editdlrm
cc_scripts_per_instance.pyc8200644editdlrm
cc_scripts_per_instance.pyo8200644editdlrm
cc_scripts_per_once.py13650644editdlrm
cc_scripts_per_once.pyc8040644editdlrm
cc_scripts_per_once.pyo8040644editdlrm
cc_scripts_user.py13880644editdlrm
cc_scripts_user.pyc7880644editdlrm
cc_scripts_user.pyo7880644editdlrm
cc_scripts_vendor.py13980644editdlrm
cc_scripts_vendor.pyc9240644editdlrm
cc_scripts_vendor.pyo9240644editdlrm
cc_seed_random.py31610644editdlrm
cc_seed_random.pyc27670644editdlrm
cc_seed_random.pyo27670644editdlrm
cc_set_hostname.py14600644editdlrm
cc_set_hostname.pyc9320644editdlrm
cc_set_hostname.pyo9320644editdlrm
cc_set_passwords.py55550644editdlrm
cc_set_passwords.pyc40100644editdlrm
cc_set_passwords.pyo40100644editdlrm
cc_ssh.py52250644editdlrm
cc_ssh.pyc41040644editdlrm
cc_ssh.pyo41040644editdlrm
cc_ssh_authkey_fingerprints.py36480644editdlrm
cc_ssh_authkey_fingerprints.pyc35070644editdlrm
cc_ssh_authkey_fingerprints.pyo35070644editdlrm
cc_ssh_import_id.py30390644editdlrm
cc_ssh_import_id.pyc21910644editdlrm
cc_ssh_import_id.pyo21910644editdlrm
cc_timezone.py13160644editdlrm
cc_timezone.pyc7690644editdlrm
cc_timezone.pyo7690644editdlrm
cc_update_etc_hosts.py23910644editdlrm
cc_update_etc_hosts.pyc15090644editdlrm
cc_update_etc_hosts.pyo15090644editdlrm
cc_update_hostname.py16270644editdlrm
cc_update_hostname.pyc11660644editdlrm
cc_update_hostname.pyo11660644editdlrm
cc_users_groups.py12650644editdlrm
cc_users_groups.pyc7920644editdlrm
cc_users_groups.pyo7920644editdlrm
cc_write_files.py35540644editdlrm
cc_write_files.pyc32310644editdlrm
cc_write_files.pyo32310644editdlrm
cc_yum_add_repo.py39440644editdlrm
cc_yum_add_repo.pyc30260644editdlrm
cc_yum_add_repo.pyo30260644editdlrm
__init__.py19700644editdlrm
__init__.pyc13490644editdlrm
__init__.pyo13490644editdlrm
Edit: /usr/lib/python2.6/site-packages/cloudinit/config/cc_power_state_change.py (5121B)
# vi: ts=4 expandtab # # Copyright (C) 2011 Canonical Ltd. # # Author: Scott Moser # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . from cloudinit.settings import PER_INSTANCE from cloudinit import util import errno import os import re import subprocess import time frequency = PER_INSTANCE EXIT_FAIL = 254 def givecmdline(pid): # Returns the cmdline for the given process id. In Linux we can use procfs # for this but on BSD there is /usr/bin/procstat. try: # Example output from procstat -c 1 # PID COMM ARGS # 1 init /bin/init -- if util.system_info()["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) except IOError: return None def handle(_name, cfg, _cloud, log, _args): try: (args, timeout) = load_power_state(cfg) if args is None: log.debug("no power_state provided. doing nothing") return except Exception as e: log.warn("%s Not performing power state change!" % str(e)) return mypid = os.getpid() cmdline = givecmdline(mypid) if not cmdline: log.warn("power_state: failed to get cmdline of current process") return devnull_fp = open(os.devnull, "w") log.debug("After pid %s ends, will execute: %s" % (mypid, ' '.join(args))) util.fork_cb(run_after_pid_gone, mypid, cmdline, timeout, log, execmd, [args, devnull_fp]) def load_power_state(cfg): # returns a tuple of shutdown_command, timeout # shutdown_command is None if no config found pstate = cfg.get('power_state') if pstate is None: return (None, None) if not isinstance(pstate, dict): raise TypeError("power_state is not a dict.") opt_map = {'halt': '-H', 'poweroff': '-P', 'reboot': '-r'} mode = pstate.get("mode") if mode not in opt_map: raise TypeError("power_state[mode] required, must be one of: %s." % ','.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).") args = ["shutdown", opt_map[mode], delay] if pstate.get("message"): args.append(pstate.get("message")) try: timeout = float(pstate.get('timeout', 30.0)) except ValueError: raise ValueError("failed to convert timeout '%s' to float." % pstate['timeout']) return (args, timeout) def doexit(sysexit): os._exit(sysexit) # pylint: disable=W0212 def execmd(exe_args, output=None, data_in=None): try: proc = subprocess.Popen(exe_args, stdin=subprocess.PIPE, stdout=output, stderr=subprocess.STDOUT) proc.communicate(data_in) ret = proc.returncode # pylint: disable=E1101 except Exception: doexit(EXIT_FAIL) doexit(ret) def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args): # wait until pid, with /proc/pid/cmdline contents of pidcmdline # is no longer alive. After it is gone, or timeout has passed # execute func(args) msg = None end_time = time.time() + timeout def fatal(msg): if log: log.warn(msg) doexit(EXIT_FAIL) known_errnos = (errno.ENOENT, errno.ESRCH) while True: if time.time() > end_time: msg = "timeout reached before %s ended" % pid break try: 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 gone [%d]" % ioerr.errno else: fatal("IOError during wait: %s" % ioerr) break except Exception as e: fatal("Unexpected Exception: %s" % e) time.sleep(.25) if not msg: fatal("Unexpected error in run_after_pid_gone") if log: log.debug(msg) func(*args)