a '¡Dgç4ã@sþddlZddlZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z mZmZmZmZddlmZddlmZddlmZdd lmZdd lmZe e¡Zd Zd d gZ ddiZ!Gdd„de ƒZ"dd„Z#dd„Z$e"e%e&dœdd„Z'Gdd„dƒZ(dS)éN)Ú signature)Ú ModuleType)ÚDictÚListÚ NamedTupleÚOptional)ÚconfigÚimporterÚ lifecycleÚ performanceÚ type_utilsÚutil)Ú ALL_DISTROS)Ú ConfigMerger)ÚReportEventStack)Ú FREQUENCIES)ÚInitZcc_Z cc_migratorZcc_rightscale_userdataZcc_ubuntu_advantageZ cc_ubuntu_proc@s2eZdZUeed<eed<eed<eeed<dS)Ú ModuleDetailsÚmoduleÚnameÚ frequencyÚrun_argsN)Ú__name__Ú __module__Ú __qualname__rÚ__annotations__Ústrr©rrúdS| t¡sTdt|f}|S)Nú-Ú_z.pyréz%s%s)ÚreplaceÚlowerÚendswithÚlenÚstripÚ startswithÚ MOD_PREFIX)rZ canon_namerrrÚform_module_name9s   r)cCsˆt|dƒrd|jvsd|jvr4td|›d|›d�ƒ‚|jdtvrdtd|›d|›d|jd›d�ƒ‚t|d ƒr„td|›d|›d �ƒ‚dS) NÚmetarÚdistroszModule 'z ' with name 'z4' MUST have a 'meta' attribute of type 'MetaSchema'.z' has an invalid frequency Ú.ZschemazX' has a JSON 'schema' attribute defined. Please define schema in cloud-init-schema,json.)Úhasattrr*Ú ValueErrorr)ÚmodrrrrÚvalidate_moduleEs&ÿþýÿÿÿ ÿr0)Úmodule_detailsÚcfgÚreturncCs2t|jj di¡ƒ}|sdS| | ¡¡s.dSdS)NZactivate_by_schema_keysTF)Ú frozensetrr*ÚgetÚ intersectionÚkeys)r1r2Zactivate_by_schema_keys_keysrrrÚ _is_active[sÿr8c@sxeZdZdedœdd„Zeejdœdd„ƒZe e dœdd „Z e e dœd d „Z e e d œd d„Zddd„Zdd„ZdS)ÚModulesN)ÚinitcCs2||_||_d|_|dur(tdddd�}||_dS)Nzmodule-reporterz module-descF)rÚ descriptionZreporting_enabled)r:Ú cfg_filesÚ _cached_cfgrÚreporter)Úselfr:r<r>rrrÚ__init__gsýzModules.__init__)r3cCs<|jdur0t|jj|jj|j|jjd�}|j|_t |j¡S)N)ÚpathsÚ datasourceZadditional_fnsZbase_cfg) r=rr:rArBr<r2ÚcopyÚdeepcopy)r?Zmergerrrrr2ts üz Modules.cfgcCs`g}||jvr|S|j |¡}|s&|S|D�].}|s6q*t|tƒrT| d| ¡i¡q*t|tƒrÆi}t|ƒdkr~|d ¡|d<t|ƒdkrš|d ¡|d<t|ƒdkr¶|dd…|d<|rÄ| |¡q*t|tƒ�rDi}d }d |vrö|d  ¡|d<d }d |v�r|d  ¡|d<d|v�r,|d�p&g|d<|�rZ|�rZ| |¡q*t d |t   |¡fƒ‚q*|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. r/éréÚfreqr!NÚargsFrTrz3Failed to read '%s' item in config, unknown type %s) r2r5Ú isinstancerÚappendr&Úlistr%ÚdictÚ TypeErrorr Úobj_name)r?rZ module_listZcfg_modsÚitemÚcontentsZvalidrrrÚ _read_modules‚sT    ÿÿ           ÿÿzModules._read_modulesc Cs.g}|D�]}|d}| d¡}| d¡p,g}t|ƒ}|sr2rrTÚ parametersr%r rUÚupdater ZTimedÚrunZdeltaÚmessageÚ Exceptionr Zlogexc)r?r]ZccZfailuresZ which_ranr/rrGrHÚrun_nameZdescZmyrepZ func_argsZfunc_signatureZ func_paramsZtimerZranZ_rÚerrrÚ _run_modulessT ÿ   ÿü  þ ÿ(ÿÿ.&zModules._run_modulescCs&|||dœ}|g}| |¡}| |¡S)N)r/rHrG)r_rl)r?r^rHrGZ mod_to_ber\r]rrrÚ run_single7sý zModules.run_singlecCs| |¡}| |¡}|jjj}g}g}|j dg¡}g}g} |D]‚} | \} } } }| durZq@| jd}t| |jƒs||  | ¡q@|r°|t gkr°||vr°| |vr¦|  | ¡q@|  | ¡|   | | | |g¡q@|rÚt   dd  |¡¡|ròt   dd  |¡|¡|�r t   dd  |¡¡| | ¡S) zóRuns 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 Zunverified_modulesNr+z?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, )rQr_r:Zdistrorr2r5r*r8rJrrYrZÚjoinrl)r?Z section_namer\r]Z distro_nameZskippedZforcedZ overriddenZinapplicable_modsZ active_modsr1r/rZ_freqÚ_argsZworked_distrosrrrÚ run_sectionCsJ         ýûzModules.run_section)NN)NN)rrrrr@ÚpropertyrZConfigr2rrrQrr_rlrmrqrrrrr9fs  ;C7 r9))rCZloggingÚinspectrÚtypesrÚtypingrrrrZ cloudinitrr r r r r Zcloudinit.distrosrZcloudinit.helpersrZcloudinit.reporting.eventsrZcloudinit.settingsrZcloudinit.stagesrZ getLoggerrrYr(rXrVrr)r0rLÚboolr8r9rrrrÚ s,         þÿ