܍~c-ddlZddlmZddlmZmZmZmZddlm Z m Z ddlm Z ddlm Z mZddlmZddlmZdd lmZdd lmZdd lmZe jeZd ZGd deZdZdZdede de!fdZ"GddZ#dS)N) ModuleType)DictList NamedTupleOptional)configimporter)log) type_utilsutil) ALL_DISTROS) ConfigMerger)ReportEventStack) FREQUENCIES)Initcc_cDeZdZUeed<eed<eed<eeed<dS) ModuleDetailsmodulename frequencyrun_argsN)__name__ __module__ __qualname__r__annotations__strr:/usr/lib/python3/dist-packages/cloudinit/config/modules.pyrrs@  IIINNN3irrc.|dd}|dr|dt|dz }|}|sdS|t s t |}|S)N-_z.pyr)replacelowerendswithlenstrip startswith MOD_PREFIX)r canon_names r form_module_namer-&sc3''J""5));S__q%8 9: !!##J t   , ,7)z::6 rc 2t|drd|jvs d|jvrtd|d|d|jdtvr$td|d|d|jddt|d rtd|d|d dS) 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.)hasattrr/ ValueErrorr)modrs r validate_moduler62s C  ch & & CH $ $ $s $ $ $ $ $    x K// (s ( ( ( (x $ ( ( (   sH  Gs G G G G G     rmodule_detailscfgreturnct|jjdi}|sdS||sdSdS)Nactivate_by_schema_keysTF) frozensetrr/get intersectionkeys)r7r8activate_by_schema_keys_keyss r _is_activerAHsc#,"&&'@"EE$$  (t ' 4 4SXXZZ @ @u 4rceZdZd defdZedejfdZde e fdZ de e fdZ de e fd Zd d Zd ZdS) ModulesNinitcf||_||_d|_|tddd}||_dS)Nzmodule-reporterz module-descF)r descriptionreporting_enabled)rD cfg_files _cached_cfgrreporter)selfrDrHrJs r __init__zModules.__init__TsH "48  '&)"'H ! rr9c|jBt|jj|jj|j|jj}|j|_tj|jS)N)paths datasourceadditional_fnsbase_cfg) rIrrDrNrOrHr8copydeepcopy)rKmergers r r8z Modules.cfgas[   #!io9/#~ F &zD }T-...rc g}||jvr|S|j|}|s|S|D]}|st|tr*|d|iEt|t ri}t|dkr|d|d<t|dkr|d|d<t|dkr |dd|d<|r||t|trti}d }d |vr|d |d<d }d |vr|d |d<d|vr |dpg|d<|r|r||}td |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. r5rfreqr$NargsFrTrzFailed to read 'z' item in config, unknown type ) r8r= isinstancerappendr)listr(dict TypeErrorr obj_name)rKr module_listcfg_modsitemcontentsvalids r _read_moduleszModules._read_modulesos#% tx   8<<%%  $ $ D $$$! ""tzz|| D4)) t99>>&*1gmmooHUOt99>>'+Aw}}HV$t99>>'+ABBxHV$1&&x000D4)) T>>&*6l&8&8&:&:HUO E$&&'+K'8'>'>'@'@HV$T>>'+F|'9rHV$11&&x000ittZ06668rc Xg}|D]#}|d}|d}|dpg}t|}|sI|r'|tvrtd||d}t j|dtjtgdg\}} |std|| t j |d } t| || | j d }| t| ||| %|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. r5rXrYz6Config specified module %s has an unknown frequency %sNhandlez,Could not find module named %s (searched %s)rr)rrrr)r=r-rLOGwarningr find_moduler r_r import_moduler6r/r[r) rKraw_mods mostly_modsraw_modraw_namerXrmod_namemod_locs looked_locsr5s r _fixup_moduleszModules._fixup_modulessn  & & Gu~H;;v&&D{{6**0bH'11H  K// L$,$82z26::;hZ%% !Hk  B (!55C C * * *|x ,   !"%     rrncd|j}g}g}|D] \}}}} td|||||j|t|g} ||d|} d| d|} t | | |j} | 5|| |j | |\} }| r d| z| _ n d| z| _ dddn #1swxYwY#t$r>}tj td |||||fYd}~d}~wwxYw||fS) Nz(Running module %s (%s) with frequency %szconfig-zrunning z with frequency )rrFparent)rXz%s ran successfullyz%s previously ranzRunning module %s (%s) failed)rDcloudifyridebugr8r[rrJrunrhmessage Exceptionr logexc)rKrnccfailures which_ranr5rrXrY func_argsrun_namedescmyrepran_res r _run_moduleszModules._run_moduless Y   ! ! '2 + + #S$d + >c4"48Rd;   &&&+T++9A44H(!tDMGG ff #*id%GCG(=(H (;h(F GGGGGGGGGGGGGGG + + + C!@$LLLq ******** +8$$s<A)C#9C C#C C#C C## D+-3D&&D+ch|||d}|g}||}||S)N)r5rYrX)rtr)rKrqrYrX mod_to_bermrns r run_singlezModules.run_singlesI  ;))(33   ---rcL||}||}|jjj}g}g}|jdg}g}g} |D]} | \} } } }|  | jd}t| |js| | D|r?|tgkr3||vr/| |vr| | p| | | | | | |g|r.t dd ||r/t dd |||r.t dd ||| 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_modulesNr0z?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, )rertrDdistrorr8r=r/rAr[r riinfojoinr)rK section_namermrn distro_nameskippedforced overriddeninapplicable_mods active_modsr7r5r_freq_argsworked_distross r run_sectionzModules.run_sections%%l33))(33 i&+ X\\"6;;  ) : :N(6 %S$u{ Xi0Nndh77 !((...  (.[M"A"An44:--t,,, MM$'''   T5%8 9 9 9 9   HH*++      HH2!!      L HH769J9J K K K  ---r)NN)rrrrrLpropertyrConfigr8rrrerrtrrrrrr rCrCSs ! !T ! ! ! ! /V] / / /X /9T$Z9999v.$}*=....`'%](;'%'%'%'%R . . . .8.8.8.8.8.rrC)$rRtypesrtypingrrrr cloudinitrr r loggingr r cloudinit.distrosr cloudinit.helpersrcloudinit.reporting.eventsrcloudinit.settingsrcloudinit.stagesr getLoggerrrir+rr-r6r]boolrArCrrr rs 333333333333&&&&&&&&$$$$$$&&&&&&&&))))))******777777******!!!!!!g!!  J      ,}4Dt.t.t.t.t.t.t.t.t.t.r