name : modules.cpython-39.opt-1.pyc
a

'�Dg�4�@s�ddlZddlZddlmZddlmZddlmZmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZe�e�ZdZd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_Zcc_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�</usr/lib/python3.9/site-packages/cloudinit/config/modules.pyr2s
rcCsX|�dd�}|���d�r.|dt|�d�}|��}|s>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	�Ze	ed�d
d�Z
e	ed�d
d�Zddd�Zdd�ZdS)�ModulesN)�initcCs2||_||_d|_|dur(tdddd�}||_dS)Nzmodule-reporterzmodule-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
�zModules.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?rZmodule_listZcfg_mods�item�contentsZvalidrrr�
_read_modules�sT


��


��zModules._read_modulesc	Cs.g}|D�]}|d}|�d�}|�d�p,g}t|�}|s<q|rf|tvrftjd|�d|��dd�d}|tvr�tjd	|�d
t|�d�dd�t|}t�|d
t�	t
�gdg�\}}	|s�|tvr�t�
d|dd��qt�d||	�qt�|d�}
t|
|�|du�r|
jd}|�t|
|||d��q|S)z�Convert 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/rGrHzConfig specified module z has an unknown frequency z22.1�Z
deprecatedZdeprecated_versionNzModule has been renamed from z to z/. Update any references in /etc/cloud/cloud.cfgz24.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)rr)rrrr)r5r)rr
�	deprecate�RENAMED_MODULESr	�find_modulerrNr�REMOVED_MODULES�LOG�infoZwarning�
import_moduler0r*rJr)r?�raw_mods�mostly_modsZraw_modZraw_namerGr�mod_nameZmod_locsZlooked_locsr/rrr�_fixup_modules�sh

��	���
��


��zModules._fixup_modules)r]cCs�|j��}g}g}|D�]t\}}}}�z t�d|||�|�|�d|��}	d|	|f}
t|	|
|jd�}||j||d�}|��t|j	�}
|
j
}t|�dkr�tj
ddd	�|�d
ti�tjddd
��(}|j|	|j	||d�\}}Wd�n1s�0Y|�r|	�d|jd�d�|_n
d|	|_Wd�n1�s:0YWqt�y�}z*t�td||�|�||f�WYd}~qd}~00q||fS)Nz(Running module %s (%s) with frequency %szconfig-zrunning %s with frequency %s)rr;�parent)rr2ZcloudrH�z%Config modules with a `log` parameterz23.2rR�logrS�skip)Zlog_mode)rGz ran successfully and took z.3fz secondsz%s previously ranzRunning module %s (%s) failed)r:ZcloudifyrY�debugrJrr>r2rrT�
parametersr%r
rU�updaterZTimed�runZdelta�message�	Exceptionr
Zlogexc)r?r]ZccZfailuresZ	which_ranr/rrGrH�run_nameZdescZmyrepZ	func_argsZfunc_signatureZfunc_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]Zdistro_nameZskippedZforcedZ
overriddenZinapplicable_modsZactive_modsr1r/rZ_freq�_argsZworked_distrosrrr�run_sectionCsJ	






��zModules.run_section)NN)NN)rrrrr@�propertyrZConfigr2rrrQrr_rlrmrqrrrrr9fs

;C7
r9))rCZlogging�inspectr�typesr�typingrrrrZ	cloudinitrr	r
rrr
Zcloudinit.distrosrZcloudinit.helpersrZcloudinit.reporting.eventsrZcloudinit.settingsrZcloudinit.stagesrZ	getLoggerrrYr(rXrVrr)r0rL�boolr8r9rrrr�<module>	s, 
��

© 2025 Cubjrnet7