
    x[h              
          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  S SK	J
r
  S SKJrJrJrJrJrJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJrJ r   S SK!J"r"J#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K0J1r1  S SK2J3r3  S SK4J5r5  S SK6J7r7J8r8J9r9J:r:J;r;  S SK<J=r=  \R|                  " \?5      r@SrASrBS\R                  S\DS\&S\%S\E4
S jrF " S S5      rGS\H4S jrISS.S\HS\D4S jjrJg)     N)
namedtuple)suppress)Path)AnyDictIterableListOptionalSetTupleUnion)atomic_helperclouddistrosfeatureshandlershelpersimporter	lifecyclenetsources
type_utilsutil)Netv1Netv2)
EventScope	EventTypeuserdata_to_events)BootHookPartHandler)CloudConfigPartHandler)JinjaTemplatePartHandler)ShellScriptPartHandler)ShellScriptByFreqPartHandler)cmdline)events)CLOUD_CONFIGDEFAULT_RUN_DIR
PER_ALWAYSPER_INSTANCEPER_ONCE)NetworkConfigSourceNO_PREVIOUS_INSTANCE_IDzAggregated cloud-config created by merging merged_system_cfg (/etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d), metadata, vendordata and userdata. The combined_cloud_config represents the aggregated desired configuration acted upon by cloud-init.
datasourcecfgevent_source_typescopereturnc                    U R                   n[        UR                  S0 5      5      n[        R                  " [
        R                  " U5      [
        R                  " U5      /5      n[        R                  U R                  R                  U[        5       5      ;   a  [        R                  " U R                  5      nUR                  US   ;   a  [        R                  SU[        R                  U R                  R!                  S5      5        UR                  U5      (       d  [        5       Xc'   Xc   R#                  [        R                  5        [        R                  SU5        U/nU V	s/ s H  oR                  PM     n
n	U H;  nX&R                  U/ 5      ;   d  M  [        R                  SUR                  U5          g   [        R                  SX5        g	s  sn	f )
a  Determine if a particular EventType is enabled.

For the `event_source_type` passed in, check whether this EventType
is enabled in the `updates` section of the userdata. If `updates`
is not enabled in userdata, check if defined as one of the
`default_events` on the datasource. `scope` may be used to
narrow the check to a particular `EventScope`.

Note that on first boot, userdata may NOT be available yet. In this
case, we only have the data source's `default_update_events`,
so an event that should be enabled in userdata may be denied.
updatesscopesz/Adding event: scope=%s EventType=%s found in %szhotplug.enabledzAllowed events: %sz$Event Allowed: scope=%s EventType=%sTz$Event Denied: scopes=%s EventType=%sF)default_update_eventsr   getr   mergemanydictcopydeepcopyr   HOTPLUGsupported_update_eventssetread_hotplug_enabled_filepathsvalueLOGdebug	get_cpathadd)r-   r.   r/   r0   default_eventsuser_eventsallowedhotplug_enabled_filer4   sscope_values	evt_scopes               2/usr/lib/python3/dist-packages/cloudinit/stages.pyupdate_event_enabledrL   B   s   & 	((  5G	25K   MM+&MM.)	
G J>>BBsu   $==j>N>NO;;.x88IIA!!  **+<=	 ;;u%%!$Ny001II"G,$)7F%+,VGGVL,	Ir ::II6!
   II.  -s   0Gc                   <   \ rS rSrS9S\\\      4S jjrS r\	S 5       r
\	S 5       rS r\	S	 5       rS
 rS:S jrS r\S\S\S\4S j5       rS rS;S jrS rS\4S jrS rS rS rS rS\R<                  4S jrS r S;S jr!S\4S jr"S r#S  r$S! r%S<S" jr&S# r'S$ r(S% r)S& r*S' r+S( r,S) r-S* r.S;S\\/R`                     4S+ jjr1S, r2S- r3 S;S. jr4\54S/ jr6\54S0 jr7\54S1 jr8S\9\:\;S4   4S2 jr<S\=\9\:\;S4   \9\>\4   4   4S3 jr?S4 r@S5 rAS\B4S6 jrCS7 rDS8rEg)=Init   Nds_depsc                     Ub  Xl         O%[        R                  [        R                  /U l         0 U l        S U l        S U l        S U l        SU l        S U l	        Uc  [        R                  " SSSS9nX l        g )NFzinit-reporterz	init-desc)namedescriptionreporting_enabled)rP   r   DEP_FILESYSTEMDEP_NETWORK_cfg_paths_distror-   ds_restored_previous_iidr%   ReportEventStackreporter)selfrP   r]   s      rK   __init__Init.__init__   sw    "L#22G4G4GHDL$&	/3158< ,0..$'"'H
 !    c                 .    0 U l         S U l        S U l        g N)rW   rX   rY   r^   s    rK   _resetInit._reset   s    	ra   c                    U R                   (       d  U R                  S5      nUR                  SS5      n[        R                  " U5      n[
        R                  SU5        U" X!U R                  5      U l         U R                  b6  U R                   U R                  l	        U R                  U R                  l        U R                   $ )NsystemdistroubuntuzUsing distro class %s)rY   _extract_cfgpopr   fetchr@   rA   r>   r-   ri   r.   sys_cfg)r^   system_configdistro_name
distro_clss       rK   ri   Init.distro   s    || --h7M'++Hh?K {3JII-z:%k$**MDL *)-&*.(('||ra   c                 $    U R                  S5      $ )N
restricted)rk   rd   s    rK   r.   Init.cfg   s      ..ra   c                    U R                  5         [        R                  " U R                  5      nUS:X  a  UR	                  SS 5        U$ US:X  a  [
        R                  " US0 5      nU$ US:X  a  [
        R                  " US0 5      nU$ )Nrt   system_inforh   )rw   r>   )rw   r>   )read_cfgr8   r9   rW   rl   r   get_cfg_by_path)r^   restrictionocfgs      rK   rk   Init._extract_cfg   s    }}TYY',&HH]D)
 	 H$''.>CD  G#''.FKDra   c                     U R                   (       d6  U R                  S5      n[        R                  " XR                  5      U l         U R                   $ )Nr>   )rX   rk   r   Pathsr-   )r^   	path_infos     rK   r>   
Init.paths   s7    {{))'2I!--	??CDK{{ra   c                    U R                   R                  nU R                   R                  nU[        R                  R                  US5      [        R                  R                  USS5      [        R                  R                  USS5      [        R                  R                  USS5      [        R                  R                  USS5      [        R                  R                  US5      [        R                  R                  US5      [        R                  R                  US5      [        R                  R                  US	5      [        R                  R                  US
5      [        R                  R                  US	5      /nU$ )Nscriptszper-instancezper-oncezper-bootvendorseed	instancesr   semdata)r>   	cloud_dirrun_dirospathjoin)r^   c_dirr   initial_dirss       rK   _initial_subdirsInit._initial_subdirs   s    

$$**$$GGLL	*GGLL	>:GGLL	:6GGLL	:6GGLL	84GGLL'GGLL,GGLL
+GGLL&GGLL'GGLL%(
 ra   c                     U R                   R                  /nU(       a%  UR                  U R                   R                  5        U H  n[        R
                  " U5        M     [        U5      $ rc   )r>   boot_finishedappendinstance_linkr   del_filelen)r^   rm_instance_lnkrm_listfs       rK   purge_cacheInit.purge_cache   sM    ::++,NN4::334AMM! 7|ra   c                 $    U R                  5         g rc   )_initialize_filesystemrd   s    rK   
initializeInit.initialize   s    ##%ra   mode_1mode_2r1   c                 
    X-  $ rc    )r   r   s     rK   _get_strictest_modeInit._get_strictest_mode   s
    ra   c                    Sn[         R                  " U R                  5       5        [         R                  " U R                  S5      nU(       a  [        [        5         U R                  S[         R                  " U5      5      nS S S 5        [         R                  " X!SS9  U R                  R                  S5      nU(       d  0 n[        U[        5      (       d  U/nS nU H3  n[         R                  " U5      u  pg [         R                  " X&U5          g    [        R!                  SUSR#                  U5      U5        g g ! , (       d  f       N= f! [         a  nUn S nAM  S nAff = f)Ni  def_log_fileF)preserve_modesyslog_fix_permsz,Failed changing perms on '%s'. tried: %s. %s,)r   ensure_dirsr   get_cfg_option_strr.   r   OSErrorr   get_permissionsensure_filer6   
isinstancelistextract_usergroupchownbynamer@   warningr   )	r^   modelog_filepermserrorpermuges	            rK   r   Init._initialize_filesystem   s&   ..01**488^D '"//4//9 # X5AHHLL!34EeT**E--d3$$X!4	  KK>	3  #"&  Es$   'E>E
E
E*E%%E*c                 T    U R                   (       d  U R                  U5      U l         g g rc   )rW   	_read_cfg)r^   	extra_fnss     rK   rx   Init.read_cfg  s    yyy1DI ra   c                     U R                  U0 5      nUR                  S0 5      R                  S0 5      nUR                  S5      [        S4;   a  U$ U R                  X5      $ )z read and merge our configurationrw   r>   r   N)_read_bootstrap_cfgr6   r'   )r^   r   initial_configr>   s       rK   r   Init._read_cfg  sf     11)R@""="599'2F 99YOT#::!! ''	99ra   bootstrapped_configc           
          [         R                  " X R                  5      nUR                  S5      n[         R                  " UU R                  U[        UR                  US9S9nUR                  $ )Ninstance_data_sensitiveinstance_data_file)r>   r-   additional_fnsbase_cfg)r   r~   r-   get_runpathConfigMergerfetch_base_configr   r.   )r^   r   r   no_cfg_pathsr   mergers         rK   r   Init._read_bootstrap_cfg+  sh    }}%8//J)55%
 %%$&$$9K	
 zzra   c                 `    [         R                  " U R                  R                  S5      5      $ )Nobj_pkl)r   pkl_loadr>   get_ipath_currd   s    rK   _restore_from_cacheInit._restore_from_cache:  s$     

 8 8 CDDra   c                 >   U R                   c  g[        R                  " U R                  SS5      (       a/  [        R                  " U R
                  R                  S5      SSS9  [        R                  " U R                   U R
                  R                  S5      5      $ )NFmanual_cache_cleanmanual_clean_markerw )omodecontentr   )	r-   r   get_cfg_option_boolr.   
write_filer>   r   r   	pkl_storerd   s    rK   _write_to_cacheInit._write_to_cache@  s}    ??"##DHH.BEJJ OO

(()>?
   OOTZZ55i@
 	
ra   c                    U R                   R                  S5      =(       d    / nS[        R                  " [        5      4 H  nX!;  d  M
  UR                  U5        M     U R                   R                  S5      =(       d    / nX14$ )Ndatasource_pkg_listr   datasource_list)r.   r6   r   obj_namer   r   )r^   pkg_listncfg_lists       rK   _get_datasourcesInit._get_datasourcesO  si    88<< 56<"j))'23A " 4 88<< 128b##ra   c                    US;  a  [        SU-  5      eU R                  5       nU(       d  gU R                  R                  S5      n[        R
                  R                  U5      (       a%  [        R                  " U5      R                  5       nOS nXBR                  5       :X  a  USU-  4$ US:X  a  USU-  4$ [        US5      (       a'  UR                  U R                  5      (       a  US	U-  4$ S S
U-  4$ )N)checktrustz!Unexpected value for existing: %s)Nzno cache foundinstance_idz&restored from cache with run check: %sr   zrestored from cache: %scheck_instance_idzrestored from checked cache: %szcache invalid in datasource: %s)
ValueErrorr   r>   r   r   r   existsr   load_text_filestripget_instance_idhasattrr   r.   )r^   existingds
run_iid_fnrun_iids        rK   _restore_from_checked_cache Init._restore_from_checked_cacheY  s    --@8KLL%%'+ZZ++M:
77>>*%%))*5;;=GG((**@2EFF 1B677r.//B4H4H5 5 =BCC?"DEEra   c           	         U R                   b  U R                   $ [        R                  " SSU-  U R                  S9 nU R	                  U5      u  p4XBl        [        U5      U l        [        R                  UR
                  5        S S S 5        W(       d   U R                  5       u  pV[        R                  " U R                  U R                  U R                  [         R"                  " U R$                  5      UUU R                  5      u  p7[&        R(                  " U R                  R*                  5        [        R-                  SXs5        X0l         U R5                  5         U$ ! , (       d  f       N= f! [        R.                   a  nUS:w  a  UeU R1                  5       nU(       a0  UR3                  5       (       a  [        R-                  SU5         S nAN[&        R(                  " U R                  R*                  5        UeS nAff = f)Nzcheck-cachez"attempting to read from cache [%s])rR   rS   parentzLoaded datasource %s - %sr   z3Restored fallback datasource from checked cache: %s)r-   r%   r\   r]   r   rS   boolrZ   r@   rA   r   r   find_sourcer.   ri   r>   r8   r9   rP   r   r   r   infoDataSourceNotFoundExceptionr   check_if_fallback_is_allowedre   )	r^   r   myrepr   descr   r   dsnamer   s	            rK   _get_data_sourceInit._get_data_sources  s   ??&??"$$<xG==
 77AHB $#BxDIIe''(
 %)%:%:%<" %00HHKKJJMM$,,/MM
 djj6674fA  		U
 
4 66 w&G--/"99;;HHM 
 MM$**":":;Gs,   A	E$B6E5 $
E25H		A
H,HH	c                 
    / SQ$ )N)r   r   r   r   rd   s    rK   _get_instance_subdirsInit._get_instance_subdirs  s    --ra   c                 `    U R                   R                  U5      nU(       d  [        S5      eU$ )NzCNo instance directory is available. Has a datasource been fetched??)r>   	get_ipathRuntimeError)r^   subnameinstance_dirs      rK   
_get_ipathInit._get_ipath  s5     zz++G43  ra   netcfgc                 R   [         R                  R                  U R                  R                  5      (       d  gU R                  R                  S5      nU R                  R                  S5      n[         R                  R                  U5      (       aD  U[        R                  " [        R                  " U5      5      :w  a  [        R                  " X!SS9  O[        R                  " X!SS9  [         R                  R                  U5      (       d  [        R                  " X#5        gg)zCreate /var/lib/cloud/instance/network-config.json

Only attempt once /var/lib/cloud/instance exists which is created
by Init.instancify once a datasource is detected.
Nnetwork_config  r   )r   r   islinkr>   r   r   r   r   r   	load_jsonr   r   
write_jsonsym_link)r^   r  ncfg_instance_pathnetwork_links       rK   _write_network_config_jsonInit._write_network_config_json  s     ww~~djj6677 !ZZ556FGzz--.>?77>>,--##$67  ((&U $$%7eLww~~l++MM,; ,ra   c                    U R                  5       n[        U R                  R                  5      R	                  5       R                  5       nU[        U5      R                  5       :H  nU(       a  [        R                  S5        OT[        R                  " U R                  R                  5        [        R                  " XR                  R                  5        / nU R                  5        H1  nUR                  [        R                  R                  X5      5        M3     [        R                   " U5        U R                  R#                  S5      n[$        R&                  " U R(                  5      < SU R(                  < 3nS n[        R                  R                  US5      n	 [        R*                  " U	5      R-                  5       nU(       d  Un[        R0                  " U	SU-  5        [        R0                  " [        R                  R                  US5      SU-  5        U R(                  R3                  5       n
[        R                  R                  US5      nU R5                  5       n[        R0                  " USU
-  5        [        R0                  " U R                  R7                  S5      SU
-  5        [        R0                  " [        R                  R                  US	5      SU-  5        U R9                  5         U(       a  X:X  a  [        R                  S
5        U
$ U R;                  5         U
$ ! [.         a     GN|f = f)Nz0Instance link already exists, not recreating it.r   z: r-   z%s
zprevious-datasourceinstance-idr   zprevious-instance-idzJNot re-loading configuration, instance id and datasource have not changed.)r  r   r>   r   resolveabsoluter@   r  r   r   r  r  r   r   r   r   r   rB   r   r   r-   r   r   	Exceptionr   r   previous_iidr   r   re   )r^   idirdestinationalready_instancifieddir_listddpr   previous_dsds_fniidiid_fnr'  s                rK   _reflect_cur_instanceInit._reflect_cur_instance  sZ     4::334<<>GGI*d4j.A.A.CCHHGHMM$**223MM$

 8 89 ++-AOOBGGLL12 ." ZZ!!&) $,,T__=tOT<0	--e4::<K Kv{+GGLL23V{5K	

 oo--/b-0((*-

..}=v|LGGLL34f6M	
 	K$5HH6 
 KKM
?  		s   %$L8 8
MMc                    U R                   b  U R                   $ U R                  R                  S5      n[        R                  R                  US5      n [        R                  " U5      R                  5       U l         [        R                  SU R                   5        U R                   $ ! [         a    [        U l          NCf = f)Nr   r#  zprevious iid found to be %s)r[   r>   rB   r   r   r   r   r   r   r&  r,   r@   rA   )r^   r-  r1  s      rK   r'  Init.previous_iid	  s    )%%%ZZ!!&)b-0	9!%!4!4V!<!B!B!DD 			/1C1CD!!!	  	9!8D	9s   )B+ +CCc                 ~    U R                  5       nU[        :H  =(       d    XR                  R                  5       :g  nU$ )zReturn true if this is a new instance.

If datasource has already been initialized, this will return False,
even on first boot.
)r'  r,   r-   r   )r^   previousrets      rK   is_new_instanceInit.is_new_instance  s?     $$&// =??::<< 	 
ra   c                      U R                  US9$ )zEoptionally load datasource from cache, otherwise discover
datasource
)r   )r	  )r^   r   s     rK   rm   
Init.fetch$  s     $$h$77ra   c                 "    U R                  5       $ rc   )r2  rd   s    rK   
instancifyInit.instancify*  s    ))++ra   c           	          [         R                  " U R                  U R                  U R                  U R
                  [        R                  " U R                  5      U R                  S9$ )N)r]   )	r   Cloudr-   r>   r.   ri   r   Runnersr]   rd   s    rK   cloudifyInit.cloudify-  sF    {{OOJJHHKKOODJJ']]
 	
ra   c                    U R                  U R                  R                  5       S5        U R                  U R                  R	                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        g )Nuserdata
vendordatavendordata2)
_store_rawdatar-   get_userdata_raw_store_processeddataget_userdata_store_raw_vendordataget_vendordata_rawget_vendordataget_vendordata2_rawget_vendordata2rd   s    rK   updateInit.update8  s    DOO<<>
K!!$//">">"@*M""OO..0,	
 	!!OO**,l	
 	""OO//1=	
 	!!OO++-}	
ra   c                     [         R                  " SSU R                  S9   U R                  c  [	        S5      eU R                  R                  U R                  5       S9  S S S 5        g ! , (       d  f       g = f)Nzsetup-datasourcezsetting up datasourcer   z!Datasource is None, cannot setup.)r9  )r%   r\   r]   r-   r  setupr9  rd   s    rK   setup_datasourceInit.setup_datasourceH  sb    $$ 7
 &"#FGGOO!!$2F2F2H!I
 
 
s   A A**
A8c                 ,   [         R                  " SSU R                  S9   U R                  c  [	        S5      eU R                  R                  U R                  U R                  5       S9  U R                  5         S S S 5        g ! , (       d  f       g = f)Nzactivate-datasourcezactivating datasourcerU  z$Datasource is None, cannot activate.)r.   r9  )	r%   r\   r]   r-   r  activater.   r9  r   rd   s    rK   activate_datasourceInit.activate_datasourceP  s|    $$!#==

 &"#IJJOO$$HHd.B.B.D %    "
 
 
s   AB
Bc                 b    Uc  Sn[         R                  " U R                  SU-  5      US5        g )Nra   z%s_rawr  )r   r   r  r^   r   r-   s      rK   rI  Init._store_rawdata]  s*    <D:(=>eLra   c                     Ub>  [        U5      [        [        [        4;  a   [	        S[        [        U5      5      -  5      e[        U[        5      (       a  [        R                  " U5      nU R                  X5        g )Nz'vendordata_raw is unsupported type '%s')	typebytesstrr   	TypeErrorr   r   
json_dumpsrI  r^  s      rK   rM  Init._store_raw_vendordatac  sd    T
5#t2D D9CT
OK  dD!! ++D1DD-ra   c                 n    Uc  Sn[         R                  " U R                  U5      [        U5      S5        g )Nr   r  )r   r   r  rc  )r^   processed_datar-   s      rK   rK  Init._store_processeddatan  s.    !NOOJ'^)<e	
ra   c                 (   Uc  0 nUR                  U R                  U R                  S.5        [        S0 UD6n[	        S0 UD6n[        S0 UD6nUU[        [        40 UD6[        [        40 UD6[        [        40 UD6U[        S0 UDSUUU/0D6/nU$ )N)r>   r-   sub_handlersr   )rR  r>   r-   r    r"   r   r#   r(   r)   r*   r!   )r^   optscloudconfig_handlershellscript_handlerboothook_handlerdef_handlerss         rK   _default_handlersInit._default_handlersv  s    <D"oo	
 5<t<4<t<.66(<t<(>>(:T:$  ('$
  ra   c                 &    U R                  SSS.S9$ )Nvendor_scriptsvendor_cloud_configscript_pathcloud_config_pathrl  rq  rd   s    rK   _default_vendordata_handlers!Init._default_vendordata_handlers  s%    %%/%: & 
 	
ra   c                 &    U R                  SSS.S9$ )Nrt  vendor2_cloud_configrv  ry  rz  rd   s    rK   _default_vendordata2_handlers"Init._default_vendordata2_handlers  s%    %%/%; & 
 	
ra   c                 T  ^^^^^ Uc  / nU R                   R                  S5      nU R                  S5      mUT4 HB  nU(       d  M  U[        R                  ;  d  M"  [        R                  R                  SU5        MD     U4S jn[        R                  " 5       mU" U5        U H2  nTR                  USS9n	U	(       d  M  [        R                  SX5        M4     U R                  5       mUUU4S jn
UUUUU4S	 jnUUU4S
 jn U
" 5         U" U5        U" 5         g! U" 5         f = f)zJ
Generalized handlers suitable for use with either vendordata
or userdata
Nr   r   c                 V  > U (       a$  [         R                  R                  U 5      (       d  g [        R                  " U 5      nUR                  5        H  u  p# [        R                  " US/SS/5      u  pEU(       d  [        R                  SUUU5        MD  [        R                  " US   5      n[        R                  " U5      nTR                  U5      nU(       a  [        R                  SUUU5        M  M     g ! [         a     [        R                   " [        SU5         M  f = f)Nr   
list_typeshandle_partzJCould not find a valid user-data handler named %s in file %s (searched %s)r   z(Added custom handler for %s [%s] from %sz"Failed to register handler from %s)r   r   isdirr   get_modules_from_diritemsr   find_moduler@   r   import_moduler   fixup_handlerregisterrA   r&  logexc)	r   potential_handlersfnamemod_namemod_locslooked_locsmodtypes
c_handlerss	           rK   register_handlers_in_dir3Init._do_handlers.<locals>.register_handlers_in_dir  s   rww}}T22!%!:!:4!@#5#;#;#=,4,@,@ 2$}(E-)H $A$!' !"00!=C"005C&//4E		F!!	 # $>0 ! KKA5s   <C>AC>>&D('D(F)	overwritez$Added default handler for %s from %sc                     > TR                  5        HJ  u  pUTR                  ;   a  M  [        R                  " UTT5        TR                  R	                  U5        ML     g rc   )r  initializedr   
call_beginr   _ctyper  r  r   	frequencys     rK   init_handlers(Init._do_handlers.<locals>.init_handlers  sQ    )//1*000 ##Cy9&&--c2  2ra   c                 `   > TTTTSU S.n[         R                  " T[         R                  US9  g )Nr   )r   
handlerdirr   r  handlercountexcluded)r   )r   walkwalker_callback)r  	part_datar  r   data_msgr  r(  s     rK   walk_handlers(Init._do_handlers.<locals>.walk_handlers  s8     '"& !"$I MM(H$<$<9Mra   c                    > TR                  5        HK  u  pUTR                  ;  a  M  TR                  R                  U5         [        R                  " UTT5        MM     g ! [
         a     [        R                  " [        SU5         My  f = f)NzFailed to finalize handler: %s)	r  r  remover   call_endr&  r   r  r@   r  s     rK   finalize_handlers,Init._do_handlers.<locals>.finalize_handlers	  s{    )//1j444 &&--c2L%%c4;  2 ! LKK%EsKLs   A""&BB)r>   rB   r  sysr   insertr   ContentHandlersr  r@   rA   rC  )r^   r  c_handlers_listr  r  cdirr,  r  r  r  r  r  r  r  r   r(  s    ` `         @@@rK   _do_handlersInit._do_handlers  s     Hzz##J/z* AqQchh&1%  	F ,,.
 	!&
 #C''u'=Eu		@%M # }}	3	N 	N"	L	 O(#s   D 	D'c                 $   [         R                  " SSU R                  S9   [        R                  " U R
                  SS5      (       a  U R                  U5        O[        R                  S5        S S S 5        [         R                  " SSU R                  S9   U R                  S	U5        S S S 5        [         R                  " S
SU R                  S9   U R                  SU5        S S S 5        U R                  5         [        R                  " U R
                  5      n[        US'   U R                  S5      US'   [        R                   " 5       US'   ["        R$                  " U R&                  R)                  S5      USS9  U R&                  R)                  S5      n [        R*                  " [        R,                  " U5      5      nUS   US'   US   US'   ["        R$                  " UUSS9  g ! , (       d  f       GN= f! , (       d  f       GN]= f! , (       d  f       GN4= f! [.        [0        4 a!  n[        R3                  SUU5         S nAg S nAf[4        R6                  [8        4 a!  n[        R3                  SUU5         S nAg S nAff = f)Nzconsume-user-datazreading and applying user-datarU  allow_userdataTz,allow_userdata = False: discarding user-datazconsume-vendor-dataz reading and applying vendor-datarG  zconsume-vendor-data2z!reading and applying vendor-data2rH  _docrh   rw   r   combined_cloud_configr  r  r   zESkipping write of system_info/features to %s. Unable to read file: %szDSkipping write of system_info/features to %s. Invalid JSON found: %s)r%   r\   r]   r   r   r.   _consume_userdatar@   rA   _consume_vendordatare   r8   r9   COMBINED_CLOUD_CONFIG_DOCrk   r   get_featuresr   r  r>   r   r  r   r   IOErrorr   jsonJSONDecodeErrorrd  )r^   r  combined_cloud_cfgjson_sensitive_fileinstance_jsonr   s         rK   consume_dataInit.consume_data  s9    $$,==

 ''2BDII&&y1		HI
 $$!.==

 $$\9=
 $$"/==

 $$]I>
 	
 "]]4884%>6" -1,=,=h,G=) *2)>)>)@:&  JJ""#:;	

 #jj445NO	 NN##$78M& (:-'Hm$$6z$Bj!  	
O
 

 

 
H ! 	KK+#	 $$i0 	KK*#	 	sH   AG/HH*H% /
G>
H
H"%J5IJ.J

Jc                     US:X  a8  U R                   R                  5       (       d  [        R                  S5        gSnOIUS:X  a8  U R                   R	                  5       (       d  [        R                  S5        gSnO[        S5      e[        R                  " U R                  U R                   / U R                  S	S
9nUR                  R                  U0 5      n[        U[        5      (       d  SS	0n[        R                  SX55        UR                  S5      nUR                  SS5      n[        R                  " U5      (       d  [        R                  SU5        g[        U[         5      (       a  ["        R$                  " SU S3SSS9  [        R                  SUU5        US:X  a+  U R                   R'                  5       nU R)                  5       n	O*U R                   R+                  5       nU R-                  5       n	U R/                  XX'S9  g)z8
Consume the vendordata and run the part handlers on it
rG  zno vendordata from datasourceNvendor_datarH  zno vendordata2 from datasourcevendor_data2z>vendor_source arg must be either 'vendordata' or 'vendordata2'F)r>   r-   r   r   include_vendorenabledz$invalid %s setting. resetting to: %sdisabled_handlersz%s consumption is disabled.zUse of string 'z!' for 'vendor_data:enabled' fieldz23.1zUse boolean value instead.)
deprecateddeprecated_versionextra_messagez)%s will be consumed. disabled_handlers=%s)r  )r-   rN  r@   rA   rP  r  r   r   rX   r.   r6   r   dictr   r   is_truerc  r   	deprecaterO  r{  rQ  r  r  )
r^   vendor_sourcer  cfg_name
_cc_mergervdcfgr  no_handlersvendor_data_msgr  s
             rK   r  Init._consume_vendordatal  s    L(??5577		9:$Hm+??6688		:;%H$ 
 ))++XX 

 ""8R0%&&&EKK6 ))I&ii 3T:||G$$II3]Cgs##,WI 6. .#):	 			7	
 L("oo<<>O"??AO"oo==?O"@@BO 	i 	 	
ra   c                 ~    U R                   R                  S5      nU R                  5       nU R                  X#U5        g)z0
Consume the userdata and run the part handlers
TN)r-   rL  rq  r  )r^   r  user_data_msgr  s       rK   r  Init._consume_userdata  s:     44T: 002 	-)Dra   c                 *    U(       a  SU;   a  US   $ U$ )z
Network configuration can be passed as a dict under a "network" key, or
optionally at the top level. In both cases, return the config.
networkr   )r^   r.   s     rK   _get_network_key_contentsInit._get_network_key_contents  s    
 9#y>!
ra   c           
         [         R                  R                  U R                  R	                  S5      S5      n[         R                  R                  U5      (       a  S U4$ [        R                  [        R                  " 5       [        R                  [        R                  " 5       [        R                  S [        R                  U R                  R                  S5      0nU R                   (       aB  [#        U R                   S5      (       a'  U R                   R$                  U[        R                  '   U R                   (       a  U R                   R&                  nO[(        R*                  R&                  nU H  n[-        U[        5      (       d  [.        R1                  SU5        M0  XB;  a  [.        R1                  SU5        MM  U R3                  X$   5      n[4        R6                  " U5      (       a  [.        R9                  SU5        S U4s  $ U(       d  M  XT4s  $    U R                  R                  SS5      (       d  [.        R1                  S	5        U R:                  R=                  5       [        R>                  4$ )
Nr   zupgraded-networkr  r  z7data source specifies an invalid network cfg_source: %sz;data source specifies an unavailable network cfg_source: %sznetwork config disabled by %sTzEmpty network config found) r   r   r   r>   rB   r   r+   CMD_LINEr$   read_kernel_cmdline_config	INITRAMFSread_initramfs_configDS
SYSTEM_CFGr.   r6   r-   r   r  network_config_sourcesr   
DataSourcer   r@   r   r  r   is_disabled_cfgrA   ri   generate_fallback_configFALLBACK)r^   disable_fileavailable_cfgsorder
cfg_sourcencfgs         rK   _find_networking_configInit._find_networking_config  s    ww||JJ  (*<
 77>>,'',''  (('*L*L*N))7+H+H+J""D**DHHLL,C	
 ??wt8HII.. .112 ??OO::E&&==EJj*=>> M /&
 11.2LMD""4((		9:Fj))t))+  , xx||It,,KK45KK002((
 	
ra   c                      [         R                  SU5        U R                  R                  R	                  U5        g ! [
         a   n[         R                  SU5         S nAg S nAff = f)Nz applying net config names for %szFailed to rename devices: %s)r@   rA   ri   
networkingapply_network_config_namesr&  r   )r^   r  r   s      rK   _apply_netcfg_namesInit._apply_netcfg_names  sP    	;II8&AKK""==fE 	;KK6::	;s   ;> 
A(A##A(c                     [        SS5      " [        R                  " U R                  R	                  S5      5      S[
        45      $ )N	Semaphorezsemaphore argsr   apply_network_config)r   r   FileSemaphoresr>   r   r*   rd   s    rK   _get_per_boot_network_semaphore$Init._get_per_boot_network_semaphore  s<    +'78""4::#9#9%#@A#X.
 	
ra   c                 h    U R                  5       nUR                  R                  " UR                  6 $ rc   )r  	semaphorehas_runargs)r^   r   s     rK   _network_already_configured Init._network_already_configured  s)    224}}$$chh//ra   c                   ^ ^	 SSK JnJn  T R                  5       u  pEUc  [        R                  SU5        gU 4S jm	U	U 4S jnT R                  bc  T R                  5       (       dN  U" 5       (       dB  T	" [        R                  5      (       d'  [        R                  S5        T R                  U5        gT R                  5       u  pET R                  U5        U(       a  U" UUR                  SSS	S
9  T R                  R                  R!                  U5        T R                  U5        [        R                  SUUU5        T R#                  5       n UR$                  R&                  " UR(                  6    T R                  R+                  XAS9sSSS5        $ ! , (       d  f       g= f! [,        R.                   a   n[        R1                  SU5         SnAgSnAf[2         a#    [        R5                  ST R                  5         gf = f)zApply the network config.

Find the config, determine whether to apply it, apply it via
the distro, and optionally bring it up
r   )
SchemaTypevalidate_cloudconfig_schemaNz network config is disabled by %sc                    > [        TR                  TR                  U [        R                  S9=(       a    TR                  R                  U /5      $ )N)r-   r.   r/   r0   )rL   r-   r.   r   NETWORKupdate_metadata_if_supported)
event_typer^   s    rK   "event_enabled_and_metadata_updatedEInit.apply_network_config.<locals>.event_enabled_and_metadata_updated(  sG    '??HH", ((	 M
 //>>
|LMra   c                  h   > TR                  5       (       + =(       a    T " [        R                  5      $ rc   )r  r   BOOT)r  r^   s   rK   should_run_on_boot_event;Init.apply_network_config.<locals>.should_run_on_boot_event0  s)    4466 G6y~~Fra   zWNo network config applied. Neither a new instance nor datasource network update allowedFT)configschema_typestrictlog_detailslog_deprecationsz5Applying network configuration from %s bringup=%s: %s)bring_upz@Unable to render networking. Network config is likely broken: %sz_distro '%s' does not implement apply_network_config. networking may not be configured properly.)cloudinit.config.schemar  r  r  r@   r  r-   r9  r   BOOT_LEGACYrA   r  r   NETWORK_CONFIGri   r  wait_for_physdevsr  r  lockr  r  r   RendererNotFoundErrorr   NotImplementedErrorr   )
r^   r  r  r  r  srcr  r   r   r  s
   `        @rK   r  Init.apply_network_config  s   	

 224>HH7=	M	 OO'((**,..6y7L7LMMII9
 $$V, 224''/'&55!!% 	008 	  ( 	C		
 224	##SXX.{{77 8  /.. (( 	II$
 " 	KK=
 	s<   #F( 4F	F( 
F%!F( %F( (H<G-HH)rW   rY   rX   r[   r-   rP   rZ   r]   )NN)Frc   )r   )F__name__
__module____qualname____firstlineno__r
   r	   rc  r_   re   propertyri   r.   rk   r>   r   r   r   staticmethodintr   r   rx   r   r  r   r   r   r   r   r   r  r	  r  r  r   r2  r'  r9  rm   r>  rC  rR  rW  r[  rI  rM  rK  r   Handlerrq  r{  r  r  r)   r  r  r  r   r   r   r  r   r+   r  r  r  r  r  r  __static_attributes__r   ra   rK   rN   rN      s   !c 3 !,    / /  && C    #J2:&$ E
$F4.G,>,> .`.
< <4;z"8,	

 J#M	.
d83C3C.D @

 >Bt l &2 N
` <H L
\ +7 EeUD6H0I 4
	uUE4'(%0CS0H*II	J4
l;
0T 0Yra   rN   r   c                 j    [         R                  " [        R                  R	                  U S5      5      $ )Nz	cloud.cfg)r   	read_confr   r   r   )r   s    rK   read_runtime_configr+  t  s     >>"'',,w<==ra   r   c                    [         R                  " [         R                  " 5       [         R                  " [        US9[        U 5      [         R                  " 5       /SS9$ )Nr   T)reverse)r   r7   get_builtin_cfgread_conf_with_confdr&   r+  read_conf_from_cmdline)r   r   s     rK   r   r   x  sW       "%%1C  ('')	
  ra   )Kr8   r  loggingr   r  collectionsr   
contextlibr   pathlibr   typingr   r   r   r	   r
   r   r   r   	cloudinitr   r   r   r   r   r   r   r   r   r   r   r   cloudinit.configr   r   cloudinit.eventr   r   r   cloudinit.handlers.boot_hookr   cloudinit.handlers.cloud_configr    !cloudinit.handlers.jinja_templater!   cloudinit.handlers.shell_scriptr"   ,cloudinit.handlers.shell_script_by_frequencyr#   cloudinit.netr$   cloudinit.reportingr%   cloudinit.settingsr&   r'   r(   r)   r*   cloudinit.sourcesr+   	getLoggerr   r@   r,   r  r  r  r  rL   rN   rc  r+  r   r   ra   rK   <module>rC     s      	 
 "   I I I    * E E = B F B " &  2!3 F B""B	B !B 	B
 
BJj jZ> > ;? s 4 ra   