f3ddlZddlZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z mZmZddlmZddlmZddlmZdd lmZdd lmZej4eZd Zd d gZddiZGdde Z dZ!dZ"de de#de$fdZ%GddZ&y)N) signature) ModuleType)DictList NamedTupleOptional)configimporter type_utilsutil) ALL_DISTROS) ConfigMerger)ReportEventStack) FREQUENCIES)Initcc_ cc_migratorcc_rightscale_userdatacc_ubuntu_advantage cc_ubuntu_proc<eZdZUeed<eed<eed<eeed<y) ModuleDetailsmodulename frequencyrun_argsN)__name__ __module__ __qualname__r__annotations__strr:/usr/lib/python3/dist-packages/cloudinit/config/modules.pyrr+s  IN3ir#rc|jdd}|jjdr|dt|dz }|j }|sy|j t s t |}|S)N-_z.pyr)replacelowerendswithlenstrip startswith MOD_PREFIX)r canon_names r$form_module_namer12spc3'J""5)S_q%8: !!#J    ,):6 r#c "t|drd|jvsd|jvrtd|d|d|jdtvr"td|d|d|jddt|d rtd|d|d y) NmetardistroszModule '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.)hasattrr3 ValueErrorr)modrs r$validate_moduler:>s C chh & CHH $se=/$ $   xx K/se=.Ixx $%Q (  sHse=/G G  r#module_detailscfgreturnct|jjjdi}|sy|j |j syy)Nactivate_by_schema_keysTF) frozensetrr3get intersectionkeys)r;r<activate_by_schema_keys_keyss r$ _is_activerETsL#,""&&'@"E$  ( ' 4 4SXXZ @ r#ceZdZd defdZedejfdZde e fdZ de e fdZ de e fd Zd d Zd Zy) ModulesNinitc\||_||_d|_|tddd}||_y)Nzmodule-reporterz module-descF)r descriptionreporting_enabled)rH cfg_files _cached_cfgrreporter)selfrHrLrNs r$__init__zModules.__init__`s: "48  '&)"'H ! r#r=c$|jft|jj|jj|j |jj }|j |_tj|jS)N)paths datasourceadditional_fnsbase_cfg) rMrrHrRrSrLr<copydeepcopy)rOmergers r$r<z Modules.cfgmsg    #!iioo99//#~~ F &zzD }}T--..r#c g}||jvr|S|jj|}|s|S|D]T}|st|tr"|j d|j i9t|t rui}t|dk\r|dj |d<t|dk\r|dj |d<t|dk\r|dd|d<|s|j |t|trei}d }d |vr|d j |d<d }d |vr|d j |d<d|vr |dxsg|d<|s|s |j |3td |dtj||S)aURead 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. r9rfreqr(NargsFrTrzFailed to read 'z' item in config, unknown type ) r<rA isinstancer!appendr-listr,dict TypeErrorr obj_name)rOr module_listcfg_modsitemcontentsvalids r$ _read_moduleszModules._read_modules{s#% txx  88<<% $ D$$""tzz| D4)t9>&*1gmmoHUOt9>'+Aw}}HV$t9>'+ABxHV$&&x0D4)T>&*6l&8&8&:HUO E$&'+K'8'>'>'@HV$T>'+F|'9rHV$&&x0Z0068C$ Jr#c g}|D]b}|d}|jd}|jdxsg}t|}|s=|r'|tvrtjd|d|dd}|t vr1tjd |d t |d d d t |}t j|dtjtgdg\}} |s;|tvrtjd|ddntjd|| t j|d} t!| ||| j"d}|j%t'| |||e|S)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. r9r\r]zConfig specified module z has an unknown frequency z22.1 deprecateddeprecated_versionNzModule has been renamed from z to rZz/. Update any references in /etc/cloud/cloud.cfgz24.1handlez\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)rr)rrrr)rAr1rr deprecateRENAMED_MODULESr find_moduler rcr REMOVED_MODULESLOGinfowarning import_moduler:r3r_r) rOraw_mods mostly_modsraw_modraw_namer\rmod_namemod_locs looked_locsr9s r$_fixup_moduleszModules._fixup_moduless  9 Gu~H;;v&D{{6*0bH'1HK/28*=&&*V-(. ?*7z*84Q789>>(. +84$,$8$82z226:;hZ% !Hk.HHI   KKF # ((!5C C *|xx ,   !"%  e9 tr#ryc|jj}g}g}|D] \}}}} tjd||||j |d|} d| d|} t | | |j } ||j||d} | 5t|j} | j}t|dk(r.tjdd | jd ti|j| |j| | \}}|r d | z| _n d| z| _ddd ||fS#1swYxYw#t"$r:}tj$td|||j ||fYd}~[d}~wwxYw)Nz(Running module %s (%s) with frequency %szconfig-zrunning z with frequency )rrJparent)rr<cloudr]z%Config modules with a `log` parameterz23.2rklog)r\z%s ran successfullyz%s previously ranzRunning module %s (%s) failed)rHcloudifyrtdebugr_rrNr<rro parametersr,r rpupdaterunmessage Exceptionlogexc)rOryccfailures which_ranr9rr\r]run_namedescmyrep func_argsfunc_signature func_paramsran_res r$ _run_moduleszModules._run_moduless YY   ! %0) + !CtT( + >c4   &$TF+9A4H(!tDMM!88  G%.szz%:N"0";";K;'1,'N/5"((%6 ff #**id%GC(=(H (;h(F G-) +T8$$)GG" + C!@$Lq ** +s1A!D> BD2#D>2D; 7D>> F/E<<FcX|||d}|g}|j|}|j|S)N)r9r]r\)rr)rOr|r]r\ mod_to_berxrys r$ run_singlezModules.run_single+s> ;))(3   --r#c|j|}|j|}|jjj}g}g}|j j dg}g}g} |D]} | \} } } }|  | jd}t| |j s|j| D|r5|tgk7r+||vr'| |vr|j| j|j| | j| | | |g|r%tjddj||r&tjddj|||r%tjddj||j| S)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_modulesr4z?Skipping modules '%s' because no applicable config is provided.,zSkipping 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, )rirrHdistrorr<rAr3rEr_r rtrujoinr)rO section_namerxry distro_nameskippedforced overriddeninapplicable_mods active_modsr;r9r_freq_argsworked_distross r$ run_sectionzModules.run_section7s}%%l3))(3 ii&&++ XX\\"6;  ) :N(6 %S$u{ XXi0Nndhh7!((. .[M"An4:-t, MM$'   T5%8 9' :*  HH*+   HH2!    HH769J K  --r#)NN)rrrrrPpropertyr Configr<rrrirrrrrr"r#r$rGrG_sn !T ! /V]] / /9T$Z9vA$}*=AF0%](;0%d .8.r#rG)'rVlogginginspectrtypesrtypingrrrr cloudinitr r r r cloudinit.distrosr cloudinit.helpersrcloudinit.reporting.eventsrcloudinit.settingsrcloudinit.stagesr getLoggerrrtr/rsrqrr1r:raboolrErGr"r#r$rs 3388)*7*!g!   ? J  ,}4DP.P.r#