Viewing File: /usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyc

ó
oBú]c@sÆdZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
eZdZd„Z
dd„Zd„Zd	„Zd
„Zddd„Zd„ZdS(
sù
Power State Change
------------------
**Summary:** change power state

This module handles shutdown/reboot after all config modules have been run. By
default it will take no action, and the system will keep running unless a
package installation/upgrade requires a system reboot (e.g. installing a new
kernel) and ``package_reboot_if_required`` is true. The ``power_state`` config
key accepts a dict of options. If ``mode`` is any value other than
``poweroff``, ``halt``, or ``reboot``, then no action will be taken.

The system
can be shutdown before cloud-init has finished using the ``timeout`` option.
The ``delay`` key specifies a duration to be added onto any shutdown command
used. Therefore, if a 5 minute delay and a 120 second shutdown are specified,
the maximum amount of time between cloud-init starting and the system shutting
down is 7 minutes, and the minimum amount of time is 5 minutes. The ``delay``
key must have an argument in a form that the ``shutdown`` utility recognizes.
The most common format is the form ``+5`` for 5 minutes. See ``man shutdown``
for more options.

Optionally, a command can be run to determine whether or not
the system should shut down. The command to be run should be specified in the
``condition`` key. For command formatting, see the documentation for
``cc_runcmd``. The specified shutdown behavior will only take place if the
``condition`` key is omitted or the command specified by the ``condition``
key returns 0.

**Internal name:** ``cc_power_state_change``

**Module frequency:** per instance

**Supported distros:** all

**Config keys**::

    power_state:
        delay: <now/'+minutes'>
        mode: <poweroff/halt/reboot>
        message: <shutdown message>
        timeout: <seconds>
        condition: <true/false/command>
iÿÿÿÿ(tPER_INSTANCE(tutilNiþcCsyttjƒrbtjddt|ƒgƒ\}}|jƒd}tjd|ƒ}|jdƒStjd|ƒSWnt	k
rˆdSXdS(Ntprocstats-cis\d+ (\w|\.|-)+\s+(/\w.+)is/proc/%s/cmdline(Rt
is_FreeBSDtsubptstrt
splitlinestretsearchtgroupt	load_filetIOErrortNone(tpidtoutputt_errtlinetm((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pytgivecmdlineCs$

cCs t|tƒr-|r)|jd|ƒn|Sd|}y°tj|dt|tƒƒ}|jƒ|j}|dkr–|r’|j|dƒntS|dkrÀ|r¼|j|dƒnt	S|râ|j
|d|d	ƒnt	SWn2tk
r}|r|j
|d
|ƒnt	SXdS(NsStatic Condition: %sscheck_condition command (%s): tshellisexited 0. condition met.isexited 1. condition not met.sunexpected exit %s. sdo not apply change.sUnexpected error: %s(t
isinstancetbooltdebugt
subprocesstPopentlisttcommunicatet
returncodetTruetFalsetwarningt	Exception(tcondtlogtpretproctrette((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pytcheck_conditionUs2

	c
Csy6t|ƒ\}}}|dkr5|jdƒdSWn+tk
rc}|jdt|ƒƒdSX|tkr|jdƒdStjƒ}	t	|	ƒ}
|
s°|jdƒdSt
tjdƒ}|jd|	dj|ƒfƒt
jt|	|
|||t||gƒdS(Ns&no power_state provided. doing nothings%%s Not performing power state change!s3Condition was false. Will not perform state change.s5power_state: failed to get cmdline of current processtws#After pid %s ends, will execute: %st (tload_power_stateRRRRRRtostgetpidRtopentdevnulltjoinRtfork_cbtrun_after_pid_gonetexecmd(t_nametcfgt_cloudR!t_argstargsttimeoutt	conditionR%tmypidtcmdlinet
devnull_fp((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pythandless(


 cCsÐ|jdƒ}|dkrdSt|tƒs=tdƒ‚nidd6dd6dd6}|jd	ƒ}||kr›td
dj|jƒƒ|fƒ‚n|jdd
ƒ}ydt|ƒ}Wntk
rÔnX|d
krt	j
d|ƒrtd|ƒ‚nd|||g}|jdƒrB|j|jdƒƒnyt|jddƒƒ}Wn%tk
r…td|dƒ‚nX|jdt
ƒ}t|tjttfƒsÃtdƒ‚n|||fS(Ntpower_statespower_state is not a dict.s-Hthalts-Ptpoweroffs-rtreboottmodes<power_state[mode] required, must be one of: %s. found: '%s'.t,tdelaytnows+%ss\+[0-9]+s?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.tshutdowntmessageR7g>@s(failed to convert timeout '%s' to float.R8s2condition type %s invalid. must be list, bool, str(NNN(tgetRRtdictt	TypeErrorR.tkeystintt
ValueErrorRtmatchtappendtfloatRtsixtstring_typesRR(R3tpstatetopt_mapRARCR6R7R8((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyR)s@"


cCstj|ƒdS(N(R*t_exit(tsysexit((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pytdoexit¿scCssd}yAtj|dtjd|dtjƒ}|j|ƒ|j}Wntk
rdttƒnXt|ƒdS(Nitstdintstdouttstderr(	RRtPIPEtSTDOUTRRRRVt	EXIT_FAIL(texe_argsRtdata_inR$R#((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyR1Ãs


cswd}tjƒ|}‡fd†}	tjtjf}
xËtrtjƒ|kr`d|}Pny0t|ƒ}||krd||f}PnWnatk
rÓ}|j|
krÁd|j}n|	d|ƒPn!tk
ró}
|	d|
ƒnXtj	dƒq:W|s|	dƒnˆr.ˆj
|ƒnyt|ˆƒsDdSWn!tk
rh}
|	d	|
ƒnX||ŒdS(
Ncs$ˆrˆj|ƒnttƒdS(N(RRVR\(tmsg(R!(sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pytfatalÖsstimeout reached before %s endeds cmdline changed for %s [now: %s]spidfile gone [%d]sIOError during wait: %ssUnexpected Exception: %sgÐ?s&Unexpected error in run_after_pid_gones0Unexpected Exception when checking condition: %s(RttimeterrnotENOENTtESRCHRRRRtsleepRR&(R
t
pidcmdlineR7R!R8tfuncR6R_tend_timeR`tknown_errnosR:tioerrR%((R!sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyR0Ïs>	

(t__doc__tcloudinit.settingsRt	cloudinitRRbR*RRPRRat	frequencyR\RRR&R<R)RVR1R0(((sJ/usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyt<module>2s"			/	
Back to Directory File Manager