
    x[h              
          % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \rS	rS
\/\S/S.r\\S'   \R2                  " \5      rS rS rS\S\S\S\SS4
S jr S r!S r"SS jr#S r$g)z&Power State Change: Change power state    N)signal_handlersubputil)Cloud)Config)
MetaSchema)ALL_DISTROS)PER_INSTANCE   cc_power_state_changepower_state)iddistros	frequencyactivate_by_schema_keysmetac                 X    [         R                  " 5       (       ag  [        R                  " SS[        U 5      /5      u  pUR	                  5       S   n[
        R                  " SU5      nU(       a  UR                  S5      $ g [         R                  " SU -  5      $ ! [         a     g f = f)Nprocstatz-c   z\d+ (\w|\.|-)+\s+(/\w.+)   z/proc/%s/cmdline)
r   
is_FreeBSDr   str
splitlinesresearchgroupload_text_fileIOError)pidoutput_errlinems        H/usr/lib/python3/dist-packages/cloudinit/config/cc_power_state_change.pygivecmdliner%   %   s     ??!YY
D#c('CDNV$$&q)D		5t<Awwqz!&&'9C'?@@ s   A?B B 
B)(B)c                    [        U [        5      (       a  [        R                  SU 5        U $ SU -  n [        R
                  " U [        U [        5      (       + S9nUR                  5         UR                  nUS:X  a  [        R                  SU5        gUS:X  a  [        R                  SU5        g	[        R                  S
X5        g	! [         a   n[        R                  SX5         S nAg	S nAff = f)NzStatic Condition: %szcheck_condition command (%s): )shellr   z%sexited 0. condition met.Tr   z%sexited 1. condition not met.Fz*%sunexpected exit %s. do not apply change.z%sUnexpected error: %s)
isinstanceboolLOGdebug
subprocessPopenlistcommunicate
returncodewarning	Exception)condpreprocretes        r$   check_conditionr8   :   s    $		($/
*T
1C
40F,FGoo!8II2C8AXII6<KKDcO ,c5s$   A C	 C	 2C	 	
C3C..C3namecfgcloudargsreturnc           
      P    [        XR                  5      u  pEnUc  [        R                  S5        g  USL a  [        R                  S5        g [        R                  " 5       n[        U5      n	U	(       d  [        R                  S5        g [        [        R                  S5      n
[        R                  SUSR                  U5      5        [        R                  " [        UU	UU[         XJ/5        g ! [         a)  n[        R                  S[        U5      5         S nAg S nAff = f)	Nz&no power_state provided. doing nothingz%%s Not performing power state change!Fz3Condition was false. Will not perform state change.z5power_state: failed to get cmdline of current processwz#After pid %s ends, will execute: %s )load_power_statedistror*   r+   r2   r1   r   osgetpidr%   opendevnulljoinr   fork_cbrun_after_pid_goneexecmd)r9   r:   r;   r<   arg_listtimeout	conditionr7   mypidcmdline
devnull_fps              r$   handlerQ   R   s    )9#||)L&III>?  E		GHIIKE% GKLbjj#&JII3UCHHX<NOLL	'  ;SVDs   0C2 2
D%<D  D%c                 \   U R                  S5      nUc  g[        U[        5      (       d  [        S5      e/ SQnUR                  S5      nXAR                  ;  a#  [        SSR                  U5      < SU< S	35      eUR                  UUR                  S
S5      UR                  S5      S9n [        UR                  SS5      5      nUR                  SS5      n[        U[        [        [        45      (       d  [        S5      eXVU4$ ! [         a  n[        SUS   -  5      UeS nAff = f)Nr   )NNNzpower_state is not a dict.)haltpoweroffrebootmodez,power_state[mode] required, must be one of: ,z
. found: 'z'.delaynowmessage)rV   rX   rZ   rL   g      >@z(failed to convert timeout '%s' to float.rM   Tz2condition type %s invalid. must be list, bool, str)getr(   dict	TypeErrorshutdown_options_maprG   shutdown_commandfloat
ValueErrorr   r.   r)   )	r:   rB   pstatemodes_okrV   r<   rL   r7   rM   s	            r$   rA   rA   v   s,    WW]#F~!fd##455-H::fD...xx!4)
 	

 ""jj%(

9% # D

9d34 

;-Ii#tT!233LMM9%%  6	9JJ
	s   .D
 

D+D&&D+c                 0    [         R                  " U 5        g N)rC   _exit)sysexits    r$   doexitrh      s    HHW    c                     Sn [         R                  " U [         R                  U[         R                  S9nUR	                  U5        UR
                  n[        U5        g ! [         a    [        [        5         N'f = f)Nr   )stdinstdoutstderr)	r,   r-   PIPESTDOUTr/   r0   r2   rh   	EXIT_FAIL)exe_argsr    data_inr6   r5   s        r$   rJ   rJ      sm    
C
//$$	
 	!oo 3K  ys   AA   A<;A<c                    S n[         R                  " 5       U-   nS n[        R                  [        R                  4n	 [         R                  " 5       U:  a  SU -  nO6 [        U 5      n
X:w  a  SU < SU
< S3nO [         R                  " S	5        MU  U(       d  U" S
5        [        R                  U5         [        U5      (       d  g  [        R                  " 5          U" U6   S S S 5        g ! [         a6  nUR                  U	;   a  SUR                  -  nOU" SU-  5         S nAM  S nAf[         a  nU" SU-  5         S nANS nAff = f! [         a  nU" SU-  5         S nANS nAff = f! , (       d  f       g = f)Nc                 L    [         R                  U 5        [        [        5        g re   )r*   r1   rh   rp   )msgs    r$   fatal!run_after_pid_gone.<locals>.fatal   s    Cyri   ztimeout reached before %s endedzcmdline changed for z [now: ]zpidfile gone [%d]zIOError during wait: %szUnexpected Exception: %sg      ?z&Unexpected error in run_after_pid_gonez0Unexpected Exception when checking condition: %s)time	monotonicerrnoENOENTESRCHr%   r   r2   sleepr*   r+   r8   r   suspend_crash)r   
pidcmdlinerL   rM   funcr<   ru   end_timerv   known_errnosrO   ioerrr7   s                r$   rI   rI      s_    C~~')H LL%++.L
>>h&3c9C	2!#&G$<?I % 	

4+ . 67IIcNFy)) * 
	%	%	'd 
(	'3  	{{l*)EKK7/%78 	2,q011	2  F@1DEEF
 
(	'sH   C/ 9E  E1/
E9+D**E7EE
E.E))E.1
E?)NN)%__doc__r{   loggingrC   r   r,   ry   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr	   cloudinit.settingsr
   r   rp   r   __annotations__	getLogger__name__r*   r%   r8   r   r.   rQ   rA   rh   rJ   rI    ri   r$   <module>r      s    -   	 	   0 0 ! # . ) +		 "} -	j  !*0! !6 !% !t ! !H#&L 2ri   