Current File : //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&