
    }fF                        d dl 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d dlmZm	Z	 d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d d	l
mZ d d
l
mZ d dl
mZ d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl
mZ d dlmZ d dl m!Z!m"Z"m#Z#m$Z$ dZ%dZ&e!e"e#dZ'dddddZ( ejR                  e*      Z+d8dZ,d Z-d9dZ.d Z/e+j`                  fd e	e1gdf   fd!Z2d" Z3d#efd$Z4d% Z5d:d&Z6d;d'ee7e1f   fd(Z8d) Z9d* Z:d+ Z;d, Z<d- Z=d. Z>d/ Z?d0ej                  fd1ZAd2 ZBd3 ZCd9d4ZDe*d5k(  rEd6ej                  vrd7ej                  d6<    eDej                        ZGeGr ej                  eG       yyy)<    N)TupleCallable)netinfo)signal_handler)sources)stages)
url_helper)util)version)warnings)	reporting)atomic_helper)read_cfg_paths)cc_set_hostname)Modules)validate_cloudconfig_schema)log)events)PER_INSTANCE
PER_ALWAYSPER_ONCECLOUD_CONFIGzOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.zcloud_%s_modules)instancealwaysoncezLocal StagezNetwork StagezConfig StagezFinal Stage)
init-localinitmodules-configmodules-finalc                    | r"t         j                  j                  d| z         t         j                  j                  d       t         j                  j                  d       t        j                  t         j                         t         j                  j                  d       t         j                  j                  d       y )N%s
z<------------------------------------------------------------
)file)sysstderrwrite	traceback	print_excmsgs    4/usr/lib/python3/dist-packages/cloudinit/cmd/main.pyr(   r(   H   su    


3(JJXJJTSZZ(JJXJJT    c                      t        j                         r+t        j                         } t        j                  d|        y y )NzPID [%s] started cloud-init.)r
   is_LinuxosgetppidLOGinfo)ppids    r+   log_ppidr4   R   s*    }}zz|/6 r,   c                 t    |st        |       }t        j                  d|z  ddt               t	                |S )Nr!   FT)consoler%   r   )welcome_formatr
   	multi_logr1   r4   )actionr*   s     r+   welcomer:   X   s/    V$NN6S>53GJJr,   c                     t         j                  t        j                         t	        j
                         t	        j                         |       S )N)r   uptime	timestampr9   )WELCOME_MSG_TPLformatr   version_stringr
   r<   time_rfc2822r9   s    r+   r7   r7   `   s>    !!&&({{}##%	 "  r,   loggerc                 d   t        j                  t        j                  j	                               sk | d       t        t         j                        5 }t        j                  |j	                         t        j                  j	                                ddd       y | d       y# 1 sw Y   yxY w)zj
    reopen stdin as /dev/null to ensure no side effects

    logger: a function for logging messages
    zClosing stdinNz"Not closing stdin, stdin is a tty.)r/   isattyr$   stdinfilenoopendevnulldup2)rC   fps     r+   close_stdinrL   i   sy     99SYY%%'("** 	5GGBIIK!1!1!34	5 	5 	34	5 	5s   AB&&B/c                     g }| j                   rI| j                   D ]:  }|j                  t        j                  j	                  |j
                               < |S N)filesappendr/   pathrealpathname)argsfn_cfgsfhs      r+   extract_fnsrW   w   sK     Gzz** 	6B NN277++BGG45	6 Nr,   modsc                 N   t         |z  }| j                  |      \  }}t        |      t        |      z   }|dk(  rBd|d|d}t        j                  j                  d|z         t        j                  |       g S t        j                  dt        |      t        |             |S )Nr   zNo 'z ' modules to run under section ''r!   zRan %s modules with %s failures)MOD_SECTION_TPLrun_sectionlenr$   r%   r&   r1   debug)rX   action_namesectionfull_section_name	which_ranfailurestotal_attemptedr*   s           r+   run_module_sectionre      s    '73 ,,->?Y)ns8}4O!
 	

3(		#			-s9~s8}	
 r,   c                 p    | j                  d      r%t        j                  | j                  d             y y )Nr   )getr   update_configuration)cfgs    r+   apply_reporting_cfgrj      s*    
ww{&&sww{';< r,   c                 x    t        j                  |       }|D ]  }||v s|||   fc S  t        d| d|d      )Nz	No keys (z) found in string 'rZ   )r
   keyval_str_to_dictKeyError)cmdlinenamesdatakeys       r+   parse_cmdline_urlrr      sH    ""7+D "$;S	>!" '5I
JJr,   returnc                    |t        j                         }	 t        |      \  }}|j                  d      }|rmt        j                  j                  |       rN|r/d| d|d}t        j                  }|rt        j
                  }||fS d| d|d}t        j                  }||fS |dd	d
d}|s|rt        j                  }d|d<   nt        j
                  }d|d<   d}	d}
	 t        j                  d%i |}d}|j                         rd
}t        |t        j                         r<	 |t#        |j%                  t'        |
                  z  }|j                  |
      s d}n|j*                  j                  |
      sd}|r|dk(  rgt        j,                  dddd
      S |dk(  rt        j                  }nt        j                  }|d| dt/        |
       fS |d|d|j0                  dfS ||j*                  z   }	t        j4                  | |	d !       t        j                  d"|d#|d$| fS # t        $ r t        j
                  dfcY S w xY w# t(        $ r Y w xY w# t        j2                  $ r}|d|d|fcY d}~S d}~ww xY w)&a  Write data from url referenced in command line to path.

    path: a file to write content to if downloaded.
    network: should network access be assumed.
    cmdline: the cmdline to parse for cloud-config-url.

    This is used in MAAS datasource, in "ephemeral" (read-only root)
    environment where the instance netboots to iscsi ro root.
    and the entity that controls the pxe config has to configure
    the maas datasource.

    An attempt is made on network urls even in local datasource
    for case of network set up in initramfs.

    Return value is a tuple of a logger function (logging.DEBUG)
    and a message indicating what happened.
    Nz!No kernel command line url found.)zfile:///zfile 'zC' existed, possibly from local stage download of command line url 'z'. Not re-writing.zE' existed, possibly from previous boot download of command line url '
      T)urltimeoutretriesstream   sec_betweeng?s   #cloud-configr,   )
chunk_sizeFrx   z!The kernel command line key `url`z22.3zD Please use `cloud-config-url` kernel command line parameter instead
deprecateddeprecated_versionextra_messageskip_logcloud-config-urlzcontents of 'z' did not start with zurl 'z' returned code z. Ignoring.zretrieving url 'z
' failed: i  )modezwrote cloud-config data from z='z' to  )r
   get_cmdlinerr   rm   loggingDEBUG
startswithr/   rQ   existsINFOWARNr	   read_file_or_urlok
isinstanceUrlResponsenextiter_contentr]   StopIterationcontents	deprecatestrcodeUrlError
write_file)rQ   networkrn   cmdline_namerx   path_is_localmlevelkwargsrp   headerrespsniffed_contentis_cloud_cfges                  r+   attempt_cmdline_urlr      s   & ""$D-g6c NN#34M- AEcK  LLE qz  AEcK  LLEqzRAFF- !} #}DF*D**4V4779L$
 6 67#t))S[)A( O
 '11&9#(L]]--f5$5(>>#F+1'@!%   #55#LLE#LLE#C5(=c&k]K  :=tyyI  .
 	OOD$U+d	$ ]  DBCCDV % >  D3BCCDsg   H- !AI %'I AI 8I I +I -I
I	II II J1	J :J Jc                    dt         j                  j                  t         j                  j                  fz  }t        j
                  j                  | j                  j                  d      d      }t        j
                  j                  |      r\t        |      j                         }||k7  r=t        j                  d       | j                  d       t        j                   ||       yyt        j
                  j                  | j                  j#                  d            rt        j%                  d       t        j                   ||       y)	zPurge the cache if python version changed on us.

    There could be changes not represented in our cache (obj.pkl) after we
    upgrade to a new version of python, so at that point clear the cache
    z%d.%drp   zpython-versionz-Python version change detected. Purging cacheTobj_pklzMWriting python-version file. Cache compatibility status is currently unknown.N)r$   version_infomajorminorr/   rQ   joinpaths	get_cpathr   rH   readr1   r^   purge_cacher
   r   get_ipath_curr2   )r   current_python_versionpython_version_pathcached_python_versions       r+   $purge_cache_on_python_version_changer     s    %(  '',,

V$&6 
ww~~)* $%8 9 > > @ !$::IIEFT"OO/1GH ;
 77>>$**229=>HHC 	+-CDr,   c                 ^    t        j                  | j                  d      ry|j                   S )Ndisable_network_activationF)r
   get_cfg_option_boolri   local)r   rT   s     r+   _should_bring_up_interfacesr   /  s&    *FGzz>r,   c                 4   t         j                  t         j                  g}|j                  rt         j                  g}t	        t
        j                  j                  dt        z  d      |j                         g|j                  st        |       }nt        d| z        }t        j                  ||j                        }|j                  t        |             d }d }	 t        fd       t!        j"                  |j$                  |       \  }}|j4                  r)t*        j5                  d       t7        j8                          t7        j:                  |j$                         t=        |j$                         t?        | |	       D ]  \  }}t*        j7                  ||        	 |jA                          |jB                  }	tE        |       |j                  rt         jF                  nt         jH                  }
|
t         jH                  k(  r7d}tJ        jL                  jO                  dtQ        jR                         z         nd}t!        jT                  |j$                  dd      }|rt*        j5                  d       d}nH|	jW                  d      }t
        j                  jY                  |      rt*        j5                  d|       d}|j[                          t]        ||      }	 |j_                  |       |
t         jH                  k(  r>|j`                  jb                  |
k7  r%t*        j5                  d|
|j`                         d g fS tk        |       |jm                         }t*        j5                  d|
| ||jo                                |
t         jF                  k(  rtq        |dd       |ji                  |       |
t         jF                  k(  ri|j`                  jb                  |
k7  r/t*        j5                  d|
|j`                         |j`                  g fS t*        j5                  d |
|j`                         |js                          |ju                          tq        |d!d"       	 |jw                         jy                  d#|jz                  t|        gt|        $      \  }}|s|j{                  t~               |jB                  jW                  d&      }t
        j                  jY                  |      rXt        j                  |      j                  d'k7  r6t        t        j                  t!        j                  |            ddd()       nt*        j5                  d*       t=        |j$                         t        |t        |      |j                  +      }	 |}|}t!        j                  |j$                  |       \  }}||k7  s||k7  r:t*        j                  d,||       t!        j"                  |j$                  |       \  }}t7        j:                  |j$                         |j                          t        |j`                  |j$                  .       |j`                  t        || |       fS # t&        $ rL d}t!        j(                  t*        |       t-        |       j/                  t0        j2                  |f       Y w xY w# t&        $ r t!        j(                  t*        d
       Y 2w xY w# t         jd                  $ r |
t         jF                  k(  rt*        j5                  d       nt!        j(                  t*        d       |jf                  sH|ji                  |       t*        j5                  d|
       |
t         jF                  k(  rd g fcY S d dgfcY S t*        j5                  d|
       Y gw xY w# t&        $ r, t!        j(                  t*        d%       |j`                  d%gfcY S w xY w# t&        $ r t!        j(                  t*        d-       Y w xY w)/Nz%s.dz91_kernel_cmdline_url.cfg)rQ   r   z%s-localds_depsreporterc                 F    j                  t        j                  | f      S rN   )rP   r   r   )r*   
early_logss    r+   <lambda>zmain_init.<locals>.<lambda>[  s    
 1 17==#2F G r,   #Failed to setup output redirection!@Logging being reset, this logger may no longer be active shortlyr)   z0Failed to initialize, likely bad things to come!trustr!   checkmanual_cache_cleanFz"manual cache clean set from configmanual_clean_markerz(manual cache clean found from marker: %sexistingz)[%s] Exiting. datasource %s in local modezNo local datasource foundz8No instance datasource found! Likely bad things to come!)bring_upz[%s] Exiting without datasourcezNo instance datasource found.z2[%s] barreling on in force mode without datasourcez5[%s] %s will now be targeting instance id: %s. new=%sr   r   )stageretry_stagez.[%s] Exiting. datasource %s not in local mode.z6[%s] %s is in local mode, will apply init modules now.zinit-netzmodules:configconsume_data)rT   freqzConsuming user data failed!cloud_configr   T)configstrictlog_detailslog_deprecationsz2Skipping user-data validation. No user-data found.r   z#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!)
datasourceri   )Lr   DEP_FILESYSTEMDEP_NETWORKr   r   r/   rQ   r   r   r7   r   Initr   read_cfgrW   rL   r
   fixup_outputri   	Exceptionlogexcr1   r(   rP   r   r   r^   r   reset_loggingsetup_loggingrj   r:   
initializer   r   DSMODE_LOCALDSMODE_NETWORKr$   r%   r&   r   
debug_infor   r   r   r   r   fetchr   dsmodeDataSourceNotFoundExceptionforceapply_network_config_maybe_persist_instance_data
instancifyis_new_instance_maybe_set_hostnamesetup_datasourceupdatecloudifyrunr   r   r   statst_sizer   yaml	safe_loadload_text_filer   get_output_cfgwarningactivate_datasourcedi_report_warnre   )rS   rT   depsw_msgr   outfmterrfmtr*   lvlpath_helperr   r   mcfgmfilebring_up_interfacesiidran_resultscloud_cfg_pathrX   outfmt_origerrfmt_origr   s                         @r+   	main_initr  5  s   ""G$7$78Dzz&&' 	%'B 

N		
J, ::t$zT23;;tdmm<DMM+d#$FF/GH**488T: zz		N	
 	dhh!
 De  SSM **K(.#'::773I3IDw%%%

7#5#5#789''2FNII:;H--.CDEww~~e$		DeL" 6dDA

H
% 7)))doo.D.D.LII;
 ":. !&
//
CII? w### 	DYG':;w###??!!T)II@
 OOR((IIH 	KKMJ<LMB --/--	 . 
h  j) ZZ--n=N	ww~~n%"''.*A*I*IQ*N#>>$"5"5n"EF!		
 			FG! 4T*T]]CDD..txx>& K6$9KK=vvN#004@VV dhh 	doo488< OO/dDABBi  /3C#7<<-.	/4  MCKLMJ ..  7'''II12KKO zz%%/B%CII7>w+++bz!>?@@IIDd%^  BC67"?!@AAB8  DCBCDsk   #1Y/ +[ *A"[1 -A^8 A+_0 /A[[#[.-[.1B!^5^5^54^582_-,_-0#``c                    d|vrt         j                  d       y |d   }|t         j                  d       y t        |t              st         j	                  d|       y |j                  d      }|t         j	                  d       y t        |t              st         j	                  d|       y | j                  j                  d      d	   }|j                  t        j                        r|t        t        j                        d  }nt         j	                  d
| |       ||v rt         j                  d| ||       y t        j                  d||t        |             y )N	di_reportzno di_report found in config.zdi_report was None.z%di_report config not a dictionary: %sdatasource_listz(no 'datasource_list' found in di_report.z(di_report/datasource_list not a list: %s.rw   z1Datasource '%s' came from unexpected module '%s'.z:used datasource '%s' from '%s' was in di_report's list: %sdsid_missing_source)sourcedslist)r1   r^   r   dictr   rg   list
__module__
rpartitionr   r   	DS_PREFIXr]   r   show_warningr   )r   ri   dicfgr  modnames        r+   r   r     s7   #		12E} 			'(eT";UCYY()F~>?%>G ##..s3A6G'++,#g//023?	
 &		H		
 	s73v;r,   c                    |j                   }t        | d|      }t        j                  g |j                        }|j                  t        |             	 |j                  d       t        |       t!        |t        |      |j                        }	 t#                t        j$                  |j&                  |       |j*                  r)t        j+                  d       t-        j.                          t-        j0                  |j&                         t3        |j&                         t5        ||	       |d
k(  rt        j6                  ddd       t9        |||      S # t        j                  $ r? d|z  }t        j                  t        |       t        |       |j                  s|gcY S Y Hw xY w# t(        $ r t        j                  t        d       Y w xY w)N:r   r   r   zGCan not apply stage %s, no datasource found! Likely bad things to come!r   r   r   r)   r   z`--mode init`24.1Use `cloud-init init` instead.)r   r   r   )r   r7   r   r   r   r   rW   r   r   r   r
   r   r1   r(   r   r   r   rL   r   ri   r   r^   r   r   r   rj   r:   r   re   )r_   rT   rS   r   r   r*   rX   s          r+   main_modulesr  F  s   99D k489E;;rDMM:DMM+d#$

G
$ !&4T*T]]CD@$((D) zz		N	
 	dhh! Dev~&%:	
 dD$//O .. 	 $% 	 	C#zz7N 	"  @C>?@s%   E" *F7 "AF43F47#GGc                    |j                   }t        |       }t        j                  g |j                        }|j                  t        |             	 |j                  d       t        |       t!        |t        |      |j                        }|j"                  }|rt        j%                  d|       |j&                  }|r+t        j%                  d|       t(        j+                  |      }	 t-                t        j.                  |j0                  d        |j$                  r)t        j%                  d
       t5        j6                          t5        j8                  |j0                         t;        |j0                         t=        | |       |j?                  |||      \  }}	|	rt        jA                  d|       y|st        jA                  d|       yy# t        j                  $ r7 t        j                  t        d       t        d       |j                  sY yY w xY w# t2        $ r t        j                  t        d	       Y 2w xY w)Nr   r   r   z;Failed to fetch your datasource, likely bad things to come!r|   r   zUsing passed in arguments %szUsing passed in frequency %sr   r   r)   zRan %s but it failed!zDid not run %s, does it exist?r   )!rS   r7   r   r   r   r   rW   r   r   r   r
   r   r1   r(   r   r   r   module_argsr^   	frequencyFREQ_SHORT_NAMESrg   rL   r   ri   r   r   r   r   rj   r:   
run_singler   )
rS   rT   mod_namer   r   rX   mod_argsmod_freqrb   rc   s
             r+   main_singler%    s    yyH4 E;;rDMM:DMM+d#$

G
$ !&4T*T]]CDH		0(;~~H		0(;#''1@$((D) zz		N	
 	dhh! De !OOHhIY+X64h? e ..  	N	
 	I	
 zz 4  @C>?@s%   G 0*H& AH#"H#&#IIc           
         t               }|j                  d      }t        j                  j	                  |j
                        }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                         }	t        j                  ||f       |j                  \  }
}| dk(  r|j                  rd}n&d}n#| dk(  rd|j                  z  }nt        d| z        |t        vrt        d	j!                  |            g i d d d
}dd |j#                         |j#                         |j#                         |j#                         di}|dk(  r!||||fD ]  }t        j$                  |        n)	 t'        j(                  t        j*                  |            }||d   vr|j#                         |d   |<   |d   }||d<   ||   d   r%||   d   st.        j1                  dt        |          t3        t        j4                               ||   d<   t7        t9        d |	j:                              j=                         }t?        j@                  ||       t        jB                  t        j                  jE                  ||      |d       	  || |      }|dv r|\  }}|tG        |      |d<   n|}||   d   jI                  |D cg c]  }tG        |       c}       t3        t        j4                               ||   d<   d |d<   t7        t9        d |	j:                              j=                         }|jU                         D ];  }||v r'tW        tY        ||   ||   z               ||   d   |<   .||   ||   d   |<   = t?        j@                  ||       |dk(  rg }|jU                         D ]O  }t[        ||   t\              s||   j_                  d      s,|jI                  ||   j_                  dg              Q t?        j@                  |d|d   |di       t        jB                  t        j                  jE                  ||      |d       ta        ||   d         S # t,        $ r Y w xY wc c}w # t,        $ rO}t.        jK                  d|       tM        d|z         ||   d   jO                  tG        |             Y d }~d }~wtP        $ ri}|jR                  rRt.        jK                  d|       tM        d|z         ||   d   jO                  dtG        |jR                         d       Y d }~`d }~ww xY w# t3        t        j4                               ||   d<   d |d<   t7        t9        d |	j:                              j=                         }|jU                         D ];  }||v r'tW        tY        ||   ||   z               ||   d   |<   .||   ||   d   |<   = t?        j@                  ||       w xY w)Nrp   zstatus.jsonzresult.jsonr   r   modules
modules-%szunknown name: %sz'Invalid cloud init mode specified '{0}')errorsrecoverable_errorsstartfinishedv1)r   r   r   r   r   r   r+  r,  z=Unexpected start time found for %s. Was this stage restarted?c                 6    t        | t        j                        S rN   r   r   LogExporterhs    r+   r   z status_wrapper.<locals>.<lambda>  s    As7 r,   T)r   )r   r   r   r)  zfailed stage %szfailed run of stage %sz	sys.exit(z) calledc                 6    t        | t        j                        S rN   r/  r1  s    r+   r   z status_wrapper.<locals>.<lambda>?  s    *Q8 r,   r*  r   )r   r)  )1r   r   r/   rQ   normpathrun_dirr   r   	getLoggerr
   ensure_dirsr9   r   r   
ValueError
STAGE_NAMEr?   copydel_filejsonloadsr   r   r1   r   floatr<   r   filterhandlersexport_logsr   
write_jsonsym_linkrelpathr   extend	exceptionr(   rP   
SystemExitr   keysr  setr   r  rg   r]   )rS   rT   r   data_dlink_dstatus_pathstatus_linkresult_pathresult_linkroot_logger_namefunctorr   
nullstatusstatusfr-  preexisting_recoverable_errorsretr   r)  r   new_recoverable_errorsrq   r   s                            r+   status_wrapperrY    s   E__V$FWWemm,F'',,v}5K'',,v}5K'',,v}5K'',,v}5K##%K	
 {{UGv~::DD		dii'+d233:5<<TB
 	

  	J 	OO%$//+(oo/'__.
F |{KE 	AMM!		ZZ 3 3K @AF 6$<'__.tT	BBwK	$xD*!5Kt	

 dkkm,BtHW%)79M9MN&km #
 [&1MM
V,k46dD!))#& Z%#&z?< F
4!!6":a3q6":;(  %T[[]347 "&8+:N:N"
 +-	 	
 *..0 	C446:6s;05674-.s3 7M74-.s3	 	  f5 	7A"Q%&2a599X+>beii"56	7 	  "\"2fEF	
 	GGOOK0+T	
 r$x!""A  		H #; *'.*T12
4!!#a&)) 	I 66 MM+T2.56tHX%%	#aff+h&GH	I  %T[[]347 "&8+:N:N"
 +-	 	
 *..0 	C446:6s;05674-.s3 7M74-.s3	 	  f5sc   (S  %:S S1S  	SSS 	VAT("V  (V4AVV  VV   B<Yr   c                     | j                   re| j                  rX| j                  j                  d      }t        j
                  j                  |      s| j                   j                  d       yyyy)zCWrite instance-data.json file if absent and datasource is restored.instance_dataF)write_cacheN)r   ds_restoredr   get_runpathr/   rQ   r   persist_instance_data)r   instance_data_files     r+   r   r   d  sX    4++!ZZ33ODww~~01OO11e1D 2 ,r,   c           	      >   | j                         }t        j                  | j                  |d      \  }}}|r$	 t	        j
                  d| j                  |d       yy# t        j                  $ r+}t        j                  d||t        |             Y d}~yd}~ww xY w)zCall set_hostname if metadata, vendordata or userdata provides it.

    @param stage: String representing current stage in which we are running.
    @param retry_stage: String represented logs upon error setting hostname.
    T)metadata_onlyset_hostnameNzGFailed setting hostname in %s stage. Will retry in %s stage. Error: %s.)
r   r
   get_hostname_fqdnri   r   handleSetHostnameErrorr1   r^   r   )r   r   r   cloudhostname_fqdn_r   s           r+   r   r   l  s     MMOE11%tXua 		"">488UDI  // 	II1A 	s   "A B1!BBc                     t         j                  j                  dj                  t	        t
        j                              dz          y )Nr"   )r$   stdoutr&   r   sortedr   FEATURES)rS   rT   s     r+   main_featuresro    s-    JJTYYvg&6&6784?@r,   c           
      P   t        j                          | st        j                  } t	        j
                  | j                  d            }|j                  ddddt        j                         z   d       |j                  d	d
ddd       |j                  ddddd       |j                  d        |j                  dd      }d|_        |j                  dd      }|j                  ddddd       |j                  ddd d!d"t	        j                  d#      $       |j                  dt        f%       |j                  d&d'      }t!        j"                  d(d)d*d+      j$                  }|j                  d,d-d.d/| d0d12       |j                  ddd d!d"t	        j                  d#      $       |j                  d&t&        f%       |j                  d3d4      }|j                  d5d6d.d7d8       |j                  d9d.d:dt)        t*        j-                               ;       |j                  d<dd=d8       |j                  d>d?d@dAB       |j                  ddd d!d"t	        j                  d#      $       |j                  d3t.        f%       |j                  dCdD      }|j                  dEdF      }|j                  dEt0        f%       |j                  dGdH      }	|j                  dIdJ      }
|j                  dKdL      }|j                  dMdN      }|j                  dOdP      }|j                  dQdR      }| rt3        dS | D        d       }|dGk(  rddTlm}  ||	       n|dIk(  rddTlm}  ||
       n|dKk(  r&ddUlm}m}  ||V       |j                  dK|f%       n|dMk(  r%ddWlm}m }  ||       |j                  dM|f%       n}|dCk(  r%ddXl!m}m"}  ||       |j                  dY|f%       nS|dQk(  r%ddZl#m}m$}  ||       |j                  dQ|f%       n)|dOk(  r$dd[l%m}m&}  ||       |j                  dO|f%       |jO                  | \      }|jP                  \  }}|d]vr@t        jR                  |jT                  rtV        jX                  ntV        jZ                         n |jT                  rt        jR                          t]        j^                          d|k(  sd&|k(  rd|j`                  k7  rtb        }d }d} |dk(  r|jd                  rd^\  }}!ncd_\  }}!n]|d&k(  rd`|j`                  z  da|j`                  z  }!}n9|d3k(  r+db|jf                  z  dc|jf                  z  }!}|jh                  } n	|}dd|z  }!d} tk        jl                  ||!| e      |_7        |jn                  5  t!        jp                  tr        jT                  df|z  d|||fg      }"d d d        tu        jv                          d&|k(  rd|j`                  k(  rty        "      }""S # 1 sw Y   >xY w)hNr   )progz	--versionz-vr   z	%(prog)s z'Show program's version number and exit.)r9   r   helpz--debugz-d
store_truez:Show additional pre-action logging (default: %(default)s).F)r9   rr  defaultz--forcezDForce running even if no datasource is found (use at your own risk).r   )r9   rr  destrt  r   Subcommands
subcommand)titleru  Tr   z2Initialize cloud-init and perform initial modules.)rr  z--localz-lz+Start in local mode (default: %(default)s).z--filez-frP   rO   z(Use additional yaml configuration files.rb)r9   ru  rr  typerB   r'  z1Activate modules using a given configuration key.z`init`r  r  r   z--modez-mstorez9Module configuration name to use (default: %(default)s). r   )r   r   final)r9   rr  rt  choicessinglezRun a single module.z--namez-nzModule name to run.)r9   rr  requiredz--frequencyzModule frequency for this run.)r9   rr  r  r}  z--reportzEnable reporting.r  *argumentz0Any additional arguments to pass to this module.)nargsmetavarrr  queryz;Query standardized instance metadata from the command line.featureszList defined features.analyzez-Devel tool: Analyze cloud-init logs and data.develzRun development tools.zcollect-logsz*Collect and tar all cloud-init debug info.cleanz3Remove logs and artifacts so cloud-init can re-run.rT  z/Report cloud-init status or wait on completion.schemaz-Validate cloud-config files using jsonschema.c              3   D   K   | ]  }|j                  d       r|  yw)-N)r   ).0posargs     r+   	<genexpr>zmain.<locals>.<genexpr>.  s     J63D3DS3IVJs     )
get_parser)r  handle_collect_logs_args)parser)r  handle_clean_args)r  handle_argsrender)r  handle_schema_args)r  handle_status_args)rT   )r   r'  )r   zsearching for local datasources)zinit-networkz!searching for network datasourcesr(  zrunning modules for %sz	single/%szrunning single module %szrunning 'cloud-init %s')reporting_enabledzcloud-init mode '%s')logfuncr*   
get_uptimefuncrT   )=r   configure_root_loggerr$   argvargparseArgumentParserpopadd_argumentr   r@   set_defaultsadd_subparsersr  
add_parserFileTyper  r
   r   messager  r  r   rH  r%  ro  r   cloudinit.analyzer  cloudinit.cmd.devel.parsercloudinit.cmd.devel.logsr  cloudinit.cmd.cleanr  cloudinit.cmd.queryr  cloudinit.config.schemar  cloudinit.cmd.statusr  
parse_argsr9   setup_basic_loggingr^   r   r   WARNINGr   attach_handlersr   rY  r   rS   reportr   ReportEventStackr   log_timer1   r   flush_eventsr]   )#	sysv_argsr  
subparsersparser_init
parser_mod
extra_helpparser_singleparser_queryparser_featuresparser_analyzeparser_develparser_collect_logsparser_cleanparser_statusparser_schemarw  analyze_parserdevel_parserlogs_parserr  clean_parserr  query_parserhandle_query_argsschema_parserr  status_parserr  rT   rS   rR  rname	report_onrdescretvals#                                      r+   mainr    s   HH	$$)--*:;F w55786   I   -   	 &&&]&NJJ ''I ( K :   7t$   VY$78 &&K ' J !6	
 g  | +  
 7t$   I|#<= ))- * M "   -%**,-    	   ?	   7t$   x&=>((J ) L
 !++1 , O   ](C D**G + N ((. ) L %//I 0  ((K ) L ))H * M ))F * M J)J

 "F >*7"M &>)
 23,,&(@A -  7"
 &%%g7H-I%J7"
 &%%h8I-J%K8#
 -(&&x9K.L&M8#
 -(&&x9K.L&M),D kkOT7 &&!ZZGMMW__	
 
! ""$
 ~)t+$))0C EIv~::LLE5LE5 
	499$$tyy0  
	$))#&2  KK	)D0	++u	DM 
 
II&-

  DVtyy0VM
 
s   1.XX%__main__TZz:/etc/localtime) rN   ))r   rx   )TN)Ir  r<  r/   r$   r'   r   r   typingr   r   	cloudinitr   r   r   r   r	   r
   r   r   r   r   cloudinit.cmd.develr   cloudinit.configr   cloudinit.config.modulesr   r  r   r   cloudinit.reportingr   cloudinit.settingsr   r   r   r   r>   r[   r   r9  r6  __name__r1   r(   r4   r:   r7   r^   r   rL   rW   re   rj   rr   intr   r   r   r  r   r  r%  rY  r   r   r   ro  r  environr  return_valueexitr   r,   r+   <module>r     s     	 
    "  $         # . , , ?  & O O(  %
    $"	
 g!
7 14		 5#- 5
W &=
KjU38_ jZE<\C~/d:0zCLX#vEv{{ E.AfR	 z2::,

4>L 	 r,   