
    x[hAF                     P   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Jr  SSKJ	r	J
r
Jr  SSKJrJrJrJrJrJr  SSKJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJr  Sr \RB                   " S S\RD                  5      5       r#\RB                   " S S\RD                  5      5       r$\RB                   " S S\RD                  5      5       r%\&" \%RN                  \%RP                  \%RR                  \%RT                  /5      r+ " S S\5      r,Sr-S\\.   S\/S\.4S jr0S.S jr1S\#S\$S\\.\.4   4S jr2S\,4S jr3S\44S jr5S\/4S  jr6S\\%\.4   4S! jr7S\/4S" jr8S\/S\/4S# jr9S\/4S$ jr:S\#4S% jr;S\.4S& jr<S' r=S( r>S\\\4   4S) jr? S/S*\\   S\/S\,4S+ jjr@S, rA\BS-:X  a  \A" 5         gg)0zGDefine 'status' utility and handler as part of cloud-init command line.    N)deepcopy)gmtimesleepstrftime)AnyDictList
NamedTupleOptionalTuple)safeyamlsubp)read_cfg_paths)uses_systemd)Paths)get_cmdline	load_jsonload_text_filez/etc/cloud/cloud-init.disabledc                   (    \ rS rSrSrSrSrSrSrSr	g)	RunningStatus   z=Enum representing user-visible cloud-init application status.znot startedrunningdonedisabled N)
__name__
__module____qualname____firstlineno____doc__NOT_STARTEDRUNNINGDONEDISABLED__static_attributes__r       6/usr/lib/python3/dist-packages/cloudinit/cmd/status.pyr   r      s    GKGDHr&   r   c                   $    \ rS rSrSrSrSrSrSrg)ConditionStatus%   z;Enum representing user-visible cloud-init condition status.errordegradedhealthyr   N)	r   r   r   r   r    ERRORDEGRADEDPEACHYr%   r   r&   r'   r)   r)   %   s    EEHFr&   r)   c                   8    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrg)EnabledStatus.   z<Enum representing user-visible cloud-init boot status codes.zdisabled-by-generatorzdisabled-by-kernel-command-linezdisabled-by-marker-filez disabled-by-environment-variablezenabled-by-generatorzenabled-by-kernel-command-linezenabled-by-sysvinitunknownr   N)r   r   r   r   r    DISABLED_BY_GENERATORDISABLED_BY_KERNEL_CMDLINEDISABLED_BY_MARKER_FILEDISABLED_BY_ENV_VARIABLEENABLED_BY_GENERATORENABLED_BY_KERNEL_CMDLINEENABLED_BY_SYSVINITUNKNOWNr%   r   r&   r'   r2   r2   .   s4    F3!B7A1 @/Gr&   r2   c                       \ rS rSr% \\S'   \\S'   \\S'   \\S'   \	\   \S'   \
\\	\   4   \S'   \\S'   \\   \S	'   \
\\4   \S
'   Srg)StatusDetailsF   running_statuscondition_statusboot_status_codedescriptionerrorsrecoverable_errorslast_update
datasourcev1r   N)r   r   r   r   r   __annotations__r)   r2   strr	   r   r   r   r%   r   r&   r'   r>   r>   F   sU    !!%%##IS$s)^,,S#Xr&   r>   zextended_status: {extended_status}
boot_status_code: {boot_code}
{last_update}detail: {description}
errors:{errors}
recoverable_errors:{recoverable_errors}systemctl_argswaitreturnc                      [         R                   " S/U Q5      R                  R                  5       $ ! [         R                   a    U(       d  e [	        S5         Of = fMa  )z-Query systemd with retries and return output.	systemctl      ?)r   stdoutstripProcessExecutionErrorr   )rK   rL   s     r'   query_systemctlrT   Z   sY     	99k;N;<CCIIKK)) 	$K	 s   04 'AAc                     U (       d  [         R                  " SSS9n U R                  S[        / SQSSS9  U R                  S	S
SSSS9  U R                  SSSSSS9  U $ )a  Build or extend an arg parser for status utility.

@param parser: Optional existing ArgumentParser instance representing the
    status subcommand which will be extended to support the args of
    this utility.

@returns: ArgumentParser with proper argument configuration.
statuszReport run status of cloud init)progrC   z--format)jsontabularyamlrY   z5Specify output format for cloud-id (default: tabular))typechoicesdefaulthelpz-lz--long
store_trueFzJReport long format of statuses including run stage name and error messages)actionr]   r^   z-wz--waitz'Block waiting on cloud-init to complete)argparseArgumentParseradd_argumentrJ   parsers    r'   
get_parserrf   i   s     (('H
 +D     	 6   Mr&   r   	conditionc                 R   U[         R                  :X  a  SUR                   SU R                   34$ U[         R                  :X  aK  U [        R
                  [        R                  4;   a'  U R                  UR                   SU R                   34$ U R                  U R                  4$ )zTranslate running and condition status to human readable strings.

Returns (status, extended_status).
Much of this is for backwards compatibility
r+   z -  )r)   r.   valuer/   r   r#   r"   )r   rg   s     r'   translate_statusrk      s     O)))9??+3w}}o>>>	o..	.7? 4 }} 17==/BBB=='--''r&   detailsc                 ,   [        UR                  UR                  5      u  p#UR                  UR                  R
                  UUUR                  UR                  UR                  UR                  S.UR                  EnU R                  S:X  Ga  SnUS   n[        U SU 35        U R                  (       a  UR                  S5      (       a
  SUS    S3nOSnUS	   (       a  S
S
R                  US	   5      -   OSnUS   (       aq  SSR                  US   R!                  5        V	V
Vs/ s H<  u  pU	 S3S
R                  U
 Vs/ s H  oR#                  SS5      PM     sn5      -   PM>     snn
n	5      -   OSn[        [$        R                  US   UUS   US   UUUS95        ggU R                  S:X  a!  [        [&        R(                  " USSSS95        gU R                  S:X  a   [        [*        R(                  " U5      5        ggs  snf s  snn
n	f )zPrint status out to the CLI.)rG   rB   rV   extended_statusdetailrD   rE   rF   rY    rV   zstatus: rF   zlast_update: 
rD   z
	- z []rE   z:
	- ri   z {}rn   rB   ro   )rn   prefix	boot_coderC   rF   rD   rE   rX      T),z: )indent	sort_keys
separatorsrZ   N)rk   r@   rA   rG   rB   rj   rC   rD   rE   rF   rH   formatprintlonggetjoinitemsreplaceTABULAR_LONG_TMPLrX   dumpsr   )argsrl   rV   rn   details_dictrr   staterF   errors_outputkvirecoverable_errors_outputs                r'   print_statusr      s3   . 8 8F ((#44::*%%..%88**
$ **
$L {{i X&()99.. -l=.I-J"M   ) 8==h)?@@    45 )) %11E$F$L$L$N %ODA #W"--q(Iq!4)=q(IJK$N  & !(($01B$C!*+=> ,X 6 +('@ ) 
- B 
	JJQ$;	

 
	hnn\*+ 
1 )Js   +HH
!H
Hc                    [        5       n[        X!R                  5      nUR                  (       a  UR                  [        R
                  [        R                  4;   a  UR                  S:X  a=  [        R                  R                  S5        [        R                  R                  5         [        X!R                  5      n[        S5        UR                  [        R
                  [        R                  4;   a  M  [        X5        UR                  [        R                   :X  a  gUR                  [        R"                  :X  a  gg)z4Handle calls to 'cloud-init status' as a subcommand.rY   .rP      rt   r   )r   get_status_detailsrL   r@   r   r!   r"   ry   sysrQ   writeflushr   r   rA   r)   r.   r/   )namer   pathsrl   s       r'   handle_status_argsr      s     E 		2Gyy$$%%!!)
 
 {{i'

  %

  "(		:G$K $$%%!!)
 
  ?#8#88		!	!_%=%=	=r&   c                 d     [        S/U S9nSU;   $ ! [        R                   a	    Sn SU;   $ f = f)z?Return whether cloud-init is disabled via environment variable.zshow-environmentrL   rp   cloud-init=disabled)rT   r   rS   )rL   envs     r'   _disabled_via_environmentr     sK    12> !C'' %%  C''s    //c                    [        5       R                  5       n[        5       (       d  [        R                  nSnXE4$ SU;   a  [        R
                  nSnXE4$ [        R                  R                  U 5      (       a$  [        R                  nSR                  U 5      nXE4$ SU;   a  [        R                  nSnXE4$ S[        R                  R                  SS5      ;   d  [        5       (       a#  [        US	9(       a  [        R                  nS
nXE4$ [        R                  R                  [        R                  R!                  UR"                  S5      5      (       a  [        R$                  nSnXE4$ [        R                  R                  [        R                  R!                  UR"                  S5      5      (       a  [        R&                  nSnXE4$ [        R(                  nSnXE4$ )a@  Report whether cloud-init current boot status

@param disable_file: The path to the cloud-init disable file.
@param paths: An initialized cloudinit.helpers.Paths object.
@param wait: If user has indicated to wait for cloud-init to complete.
@returns: A tuple containing (code, reason) about cloud-init's status and
why.
zCloud-init enabled on sysvinitzcloud-init=enabledz<Cloud-init enabled by kernel command line cloud-init=enabledzCloud-init disabled by {0}r   z;Cloud-init disabled by kernel parameter cloud-init=disabledKERNEL_CMDLINErp   r   zNCloud-init disabled by environment variable KERNEL_CMDLINE=cloud-init=disabledr   z+Cloud-init disabled by cloud-init-generatorenabledz2Cloud-init enabled by systemd cloud-init-generatorz'Systemd generator may not have run yet.)r   splitr   r2   r;   r:   ospathexistsr7   ry   r6   environr|   r   r8   r}   run_dirr5   r9   r<   )disable_filer   rL   cmdline_partsbootstatus_codereasons         r'   get_bootstatusr     s     M'')M>>';;16 $$5 
	.'AAO0 $$/ 
	%	%'??-44\B* $$) 
-	/'BBN$ $$# 
"**..1A2"F	F4$?'@@1 	 $$ 
U]]J?	@	@'==> $$ 
U]]I>	?	?'<<E $$ (//:$$r&   c                  J    [        [        5       5      R                  [        ;  $ N)r   r   rB   DISABLED_BOOT_CODESr   r&   r'   is_cloud_init_enabledr   5  s     >+,=="	#r&   c                 J   S H  n [        SSU/U S9n[        UR                  5        VVs/ s H1  oDR                  S	5       Vs/ s H  oUR                  5       PM     snPM3     snn5      nUS
   R                  S5      (       d  US
   S:X  d    gUS   S:X  a!  US   S:X  a  M  US   S:X  a  US   S:X  a    g  gUS   S:X  d	  US   S:X  a    g  g   g! [        R                   a0  n[        SUR                   3[
        R                  S9   SnA  gSnAff = fs  snf s  snnf )z2Return if systemd units report a cloud-init error.)zcloud-final.servicezcloud-config.servicezcloud-init-network.servicezcloud-init-local.servicezcloud-init-main.serviceshowz5--property=ActiveState,UnitFileState,SubState,MainPIDr   z^Failed to get status from systemd. Cloud-init status may be inaccurate. Error from systemctl: )fileNF=UnitFileStater   staticTActiveStateactiveSubStateexitedr   MainPID0failed)rT   r   rS   rz   stderrr   dict
splitlinesr   rR   
startswith)rL   servicerQ   erxstatess          r'   systemd_failedr   <  sO   	$K
 F" 8>8I8I8KL8K1.Aggi.8KL
 ?#..y99o&(2 M"h.j!X-
#y0VI5F#5M   =!X-
1Cx1O gl M )) 	))*
4 ZZ	 	 /Ls.   CDDDD'%DDDc                     [         R                  R                  U 5      =(       a$    [         R                  R                  U5      (       + $ )z%Return True if cloud-init is running.)r   r   r   )status_fileresult_files     r'   
is_runningr   w  s*    77>>+&Jrww~~k/J+JJr&   c                     U[         ;   a  [        R                  $ [        X5      (       a  [        R                  $ US:  a  [        R
                  $ [        R                  $ )z(Return the running status of cloud-init.r   )r   r   r$   r   r"   r#   r!   )r   r   rB   latest_events       r'   get_running_statusr   |  sP     ..%%%	K	-	-$$$		!!!(((r&   c                     U R                  SS5      nU(       a5  UR                  S5      u  n  nUR                  5       R                  SS5      nU$ )zqGet the datasource from status.json.

Return a lowercased non-prefixed version. So "DataSourceEc2" becomes "ec2"
rG   rp   ri   )r|   	partitionlowerr   )	status_v1rG   ds_s       r'   get_datasourcer     sK    
 |R0J'',AqXXZ''b9
r&   c                 v    U R                  S5      nU(       a  U$ U R                  S5      (       a  SU S    3$ U$ )zReturn a description of the current status.

If we have a datasource, return that. If we're running in a particular
stage, return that. Otherwise, return the boot_description.
rG   stagezRunning in stage: )r|   )r   boot_descriptionrG   s      r'   get_descriptionr     sC     |,J	w		#Ig$6#788r&   c                     SnU R                  5        HW  n[        U[        5      (       d  M  [        UUR	                  S5      =(       d    SUR	                  S5      =(       d    S5      nMY     U$ )z,Return the latest event time from status_v1.r   startfinished)values
isinstancer   maxr|   )r   r   
stage_infos      r'   get_latest_eventr     s^    L&&(
j$''w',1z*/aL ) r&   c                 l   / n0 n[        U R                  5       5       H  u  p4[        U[        5      (       d  M  UR	                  UR                  S/ 5      5        UR                  S0 5      nUR                  5        H.  nXb;  a  [        XV   5      X&'   M  X&   R	                  XV   5        M0     M     X4$ )z>Return a list of errors and recoverable_errors from status_v1.rD   rE   )sortedr~   r   r   extendr|   keysr   )r   rD   rE   _keyr   current_recoverable_errorserr_types          r'   
get_errorsr     s    F"9??#45j$''MM*..267 *4$b*& 7;;=53;2<4&0 '0772< > 6" %%r&   r   c                    [         R                  nU =(       d
    [        5       n [        R                  R                  U R                  S5      n[        R                  R                  U R                  S5      n[        [        X5      u  pV0 n[        R                  R                  U5      (       a$  [        [        U5      5      R                  S0 5      n[        U5      n[        Xv5      n	[        U5      n
U
(       a  [!        S[#        U
5      5      OSn[%        U5      u  pU(       a  [         R&                  nOU(       a  [         R(                  n[+        X4XZ5      nU[,        R.                  :X  aP  [1        5       (       aA  [3        US9(       a3  [,        R4                  n[         R&                  nSn	UR7                  S5        UR9                  S	S
5        [;        UUUU	UUUUU5	      $ )zReturn a dict with status, details and errors.

@param paths: An initialized cloudinit.helpers.paths object.
@param wait: If user has indicated to wait for cloud-init to complete.

Values are obtained from parsing paths.run_dir/status.json.
zstatus.jsonzresult.jsonrH   z%a, %d %b %Y %H:%M:%S %zrp   r   z"Failed due to systemd unit failurezFailed due to systemd unit failure. Ensure all cloud-init services are enabled, and check 'systemctl' or 'journalctl' for more information.rG   N)r)   r0   r   r   r   r}   r   r   CLOUDINIT_DISABLED_FILEr   r   r   r|   r   r   r   r   r   r   r.   r/   r   r   r"   r   r   r#   appendpopr>   )r   rL   rA   r   r   rB   r   r   rG   rC   r   rF   rD   rE   r@   s                  r'   r   r     s    '--%^%E'',,u}}m<K'',,u}}m<K)7*& I	ww~~k""n[9:>>tRH		*J!)>K#I.L  	+VL-AB  ",I!6F*00	*33'"2N
 	-///NN%&++*00:$	
 MM,%
 
r&   c                  t    [        5       n [        R                  " [        SU R	                  5       5      5        g)z$Tool to report status of cloud-init.rV   N)rf   r   exitr   
parse_argsrd   s    r'   mainr     s&    \FHH&*;*;*=>?r&   __main__r   )NF)Cr    ra   enumrX   r   r   copyr   timer   r   r   typingr   r   r	   r
   r   r   	cloudinitr   r   cloudinit.cmd.develr   cloudinit.distrosr   cloudinit.helpersr   cloudinit.utilr   r   r   r   uniqueEnumr   r)   r2   	frozensetr5   r6   r7   r8   r   r>   r   rJ   boolrT   rf   rk   r   intr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   <module>r      s+   N    	 
  ( ( ? ? $ . * # A A:  DII   dii   
DII 
 
  ++00--..	 	J 	+ I  		%P(('6(
38_((?, ?,Dc 6(t ('%}c7I1J '%Tt 8 8$ 8vKD K
))	 	 
&U4:. &2 16DE?D)-DDN@ zF r&   