x[hK5"ddlZddlZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z mZmZmZmZddlmZddlmZddlmZdd lmZdd lmZej8eZd Zgd Z d diZ!Gdde Z"dZ#dZ$de"de%de&fdZ'GddZ(y)N) signature) ModuleType)DictList NamedTupleOptional)configimporter lifecycle performance type_utilsutil) ALL_DISTROS) ConfigMerger)ReportEventStack) FREQUENCIES)Initcc_)cc_emit_upstartzcc_refresh_rmc_and_interface.py 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.pyrr4s  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_namer4;spc3'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.)hasattrr6 ValueErrorr)modrs r'validate_moduler=Gs C chh & CHH $se=/$ $   xx K/se=.Ixx $%Q (  sHse=/G G  r&module_detailscfgreturnct|jjjdi}|sy|j |j syy)Nactivate_by_schema_keysTF) frozensetrr6get intersectionkeys)r>r?activate_by_schema_keys_keyss r' _is_activerH]sL#,""&&'@"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)rK cfg_files _cached_cfgrreporter)selfrKrOrQs r'__init__zModules.__init__is: "48  '&)"'H ! r&r@c$|jft|jj|jj|j |jj }|j |_tj|jS)N)paths datasourceadditional_fnsbase_cfg) rPrrKrUrVrOr?copydeepcopy)rRmergers r'r?z Modules.cfgvsg    #!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. r<rfreqr+NargsFrTrzFailed to read 'z' item in config, unknown type ) r?rD isinstancer$appendr0listr/dict TypeErrorr obj_name)rRr module_listcfg_modsitemcontentsvalids r' _read_moduleszModules._read_moduless#% 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]_}|d}|jd}|jdxsg}t|}|s=|r'|tvrtjd|d|dd}|t vr.tjd |d t |d d t |}t j|d tjtgdg\}} |s;|tvrtjd|ddntjd||  t j|d} t!| ||| j"d}|j%t'| |||b|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. r<r_r`zConfig specified module z has an unknown frequency z22.1 deprecateddeprecated_versionNzModule has been renamed from z to z/. 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)rDr4rr deprecateRENAMED_MODULESr find_moduler rfr REMOVED_MODULESLOGinfowarning import_moduler=r6rbr) rRraw_mods mostly_modsraw_modraw_namer_rmod_namemod_locs looked_locsr<s r'_fixup_moduleszModules._fixup_moduless  9 Gu~H;;v&D{{6*0bH'1HK/##28*=&&*V-(. ?*##7z*8456>>(. +84$,$8$82z226:;hZ% !Hk.HHI   KKF # ((!5C C *|xx ,   !"%  e9 tr&r|c ||jj}g}g}|D]7\}}}} tjd||||j |d|} d| d|} t | | |j } ||j||d} | 5t|j} | j}t|dk(r.tjdd | jd titj d d 5}|j#| |j| |\}}dddr| dj$dd| _n d| z| _ddd:||fS#1swY=xYw#1swYxYw#t($r:}t+j,td|||j ||fYd}~d}~wwxYw)Nz(Running module %s (%s) with frequency %szconfig-zrunning z with frequency )rrMparent)rr?cloudr`z%Config modules with a `log` parameterz23.2rnlogrqskip)log_mode)r_z ran successfully and took z.3fz secondsz%s previously ranzRunning module %s (%s) failed)rKcloudifyrwdebugrbrrQr?rrr parametersr/r rsupdater Timedrundeltamessage Exceptionrlogexc)rRr|ccfailures which_ranr<rr_r`run_namedescmyrep func_argsfunc_signature func_paramstimerran_res r' _run_moduleszModules._run_moduless YY   ! %0. + !CtT- + >c4   &$TF+9A4H(!tDMM!88  G%.szz%:N"0";";K;'1,!++'N/5"((%6$**2?5"$&&$cjj)$#)#R'j)$$)KK#4H> ) ;))(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_modulesr7z?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, )rlrrKdistrorr?rDr6rHrbrrwrxjoinr)rR section_namer{r| distro_nameskippedforced overriddeninapplicable_mods active_modsr>r<r_freq_argsworked_distross r' run_sectionzModules.run_sectionEs}%%l3))(3 ii&&++ XX\\"6;  ) :N(6 %S$u{ XXi0Nndhh7!((. .[M"An4:-t, MM$'   T5%8 9' :*  HH*+   HH2!    HH769J K  --r&)NN)r r!r"rrSpropertyr Configr?rrrlrrrrrr%r&r'rJrJhsn !T ! /V]] / /9T$Z9vA$}*=AF5%](;5%n .8.r&rJ))rYlogginginspectrtypesrtypingrrrr cloudinitr r r r r rcloudinit.distrosrcloudinit.helpersrcloudinit.reporting.eventsrcloudinit.settingsrcloudinit.stagesr getLoggerr rwr2rvrtrr4r=rdboolrHrJr%r&r'rs 33**7*!g!  ? J  ,}4DU.U.r&