
    x[hK5                     $   S SK r S SKrS SKJr  S SKJr  S SKJrJrJ	r	J
r
  S SKJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  \R8                  " \5      rSr/ SQr SS0r! " S S\	5      r"S r#S r$S\"S\%S\&4S jr' " S S5      r(g)    N)	signature)
ModuleType)DictList
NamedTupleOptional)configimporter	lifecycleperformance
type_utilsutil)ALL_DISTROS)ConfigMerger)ReportEventStack)FREQUENCIES)Initcc_)cc_emit_upstartzcc_refresh_rmc_and_interface.pycc_migratorcc_rightscale_userdatacc_ubuntu_advantagecc_ubuntu_proc                   D    \ rS rSr% \\S'   \\S'   \\S'   \\   \S'   Srg)ModuleDetails4   modulename	frequencyrun_args N)	__name__
__module____qualname____firstlineno__r   __annotations__strr   __static_attributes__r!       :/usr/lib/python3/dist-packages/cloudinit/config/modules.pyr   r   4   s    
IN3ir)   r   c                    U R                  SS5      nUR                  5       R                  S5      (       a  US[        U5      S-
   nUR	                  5       nU(       d  g UR                  [        5      (       d  [        < U< 3nU$ )N-_z.pyr      )replacelowerendswithlenstrip
startswith
MOD_PREFIX)r   
canon_names     r*   form_module_namer7   ;   sv    c3'J""5))S_q%8:
!!#J  ,,):6
r)   c           	      B   [        U S5      (       a   SU R                  ;  d  SU R                  ;  a  [        SU  SU S35      eU R                  S   [        ;  a"  [        SU  SU SU R                  S    S35      e[        U S	5      (       a  [        SU  SU S
35      eg )Nmetar   distroszModule 'z' with name 'z4' MUST have a 'meta' attribute of type 'MetaSchema'.z' has an invalid frequency .schemazX' has a JSON 'schema' attribute defined. Please define schema in cloud-init-schema,json.)hasattrr9   
ValueErrorr   )modr   s     r*   validate_moduler@   G   s    C  chh&CHH$se= /$ $
 	
 xxK/se=.Ixx$%Q(
 	
 sHse= /G G
 	
 r)   module_detailscfgreturnc                     [        U R                  R                  R                  S0 5      5      nU(       d  gUR	                  UR                  5       5      (       d  gg)Nactivate_by_schema_keysTF)	frozensetr   r9   getintersectionkeys)rA   rB   activate_by_schema_keys_keyss      r*   
_is_activerK   ]   sO    #,""&&'@"E$  ('44SXXZ@@r)   c                       \ rS rSrSS\4S jjr\S\R                  4S j5       r	S\
\   4S jrS\
\   4S jrS	\
\   4S
 jrSS jrS rSrg)Modulesh   Ninitc                 R    Xl         X l        S U l        Uc  [        SSSS9nX0l        g )Nzmodule-reporterzmodule-descF)r   descriptionreporting_enabled)rO   	cfg_files_cached_cfgr   reporter)selfrO   rS   rU   s       r*   __init__Modules.__init__i   s4    	"48'&)"'H
 !r)   rC   c                 "   U R                   cc  [        U R                  R                  U R                  R                  U R
                  U R                  R                  S9nUR                  U l         [        R                  " U R                   5      $ )N)paths
datasourceadditional_fnsbase_cfg)	rT   r   rO   rZ   r[   rS   rB   copydeepcopy)rV   mergers     r*   rB   Modules.cfgv   sg     #!iioo99//#~~	F  &zzD}}T--..r)   c           	         / nXR                   ;  a  U$ U R                   R                  U5      nU(       d  U$ U GH  nU(       d  M  [        U[        5      (       a#  UR	                  SUR                  5       05        ME  [        U[        5      (       a  0 n[        U5      S:  a  US   R                  5       US'   [        U5      S:  a  US   R                  5       US'   [        U5      S:  a  USS US'   U(       a  UR	                  U5        M  M  [        U[        5      (       a}  0 nS	nS
U;   a  US
   R                  5       US'   SnSU;   a  US   R                  5       US'   SU;   a  US   =(       d    / US'   U(       a  U(       a  UR	                  U5        GMe  GMh  GMk  [        SU< S[        R                  " U5      < 35      e   U$ )a  Read the modules from the config file given the specified name.

Returns a list of module definitions. E.g.,
[
    {
        "mod": "bootcmd",
        "freq": "always",
        "args": "some_arg",
    }
]

Note that in the default case, only "mod" will be set.
r?      r      freqr.   NargsFr   Tr   zFailed to read 'z' item in config, unknown type )rB   rG   
isinstancer'   appendr3   listr2   dict	TypeErrorr   obj_name)rV   r   module_listcfg_modsitemcontentsvalids          r*   _read_modulesModules._read_modules   s    #%xx88<<%D$$$""tzz|
 D4))t9>&*1gmmoHUOt9>'+Aw}}HV$t9>'+ABxHV$&&x0 D4))T>&*6l&8&8&:HUO E$&'+K'8'>'>'@HV$T>'+F|'9rHV$&&x0 !&8  Z0068 C J r)   c           
         / nU GHw  nUS   nUR                  S5      nUR                  S5      =(       d    / n[        U5      nU(       d  MH  U(       a'  U[        ;  a  [        R                  " SU SU 3SS9  SnU[
        ;   a,  [        R                  " S	U S
[
        U    S3SS9  [
        U   n[        R                  " US[        R                  " [        5      /S/5      u  pU(       d>  U[        ;   a  [        R                  SUSS 5        O[        R                  SUU	5        GM&  [        R                  " US   5      n
[!        X5        Uc  U
R"                  S   nUR%                  ['        U
UUUS95        GMz     U$ )zConvert list of returned from _read_modules() into new format.

Invalid modules and arguments are ignored.
Also ensures that the module has the required meta fields.
r?   re   rf   zConfig specified module z has an unknown frequency z22.1
deprecateddeprecated_versionNzModule has been renamed from z to z/. Update any references in /etc/cloud/cloud.cfgz24.1 handlez\Module `%s` has been removed from cloud-init. It may be removed from `/etc/cloud/cloud.cfg`.r.   z,Could not find module named %s (searched %s)r   r   )r   r   r   r    )rG   r7   r   r   	deprecateRENAMED_MODULESr
   find_moduler   rl   r	   REMOVED_MODULESLOGinfowarningimport_moduler@   r9   rh   r   )rV   raw_modsmostly_modsraw_modraw_namere   r    mod_namemod_locslooked_locsr?   s              r*   _fixup_modulesModules._fixup_modules   s    Gu~H;;v&D{{6*0bH'1HK/##28* =&&*V- (. ?*##7z*845 6>> (. +84$,$8$82z226:;hZ%!H .HHI  KKF #
 ((!5CC*|xx,!"%	e  t r)   r   c           
         U R                   R                  5       n/ n/ nU GH0  u  pVpx [        R                  SXeU5        UR	                  U5        SU 3n	SU	< SU< 3n
[        XU R                  S9nUU R                  UUS.nU   [        UR                  5      nUR                  n[        U5      S:X  a,  [        R                  " SS	S
9  UR                  S[        05        [        R                   " SSS9 nUR#                  XR                  XS9u  nnS S S 5        W(       a  U	 SWR$                  S S3Ul        O
SU	-  Ul        S S S 5        GM3     XC4$ ! , (       d  f       NH= f! , (       d  f       GMY  = f! [(         a;  n[*        R,                  " [        SXe5        UR	                  UU45         S nAGM  S nAff = f)Nz(Running module %s (%s) with frequency %szconfig-zrunning z with frequency )r   rQ   parent)r   rB   cloudrf      z%Config modules with a `log` parameterz23.2ru   logrx   skip)log_mode)re   z ran successfully and took z.3fz secondsz%s previously ranzRunning module %s (%s) failed)rO   cloudifyr~   debugrh   r   rU   rB   r   ry   
parametersr2   r   rz   updater   Timedrundeltamessage	Exceptionr   logexc)rV   r   ccfailures	which_ranr?   r   re   rf   run_namedescmyrep	func_argsfunc_signaturefunc_paramstimerran_res                      r*   _run_modulesModules._run_modules  s   YY! 	%0!Ct-+		>4
   &$TF+9A4H(!DMM !88 		 %.szz%:N"0";";K;'1,!++'N/5 "((%6$**2?5"$&&$jj) #) #R @ 'j )$$)KK#4H> 
 )<h(F) U- &1^ $$ @? U,  +C!@$Lq	**+sO   AE=A2E*9E2E*	E=
E'#E**
E:	4E=:E==
G/F==Gc                 X    UUUS.nU/nU R                  U5      nU R                  U5      $ )N)r?   rf   re   )r   r   )rV   r   rf   re   	mod_to_ber   r   s          r*   
run_singleModules.run_single9  s>     
	 ;))(3  --r)   c                 >   U R                  U5      nU R                  U5      nU R                  R                  R                  n/ n/ nU R
                  R                  S/ 5      n/ n/ n	U H  n
U
u  ppUc  M  UR                  S   n[        XR
                  5      (       d  UR                  U5        MI  U(       a9  U[        /:w  a.  XO;  a)  X;  a  UR                  U5        Mx  UR                  U5        U	R                  XX/5        M     U(       a%  [        R                  SSR                  U5      5        U(       a&  [        R                  SSR                  U5      U5        U(       a%  [        R                  SSR                  U5      5        U R                  U	5      $ )zRuns all modules in the given section.

section_name - One of the modules lists as defined in
  /etc/cloud/cloud.cfg. One of:
 - cloud_init_modules
 - cloud_config_modules
 - cloud_final_modules
unverified_modulesr:   z?Skipping modules '%s' because no applicable config is provided.,zSkipping modules '%s' because they are not verified on distro '%s'.  To run anyway, add them to 'unverified_modules' in config.z running unverified_modules: '%s'z, )rr   r   rO   distror   rB   rG   r9   rK   rh   r   r~   r   joinr   )rV   section_namer   r   distro_nameskippedforced
overriddeninapplicable_modsactive_modsrA   r?   r   _freq_argsworked_distross                   r*   run_sectionModules.run_sectionE  sm    %%l3))(3ii&&++XX\\"6;
)N(6%S{ XXi0Nnhh77!((. .[M"A4-t, MM$'589' ** HH*+
 HH2 ! HH769JK  --r)   )rT   rS   rO   rU   )NN)r"   r#   r$   r%   r   rW   propertyr	   ConfigrB   r   r   rr   r   r   r   r   r   r(   r!   r)   r*   rM   rM   h   sn    !T ! /V]] / /9T$Z 9vA$}*= AF5%](; 5%n
.8.r)   rM   ))r^   logginginspectr   typesr   typingr   r   r   r   	cloudinitr	   r
   r   r   r   r   cloudinit.distrosr   cloudinit.helpersr   cloudinit.reporting.eventsr   cloudinit.settingsr   cloudinit.stagesr   	getLoggerr"   r~   r5   r}   r{   r   r7   r@   rj   boolrK   rM   r!   r)   r*   <module>r      s        3 3  * * 7 * !! 

 ?
J 	
,} 4 D U. U.r)   