+
    iѥ                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
HtHtHtHtHtHtHt ^ RIHtHtHtHtHtHtHtHtHtHtHtHt ^ RIH t H!t! ^ RI"H#t#H$t$H%t% ^ RI&H't' ^ R	I(H)t) ^ R
I*H+t+ ^ RI,H-t- ^ RI.H/t/ ^ RI0H1t1 ^ RI2H3t3 ^ RI4H5t5H6t6H7t7H8t8H9t9 ^ RI:H;t; ]Px                  ! ]=4      t>Rt? ! R R4      t@RtAR R ltB ! R R4      tCR R ltDRR/R R lltER# )    N)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_IDc                   &   a  ] tR t^9t o R tRtV tR# )
_Semaphorec                    Wn         W n        R # N)	semaphoreargs)selfr0   r1   s   &&&2/usr/lib/python3/dist-packages/cloudinit/stages.py__init___Semaphore.__init__:   s    "	    )r1   r0   N)__name__
__module____qualname____firstlineno__r4   __static_attributes____classdictcell____classdict__s   @r3   r-   r-   9   s      r6   r-   zAggregated 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.c          
      h    V ^8  d   QhR\         P                  R\        R\        R\        R\
        /# )   
datasourcecfgevent_source_typescopereturn)r   
DataSourcedictr   r   bool)formats   "r3   __annotate__rJ   G   sG     B B""B	B !B 	B
 
Br6   c                   V P                   p\        VP                  R/ 4      4      p\        P                  ! \
        P                  ! V4      \
        P                  ! V4      .4      p\        P                  V P                  P                  V\        4       4      9   d   \        P                  ! V P                  4      pVP                  VR,          9   d   \        P                  RV\        P                  V P                  P!                  R4      4       VP                  V4      '       g   \        4       Wc&   Wc,          P#                  \        P                  4       \        P                  RV4       V.pV U	u. uF  qP                  NK  	  p
p	V F=  pW&P                  V. 4      9   g   K  \        P                  RVP                  V4        R# 	  \        P                  RW4       R	# u up	i )
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)rA   rB   rC   rD   default_eventsuser_eventsallowedhotplug_enabled_filerM   sscope_values	evt_scopes   &&&&        r3   update_event_enabledrd   G   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   ;G,c                   $  a  ] tR t^t o R>V 3R lR lltR t]R 4       t]R 4       tR t	]R 4       t
R	 tR?R
 ltR t]V 3R lR l4       tR tR@R ltR tV 3R lR ltR tR tR tR tV 3R lR ltR tR@R ltV 3R lR ltR t]V 3R lR l4       tR  tR! tRAR" lt R# t!R$ t"R% t#R& t$R' t%R( t&R) t'R* t(R@V 3R+ lR, llt)R- t*R. t+R@R/ lt,]-3R0 lt.]-3R1 lt/]-3R2 lt0V 3R3 lR4 lt1V 3R5 lR6 lt2R7 t3V 3R8 lR9 lt4V 3R: lR; lt5R< t6R=t7V t8R# )BInitNc                @   < V ^8  d   QhRS[ S[S[,          ,          /# )r@   ds_deps)r	   r   str)rI   r>   s   "r3   rJ   Init.__annotate__   s     ! !c 3 !r6   c                    Ve   Wn         M%\        P                  \        P                  .V n         / V n        R V n        R V n        R V n        RV n        R V n	        Vf   \        P                  ! RRRR7      pW n        R # )NFzinit-reporterz	init-desc)namedescriptionreporting_enabled)rh   r   DEP_FILESYSTEMDEP_NETWORK_cfg_paths_distrorA   ds_restored_previous_iidr$   ReportEventStackreporter)r2   rh   rw   s   &&&r3   r4   Init.__init__   sw    "L#22G4G4GHDL$&	/3158< ,0..$'"'H
 !r6   c                0    / V n         R V n        R V n        R # r/   )rq   rr   rs   r2   s   &r3   _resetInit._reset   s    	r6   c                   V P                   '       g   V P                  R 4      pVP                  RR4      p\        P                  ! V4      p\
        P                  RV4       V! W!V P                  4      V n         V P                  e7   V P                   V P                  n	        V P                  V P                  n        V P                   # )systemdistroubuntuzUsing distro class %s)rs   _extract_cfgpopr   fetchrY   rZ   rW   rA   r   rB   sys_cfg)r2   system_configdistro_name
distro_clss   &   r3   r   Init.distro   s    ||| --h7M'++Hh?K {3JII-z:%k$**MDL *)-&*.(('||r6   c                $    V P                  R 4      # )
restricted)r   rz   s   &r3   rB   Init.cfg   s      ..r6   c                   V P                  4        \        P                  ! V P                  4      pVR 8X  d   VP	                  RR4       V# VR8X  d   \
        P                  ! VR/ 4      pV# VR8X  d   \
        P                  ! VR/ 4      pV# )r   system_infoNr~   rW   )r   )r   rW   )read_cfgrQ   rR   rq   r   r   get_cfg_by_path)r2   restrictionocfgs   && r3   r   Init._extract_cfg   s    }}TYY',&HH]D)
 	 H$''.>CD  G#''.FKDr6   c                    V P                   '       g7   V P                  R 4      p\        P                  ! WP                  4      V n         V P                   # )rW   )rr   r   r   PathsrA   )r2   	path_infos   & r3   rW   
Init.paths   s9    {{{))'2I!--	??CDK{{r6   c                   V P                   P                  pV P                   P                  pV\        P                  P                  VR 4      \        P                  P                  VR R4      \        P                  P                  VR R4      \        P                  P                  VR R4      \        P                  P                  VR R4      \        P                  P                  VR4      \        P                  P                  VR4      \        P                  P                  VR4      \        P                  P                  VR4      \        P                  P                  VR	4      \        P                  P                  VR4      .pV# )
scriptszper-instancezper-oncezper-bootvendorseed	instancesr   semdata)rW   	cloud_dirrun_dirospathjoin)r2   c_dirr   initial_dirss   &   r3   _initial_subdirsInit._initial_subdirs   s    

$$**$$GGLL	*GGLL	>:GGLL	:6GGLL	:6GGLL	84GGLL'GGLL,GGLL
+GGLL&GGLL'GGLL%(
 r6   c                    V P                   P                  .pV'       d&   VP                  V P                   P                  4       V F  p\        P
                  ! V4       K  	  \        V4      # r/   )rW   boot_finishedappendinstance_linkr   del_filelen)r2   rm_instance_lnkrm_listfs   &&  r3   purge_cacheInit.purge_cache   sM    ::++,NN4::334AMM! 7|r6   c                &    V P                  4        R # r/   )_initialize_filesystemrz   s   &r3   
initializeInit.initialize   s    ##%r6   c                ,   < V ^8  d   QhRS[ RS[ RS[ /# )r@   mode_1mode_2rE   )int)rI   r>   s   "r3   rJ   rj      s"      C   r6   c                    W,          # r/    )r   r   s   &&r3   _get_strictest_modeInit._get_strictest_mode   s
    r6   c                   R p\         P                  ! V P                  4       4       \         P                  ! V P                  R4      pV'       Ed   \        \        4      ;_uu_ 4        V P                  R \         P                  ! V4      4      pRRR4       \         P                  ! W!RR7       V P                  P                  R4      pV'       g   / p\        V\        4      '       g   V.pRpV F4  p\         P                  ! V4      w  rg \         P                  ! W&V4        R# 	  \        P!                  RVRP#                  V4      V4       R# R#   + '       g   i     L; i  \         d   pTp Rp?K  Rp?ii ; i)i  def_log_fileNF)preserve_modesyslog_fix_permsz,Failed changing perms on '%s'. tried: %s. %s,)r   ensure_dirsr   get_cfg_option_strrB   r   OSErrorr   get_permissionsensure_filerO   
isinstancelistextract_usergroupchownbynamerY   warningr   )	r2   modelog_filepermserrorpermuges	   &        r3   r   Init._initialize_filesystem   s+   ..01**488^D8 '""//4//9 # X5AHHLL!34EeT**E--d3$$X!4	  KK>	3  #"&  Es$   ('EE'E$	'E?2E::E?c                Z    V P                   '       g   V P                  V4      V n         R # R # r/   )rq   	_read_cfg)r2   	extra_fnss   &&r3   r   Init.read_cfg  s     yyyy1DI r6   c                    V P                  V/ 4      pVP                  R/ 4      P                  R/ 4      pVP                  R4      \        R39   d   V# V P                  W4      # )z read and merge our configurationr   rW   r   N)_read_bootstrap_cfgrO   r&   )r2   r   initial_configrW   s   &&  r3   r   Init._read_cfg  sf     11)R@""="599'2F 99YOT#::!! ''	99r6   c                    < V ^8  d   QhRS[ /# )r@   bootstrapped_configrG   )rI   r>   s   "r3   rJ   rj   0  s      $ r6   c           
         \         P                  ! W P                  4      pVP                  R 4      p\         P                  ! VV P                  V\        VP                  VR7      R7      pVP                  # )instance_data_sensitiveinstance_data_file)rW   rA   additional_fnsbase_cfg)r   r   rA   get_runpathConfigMergerfetch_base_configr   rB   )r2   r   r   no_cfg_pathsr   mergers   &&&   r3   r   Init._read_bootstrap_cfg0  sh    }}%8//J)55%
 %%$&$$9K	
 zzr6   c                `    \         P                  ! V P                  P                  R 4      4      # )obj_pkl)r   pkl_loadrW   get_ipath_currz   s   &r3   _restore_from_cacheInit._restore_from_cache?  s$     

 8 8 CDDr6   c                *   \         P                  ! V P                  R R4      '       d3   \         P                  ! V P                  P                  R4      RRR7       \        P                  ! V P                  V P                  P                  R4      4      # )manual_cache_cleanFmanual_clean_markerw )omodecontentr   )	r   get_cfg_option_boolrB   
write_filerW   r   r   	pkl_storedsrz   s   &r3   _write_to_cacheInit._write_to_cacheE  sk    ##DHH.BEJJ OO

(()>?
   $***B*B9*MNNr6   c                   V P                   P                  R 4      ;'       g    . pR\        P                  ! \        4      3 F  pW!9  g   K  VP                  V4       K  	  V P                   P                  R4      ;'       g    . pW13# )datasource_pkg_listr   datasource_list)rB   rO   r   obj_namer   r   )r2   pkg_listncfg_lists   &   r3   _get_datasourcesInit._get_datasourcesP  so    88<< 56<<"j))'23A " 4 88<< 1288b##r6   c                *   VR
9  d   \        RV,          4      hV P                  4       pV'       g   R# V P                  P                  R4      p\        P
                  P                  V4      '       d&   \        P                  ! V4      P                  4       pMRpWBP                  4       8X  d   VRV,          3# VR8X  d   VRV,          3# \        VR4      '       d-   VP                  V P                  4      '       d   VRV,          3# RR	V,          3# )checktrustz!Unexpected value for existing: %sNinstance_idz&restored from cache with run check: %szrestored from cache: %scheck_instance_idzrestored from checked cache: %szcache invalid in datasource: %s)r
  r  )Nzno cache found)
ValueErrorr   rW   r   r   r   existsr   load_text_filestripget_instance_idhasattrr  rB   )r2   existingr   
run_iid_fnrun_iids   &&   r3   _restore_from_checked_cache Init._restore_from_checked_cacheZ  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Er6   c                4   < V ^8  d   QhRS[ P                  /# r@   rE   r   rF   )rI   r>   s   "r3   rJ   rj   t  s     . .G,>,> .r6   c           	     F   V P                   e   V P                   # \        P                  ! RRV,          V P                  R7      ;_uu_ 4       pV P	                  V4      w  r4WBn        \        V4      V n        \        P                  VP
                  4       R R R 4       X'       g    V P                  4       w  rV\        P                  ! V P                  V P                  V P                  \         P"                  ! V P$                  4      VVV P                  4      w  r7\&        P(                  ! V P                  P*                  4       \        P-                  RWs4       W0n         V P5                  4        V#   + '       g   i     L; i  \        P.                   d   pTR8w  d   ThT P1                  4       pT'       d2   TP3                  4       '       d   \        P-                  RT4        R p?L\&        P(                  ! T P                  P*                  4       ThR p?ii ; i)Nzcheck-cachez"attempting to read from cache [%s])rl   rm   parentzLoaded datasource %s - %sr
  z3Restored fallback datasource from checked cache: %s)rA   r$   rv   rw   r  rm   rH   rt   rY   rZ   r  r   find_sourcerB   r   rW   rQ   rR   rh   r   r   r   infoDataSourceNotFoundExceptionr   check_if_fallback_is_allowedr{   )	r2   r  myrepr   descr  r  dsnamer   s	   &&       r3   _get_data_sourceInit._get_data_sourcet  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s8   A	E5'B6F 5F	H  H>HH/,HH c                
    . RO# )r   )r   r   r   r   rz   s   &r3   _get_instance_subdirsInit._get_instance_subdirs  s    --r6   c                b    V P                   P                  V4      pV'       g   \        R 4      hV# )zCNo instance directory is available. Has a datasource been fetched??)rW   	get_ipathRuntimeError)r2   subnameinstance_dirs   && r3   
_get_ipathInit._get_ipath  s5     zz++G43  r6   c                    < V ^8  d   QhRS[ /# )r@   netcfgr   )rI   r>   s   "r3   rJ   rj     s     < < <r6   c                l   \         P                  P                  V P                  P                  4      '       g   R# V P                  P                  R4      pV P                  P                  R4      p\         P                  P                  V4      '       dI   V\        P                  ! \        P                  ! V4      4      8w  d   \        P                  ! W!RR7       M\        P                  ! W!RR7       \         P                  P                  V4      '       g   \        P                  ! W#4       R# R# )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   islinkrW   r   r   r   r  r   	load_jsonr  r   
write_jsonsym_link)r2   r2  ncfg_instance_pathnetwork_links   &&  r3   _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,; ,r6   c                   V P                  4       p\        V P                  P                  4      P	                  4       P                  4       pV\        V4      P                  4       8H  pV'       d   \        P                  R 4       MT\        P                  ! V P                  P                  4       \        P                  ! WP                  P                  4       . pV P                  4        F1  pVP                  \        P                  P                  W4      4       K3  	  \        P                   ! V4       V P                  P#                  R4      p\$        P&                  ! V P(                  4      : RV P(                  : 2pRp\        P                  P                  VR4      p	 \        P*                  ! V	4      P-                  4       pV'       g   Tp\        P0                  ! V	RV,          4       \        P0                  ! \        P                  P                  VR4      RV,          4       V P(                  P3                  4       p
\        P                  P                  VR4      pV P5                  4       p\        P0                  ! VRV
,          4       \        P0                  ! V P                  P7                  R4      RV
,          4       \        P0                  ! \        P                  P                  VR	4      RV,          4       V P9                  4        V'       d   W8X  d   \        P                  R
4       V
# V P;                  4        V
#   \.         d     ELi ; i)z0Instance link already exists, not recreating it.r   z: NrA   z%s
zprevious-datasourceinstance-idr  zprevious-instance-idzJNot re-loading configuration, instance id and datasource have not changed.)r/  r   rW   r   resolveabsoluterY   r  r   r   r:  r(  r   r   r   r   r   r[   r   r  r   r  r  	Exceptionr   r  previous_iidr   r   r{   )r2   idirdestinationalready_instancifieddir_listddpr   previous_dsds_fniidiid_fnrD  s   &            r3   _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!!&) $,,TWW5tww?T<0	--e4::<K Kv{+GGLL23V{5K	

 gg%%'b-0((*-

..}=v|LGGLL34f6M	
 	K$5HH6 
 KKM
?  		s   &$M MMc                4   < V ^8  d   QhRS[ P                  /# r  r  )rI   r>   s   "r3   rJ   rj     s     
 
G&& 
r6   c                T    V P                   '       g   \        R4      hV P                   # )a  ds has a reference to the DataSource object

self.datasource can contain a DataSource or None
self.ds is preferred for any code path that is known to require an
initialized DataSource, basically any code besides the initial
bootstrapping of various objects.
zDatasource is not initialized.)rA   r,  rz   s   &r3   r   Init.ds
  s#     ?@@r6   c                   V P                   e   V P                   # V P                  P                  R4      p\        P                  P                  VR4      p \        P                  ! V4      P                  4       V n         \        P                  RV P                   4       V P                   #   \         d    \        T n          LDi ; i)Nr   r@  zprevious iid found to be %s)ru   rW   r[   r   r   r   r   r  r  rC  r+   rY   rZ   )r2   rJ  rN  s   &  r3   rD  Init.previous_iid  s    )%%%ZZ!!&)b-0	9!%!4!4V!<!B!B!DD 			/1C1CD!!!	  	9!8D	9s   )B, ,CCc                |    V P                  4       pV\        8H  ;'       g    WP                  P                  4       8g  # )zReturn true if this is a new instance.

If datasource has already been initialized, this will return False,
even on first boot.
)rD  r+   r   r  )r2   previouss   & r3   is_new_instanceInit.is_new_instance%  s=     $$&// 5 5772244	
r6   c                &    V P                  VR7      # )zEoptionally load datasource from cache, otherwise discover
datasource
)r  )r%  )r2   r  s   &&r3   r   
Init.fetch1  s     $$h$77r6   c                "    V P                  4       # r/   )rO  rz   s   &r3   
instancifyInit.instancify7  s    ))++r6   c           	         \         P                  ! V P                  V P                  V P                  V P
                  \        P                  ! V P                  4      V P                  R 7      # ))rw   )	r   Cloudr   rW   rB   r   r   Runnersrw   rz   s   &r3   cloudifyInit.cloudify:  sF    {{GGJJHHKKOODJJ']]
 	
r6   c                   V P                  V P                  P                  4       R 4       V P                  V P                  P	                  4       R 4       V P                  V P                  P                  4       R4       V P                  V P                  P                  4       R4       V P                  V P                  P                  4       R4       V P                  V P                  P                  4       R4       R# )userdata
vendordatavendordata2N)
_store_rawdatar   get_userdata_raw_store_processeddataget_userdata_store_raw_vendordataget_vendordata_rawget_vendordataget_vendordata2_rawget_vendordata2rz   s   &r3   updateInit.updateE  s    DGG446
C!!$''"6"6"8*E""477#=#=#?N!!$''"8"8":LI""GG'')=	
 	!!$''"9"9";]Kr6   c                    \         P                  ! R RV P                  R7      ;_uu_ 4        V P                  P	                  V P                  4       R7       RRR4       R#   + '       g   i     R# ; i)zsetup-datasourcezsetting up datasourcer  )rX  N)r$   rv   rw   r   setuprX  rz   s   &r3   setup_datasourceInit.setup_datasourceO  sS    $$ 7
 
 GGMM$*>*>*@MA
 
 
 
s   +A!!A2	c                    \         P                  ! R RV P                  R7      ;_uu_ 4        V P                  P	                  V P
                  V P                  4       R7       V P                  4        RRR4       R#   + '       g   i     R# ; i)zactivate-datasourcezactivating datasourcert  )rB   rX  N)r$   rv   rw   r   activaterB   rX  r   rz   s   &r3   activate_datasourceInit.activate_datasourceU  sp    $$!#==
 

 GGHHd.B.B.D     "
 
 
 
s   AA<<B	c                n    Vf   Rp\         P                  ! V P                  RV,          4      VR4       R # )Nr6   z%s_rawr5  )r   r   r/  r2   r   rA   s   &&&r3   rh  Init._store_rawdata`  s*    <D:(=>eLr6   c                   VeD   \        V4      \        \        \        39  d%   \	        R\        \        V4      4      ,          4      h\        V\        4      '       d   \        P                  ! V4      pV P                  W4       R # )Nz'vendordata_raw is unsupported type '%s')	typebytesri   r   	TypeErrorr   r   
json_dumpsrh  r}  s   &&&r3   rl  Init._store_raw_vendordataf  sd    T
5#t2D D9CT
OK  dD!! ++D1DD-r6   c                r    Vf   Rp\         P                  ! V P                  V4      \        V4      R4       R # )Nr   r5  )r   r   r/  ri   )r2   processed_datarA   s   &&&r3   rj  Init._store_processeddataq  s.    !NOOJ'^)<e	
r6   c                D   < V ^8  d   QhRS[ S[P                  ,          /# r  )r   r   Handler)rI   r>   s   "r3   rJ   rj   y  s      d83C3C.D r6   c                ,   Vf   / pVP                  RV P                  RV P                  /4       \        R/ VB p\	        R/ VB p\        R/ VB pVV\        \        3/ VB \        \        3/ VB \        \        3/ VB V\        R/ VBRVVV./B .pV# )NrW   rA   sub_handlersr   )rq  rW   r   r   r!   r   r"   r'   r(   r)   r    )r2   optscloudconfig_handlershellscript_handlerboothook_handlerdef_handlerss   &&    r3   _default_handlersInit._default_handlersy  s    <Ddgg	
 5<t<4<t<.66(<t<(>>(:T:$  ('$
  r6   c                .    V P                  R RRR/R7      # )script_pathvendor_scriptscloud_config_pathvendor_cloud_configr  r  rz   s   &r3   _default_vendordata_handlers!Init._default_vendordata_handlers  s+    %%/#%: & 
 	
r6   c                .    V P                  R RRR/R7      # )r  r  r  vendor2_cloud_configr  r  rz   s   &r3   _default_vendordata2_handlers"Init._default_vendordata2_handlers  s+    %%/#%; & 
 	
r6   c                d  aaaaa Vf   . pV P                   P                  R4      pV P                  R4      oVS3 FD  pV'       g   K  V\        P                  9  g   K$  \        P                  P                  ^ V4       KF  	  V3R lp\        P                  ! 4       oV! V4       V F6  pSP                  VRR7      p	V	'       g   K   \        P                  RW4       K8  	  V P                  4       oVVV3R lp
VVVVV3R lpVVV3R	 lp V
! 4        V! V4       V! 4        R#   T! 4        i ; i)
zJ
Generalized handlers suitable for use with either vendordata
or userdata
Nr   c                 l  < V '       d&   \         P                  P                  V 4      '       g   R # \        P                  ! V 4      pVP                  4        F  w  r# \        P                  ! VR.RR.4      w  rEV'       g   \        P                  RVVV4       KE  \        P                  ! V^ ,          4      p\        P                  ! V4      pSP                  V4      pV'       d   \        P                  RVVV4       K  K  	  R #   \         d!    \        P                   ! \        RT4        K  i ; i)Nr   
list_typeshandle_partzJCould not find a valid user-data handler named %s in file %s (searched %s)z(Added custom handler for %s [%s] from %sz"Failed to register handler from %s)r   r   isdirr   get_modules_from_diritemsr   find_modulerY   r   import_moduler   fixup_handlerregisterrZ   rC  logexc)	r   potential_handlersfnamemod_namemod_locslooked_locsmodtypes
c_handlerss	   &       r3   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   =DAD(D'D32D3F)	overwritez$Added default handler for %s from %sc                     < SP                  4        FK  w  rVSP                  9   d   K  \        P                  ! VSS4       SP                  P	                  V4       KM  	  R # r/   )r  initializedr   
call_beginr   _ctyper  r  r   	frequencys     r3   init_handlers(Init._do_handlers.<locals>.init_handlers  sQ    )//1*000 ##Cy9&&--c2  2r6   c                 r   < R SRSRSRSR^ RV /p\         P                  ! S\         P                  VR7       R# )r   
handlerdirr   r  handlercountexcluded)r   N)r   walkwalker_callback)r  	part_datar  r   data_msgr  rE  s   & r3   walk_handlers(Init._do_handlers.<locals>.walk_handlers  sD     JdY HI MM(H$<$<9Mr6   c                  $  < SP                  4        FL  w  rVSP                  9  d   K  SP                  P                  V4        \        P                  ! VSS4       KN  	  R#   \
         d!    \        P                  ! \        R T4        K|  i ; i)zFailed to finalize handler: %sN)	r  r  remover   call_endrC  r   r  rY   r  s     r3   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)rW   r[   r/  sysr   insertr   ContentHandlersr  rY   rZ   rb  )r2   r  c_handlers_listr  r  cdirrI  r  r  r  r  r  r  r  r   rE  s   &f&f&        @@@r3   _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                   \         P                  ! R RV P                  R7      ;_uu_ 4        \        P                  ! V P
                  RR4      '       d   V P                  V4       M\        P                  R4       RRR4       \         P                  ! RRV P                  R7      ;_uu_ 4        V P                  R	V4       RRR4       \         P                  ! R
RV P                  R7      ;_uu_ 4        V P                  RV4       RRR4       V P                  4        \        P                  ! V P
                  4      p\        VR&   V P                  R4      VR&   \        P                   ! 4       VR&   \"        P$                  ! V P&                  P)                  R4      VRR7       V P&                  P)                  R4      p \        P*                  ! \        P,                  ! V4      4      pTR,          TR&   TR,          TR&   \"        P$                  ! TTRR7       R#   + '       g   i     EL; i  + '       g   i     EL{; i  + '       g   i     ELI; i  \.        \0        3 d#   p\        P3                  RTT4        Rp?R# Rp?i\4        P6                  \8        3 d#   p\        P3                  RTT4        Rp?R# Rp?ii ; i)zconsume-user-datazreading and applying user-datart  allow_userdataTz,allow_userdata = False: discarding user-dataNzconsume-vendor-dataz reading and applying vendor-datarf  zconsume-vendor-data2z!reading and applying vendor-data2rg  _docr~   r   r   combined_cloud_configr5  r6  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$   rv   rw   r   r   rB   _consume_userdatarY   rZ   _consume_vendordatar{   rQ   rR   COMBINED_CLOUD_CONFIG_DOCr   r   get_featuresr   r9  rW   r   r8  r  r   IOErrorr   jsonJSONDecodeErrorr  )r2   r  combined_cloud_cfgjson_sensitive_fileinstance_jsonr   s   &&    r3   consume_dataInit.consume_data  sW    $$,==
 

 ''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*#	 	sN   AH /H45I*I  H1	4I	I	K
-J

K
'K
(KK
c                J   VR8X  d;   V P                   P                  4       '       g   \        P                  R4       R# RpMLVR8X  d;   V P                   P	                  4       '       g   \        P                  R4       R# RpM\        R4      h\        P                  ! V P                  V P                   . V P                  R	R
7      pVP                  P                  V/ 4      p\        V\        4      '       g   RR	/p\        P                  RW54       VP                  R4      pVP                  RR4      p\        P                  ! V4      '       g   \        P                  RV4       R# \        V\         4      '       d   \"        P$                  ! RV R2RRR7       \        P                  RVV4       VR8X  d,   V P                   P'                  4       pV P)                  4       p	M*V P                   P+                  4       pV P-                  4       p	V P/                  WW'R7       R# )z8
Consume the vendordata and run the part handlers on it
rf  zno vendordata from datasourceNvendor_datarg  zno vendordata2 from datasourcevendor_data2z>vendor_source arg must be either 'vendordata' or 'vendordata2'F)rW   rA   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   rm  rY   rZ   ro  r,  r   r   rr   rB   rO   r   rG   r   r   is_trueri   r   	deprecatern  r  rp  r  r  )
r2   vendor_sourcer  cfg_name
_cc_mergervdcfgr  no_handlersvendor_data_msgr  s
   &&&       r3   r  Init._consume_vendordatao  s    L(77--//		9:$Hm+77..00		:;%H$ 
 ))++wwXX 

 ""8R0%&&&EKK6 ))I&ii 3T:||G$$II3]Cgs##,WI 6. .#):	 			7	
 L("gg446O"??AO"gg557O"@@BO 	i 	 	
r6   c                    V P                   P                  R4      pV P                  4       pV P                  W#V4       R# )z0
Consume the userdata and run the part handlers
TN)r   rk  r  r  )r2   r  user_data_msgr  s   &&  r3   r  Init._consume_userdata  s:     ,,T2 002 	-)Dr6   c                8   < V ^8  d   QhRS[ S[S[R3,          /# r@   rE   N)r   r   r   )rI   r>   s   "r3   rJ   rj     s       eUD6H0I r6   c                6    V'       d   RV9   d
   VR,          # V# )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   )r2   rB   s   &&r3   _get_network_key_contentsInit._get_network_key_contents  s    
 9#y>!
r6   c                d   < V ^8  d   QhRS[ S[S[S[R3,          S[S[S[3,          3,          /# r  )r   r   r   r   r*   ri   )rI   r>   s   "r3   rJ   rj     s6     2
 2
	uUE4'(%0CS0H*II	J2
r6   c           
        \         P                  P                  V P                  P	                  R 4      R4      p\         P                  P                  V4      '       d   RV3# \        P                  \        P                  ! 4       \        P                  \        P                  ! 4       \        P                  R\        P                  V P                  P                  R4      /pV P                   '       d[   V P"                  P$                  p\'        V P"                  R4      '       d(   V P"                  P(                  V\        P                  &   M\*        P,                  P$                  pV F  p\/        V\        4      '       g   \0        P3                  RV4       K1  WB9  d   \0        P3                  RV4       KO  V P5                  W$,          4      p\6        P8                  ! V4      '       d   \0        P;                  RV4       RV3u # V'       g   K  WT3u # 	  V P                  P                  RR4      '       g   \0        P3                  R	4       V P<                  P?                  4       \        P@                  3# )
r   zupgraded-networkNr  r4  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   rW   r[   r  r*   CMD_LINEr#   read_kernel_cmdline_config	INITRAMFSread_initramfs_configDS
SYSTEM_CFGrB   rO   rA   r   network_config_sourcesr  r4  r   rF   r   rY   r   r  r   is_disabled_cfgrZ   r   generate_fallback_configFALLBACK)r2   disable_fileavailable_cfgsorder
cfg_sourcencfgs   &     r3   _find_networking_configInit._find_networking_config  s    ww||JJ  (*<
 77>>,'',''  (('*L*L*N))7+H+H+J""D**DHHLL,C	
 ???GG22Etww 0119=9O9O2556&&==EJj*=>> M /&
 11.2LMD""4((		9:Fj))t))+  , xx||It,,KK45KK002((
 	
r6   c                     \         P                  R V4       V P                  P                  P	                  V4       R#   \
         d"   p\         P                  RT4        Rp?R# Rp?ii ; i)z applying net config names for %szFailed to rename devices: %sN)rY   rZ   r   
networkingapply_network_config_namesrC  r   )r2   r2  r   s   && r3   _apply_netcfg_namesInit._apply_netcfg_names  sP    	;II8&AKK""==fE 	;KK6::	;s   ;? A+
A&&A+c                    < V ^8  d   QhRS[ /# r  )r-   )rI   r>   s   "r3   rJ   rj     s     
 
 
r6   c                    \        \        P                  ! V P                  P	                  R 4      4      R\
        34      # )r   apply_network_config)r-   r   FileSemaphoresrW   r   r)   rz   s   &r3   _get_per_boot_network_semaphore$Init._get_per_boot_network_semaphore  s4    ""4::#9#9%#@A#X.
 	
r6   c                    < V ^8  d   QhRS[ /# r  )rH   )rI   r>   s   "r3   rJ   rj     s     0 0T 0r6   c                j    V P                  4       pVP                  P                  ! VP                  !  # r/   )r  r0   has_runr1   )r2   r   s   & r3   _network_already_configured Init._network_already_configured  s)    224}}$$chh//r6   c                R  a a	 ^ RI HpHp S P                  4       w  rEVf   \        P                  RV4       R# V 3R lo	V	V 3R lpS P                  eh   S P                  4       '       gR   V! 4       '       gE   S	! \        P                  4      '       g)   \        P                  R4       S P                  V4       R# S P                  4       w  rEV'       d)   S P                  V4       V! VVP                  RRRR	7       S P                  P                  P!                  V4       S P                  V4       \        P                  R
VVV4       S P#                  4       p VP$                  P&                  ! VP(                  !  ;_uu_ 4        S P                  P+                  WAR7      uuRRR4       #   + '       g   i     R# ; i  \,        P.                   d"   p\        P1                  RT4        Rp?R# Rp?i\2         d%    \        P5                  RS P                  4        R# i ; i)zApply the network config.

Find the config, determine whether to apply it, apply it via
the distro, and optionally bring it up
)
SchemaTypevalidate_cloudconfig_schemaNz network config is disabled by %sc                    < \        SP                  SP                  V \        P                  R 7      ;'       d    SP                  P                  V .4      # ))rA   rB   rC   rD   )rd   r   rB   r   NETWORKupdate_metadata_if_supported)
event_typer2   s   &r3   "event_enabled_and_metadata_updatedEInit.apply_network_config.<locals>.event_enabled_and_metadata_updated)  sM    '77HH", ((	 E E
 ''66
|DEr6   c                  j   < SP                  4       '       * ;'       d    S ! \        P                  4      # r/   )r!  r   BOOT)r*  r2   s   r3   should_run_on_boot_event;Init.apply_network_config.<locals>.should_run_on_boot_event1  s/    4466 G G6y~~Fr6   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  rY   r  rA   rX  r   BOOT_LEGACYrZ   r  r=  NETWORK_CONFIGr   r  wait_for_physdevsr  r0   lockr1   r  r   RendererNotFoundErrorr   NotImplementedErrorr   )
r2   r5  r$  r%  r2  srcr.  r   r   r*  s
   f&       @r3   r  Init.apply_network_config  s   	

 224>HH7=	E	 OO'((**,..6y7L7LMMII9
 $$V, 224++F3'&55!!% 	008 	  ( 	C		
 224	##SXX..{{77 8  /... (( 	II$
 " 	KK=
 	sB   ,G F/$
G /G 	:G  G H&G44H&!H&%H&)rq   rs   rr   ru   rA   rh   rt   rw   )NN)Fr/   )r
  )9r7   r8   r9   r:   r4   r{   propertyr   rB   r   rW   r   r   r   staticmethodr   r   r   r   r   r   r   r  r  r%  r(  r/  r=  rO  r   rD  rX  r   r]  rb  rq  rv  rz  rh  rl  rj  r  r  r  r  r(   r  r  r  r  r  r  r  r!  r  r;   r<   r=   s   @r3   rf   rf      s    ! !,    / /  &&  #J2:& E	O$F4. .`.
< <4;z 
 
"

8,	
LB	#M	.
 @

t l &2 N
` <H L
\ +7 E 2
 2
h;
 
0 0X Xr6   rf   c                $    V ^8  d   QhR\         /# )r@   r   )ri   )rI   s   "r3   rJ   rJ   t  s     > > >r6   c                 j    \         P                  ! \        P                  P	                  V R 4      4      # )z	cloud.cfg)r   	read_confr   r   r   )r   s   &r3   read_runtime_configrD  t  s     >>"'',,w<==r6   r   c                0    V ^8  d   QhR\         R\        /# )r@   r   rE   )ri   rG   )rI   s   "r3   rJ   rJ   x  s      s 4 r6   c                    \         P                  ! \         P                  ! 4       \         P                  ! \        VR 7      \        V 4      \         P                  ! 4       .RR7      # )r   T)reverse)r   rP   get_builtin_cfgread_conf_with_confdr%   rD  read_conf_from_cmdline)r   r   s   &$r3   r   r   x  sW       "%%1C  ('')	
  r6   )FrQ   r  loggingr   r  
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*   	getLoggerr7   rY   r+   r-   r  rd   rf   rD  r   r   r6   r3   <module>r\     s       	 
   I I I    * E E = B F B " &  2!3  F BJe eP>$  r6   