Viewing File: /usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyo
ó
oBú]c @ sÆ d Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l
Z
e Z d Z d „ Z
d d „ Z d „ Z d „ Z d
„ Z d d d „ Z d „ Z d S(
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( t utilNiþ c C s yt t j ƒ rb t j d d t | ƒ g ƒ \ } } | j ƒ d } t j d | ƒ } | j d ƒ St j d | ƒ SWn t k
rˆ d SXd S( Nt procstats -ci s \d+ (\w|\.|-)+\s+(/\w.+)i s /proc/%s/cmdline( R t
is_FreeBSDt subpt strt
splitlinest ret searcht groupt load_filet IOErrort None( t pidt outputt _errt linet m( ( sJ /usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyt givecmdlineC s $
c C s t | t ƒ r- | r) | j d | ƒ n | Sd | } y° t j | d t | t ƒ ƒ} | j ƒ | j } | d k r– | r’ | j | d ƒ n t S| d k rÀ | r¼ | j | d ƒ n t S| râ | j
| d | d ƒ n t SWn2 t k
r} | r| j
| d
| ƒ n t SXd S( Ns Static Condition: %ss check_condition command (%s): t shelli s exited 0. condition met.i s exited 1. condition not met.s unexpected exit %s. s do not apply change.s Unexpected error: %s( t
isinstancet boolt debugt
subprocesst Popent listt communicatet
returncodet Truet Falset warningt Exception( t condt logt pret proct rett e( ( sJ /usr/lib/python2.7/site-packages/cloudinit/config/cc_power_state_change.pyt check_conditionU s2
c
C s y6 t | ƒ \ } } } | d k r5 | j d ƒ d SWn+ t k
rc } | j d t | ƒ ƒ d SX| t k r | j d ƒ d St j ƒ } t | ƒ }
|
s° | j d ƒ d St
t j d ƒ } | j d | d j | ƒ f ƒ t
j t | |
| | | t | | g ƒ d S( Ns&