HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/modules.cpython-310.pyc
o

�Ad�-�@s�ddlZddlmZddlmZmZmZmZddlm	Z	m
Z
ddlmZddlm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZe�e�ZdZGd
d�de�Zdd�Zdd�Zdede de!fdd�Z"Gdd�d�Z#dS)�N)�
ModuleType)�Dict�List�
NamedTuple�Optional)�config�importer)�log)�
type_utils�util)�ALL_DISTROS)�ConfigMerger)�ReportEventStack)�FREQUENCIES)�Init�cc_c@s2eZdZUeed<eed<eed<eeed<dS)�
ModuleDetails�module�name�	frequency�run_argsN)�__name__�
__module__�__qualname__r�__annotations__�strr�rr�:/usr/lib/python3/dist-packages/cloudinit/config/modules.pyrs

rcCsX|�dd�}|���d�r|dt|�d�}|��}|sdS|�t�s*dt|f}|S)N�-�_z.pyr�z%s%s)�replace�lower�endswith�len�strip�
startswith�
MOD_PREFIX)r�
canon_namerrr�form_module_name&s
r)cCs�t|d�rd|jvsd|jvrtd|�d|�d���|jdtvr2td|�d|�d|jd�d���t|d	�rBtd|�d|�d
���dS)N�metar�distroszModule '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)�modrrrr�validate_module2s(������
��r1�module_details�cfg�returncCs2t|jj�di��}|sdS|�|���sdSdS)N�activate_by_schema_keysTF)�	frozensetrr*�get�intersection�keys)r2r3�activate_by_schema_keys_keysrrr�
_is_activeHs�r;c@sxeZdZddefdd�Zedejfdd��Zde	e
fdd	�Zde	efd
d�Z
de	efd
d�Zddd�Zdd�ZdS)�ModulesN�initcCs2||_||_d|_|durtdddd�}||_dS)Nzmodule-reporterzmodule-descF)r�description�reporting_enabled)r=�	cfg_files�_cached_cfgr�reporter)�selfr=r@rBrrr�__init__Ts�
zModules.__init__r4cCs<|jdurt|jj|jj|j|jjd�}|j|_t�|j�S)N)�paths�
datasource�additional_fns�base_cfg)	rAr
r=rErFr@r3�copy�deepcopy)rC�mergerrrrr3as
�zModules.cfgcCsPg}||jvr	|S|j�|�}|s|S|D]�}|sqt|t�r)|�d|��i�qt|t�rbi}t|�dkr>|d��|d<t|�dkrL|d��|d<t|�dkrZ|dd�|d<|ra|�|�qt|t�r�i}d	}d
|vry|d
��|d<d}d|vr�|d��|d<d|vr�|dp�g|d<|r�|r�|�|�qt	d
|t
�|�f��|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.
        r0�r��freqr N�argsFrTrz3Failed to read '%s' item in config, unknown type %s)r3r7�
isinstancer�appendr%�listr$�dict�	TypeErrorr
�obj_name)rCr�module_list�cfg_mods�item�contents�validrrr�
_read_modulesosX

��

�

���zModules._read_modulesc	Cs�g}|D]a}|d}|�d�}|�d�pg}t|�}|sq|r,|tvr,t�d||�d}t�|dt�t	�gdg�\}}	|sEt�d||	�qt�
|d	�}
t|
|�|durZ|
jd
}|�
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.
        r0rNrOz6Config specified module %s has an unknown frequency %sN��handlez,Could not find module named %s (searched %s)rr)rrrr)r7r)r�LOG�warningr�find_moduler
rUr�
import_moduler1r*rQr)rC�raw_mods�mostly_mods�raw_mod�raw_namerNr�mod_name�mod_locs�looked_locsr0rrr�_fixup_modules�sL
���

��zModules._fixup_modulesrccCs|j��}g}g}|D]|\}}}}zUt�d|||�||j|t|g}	|�|�d|��}
d|
|f}t|
||jd�}|�!|j|
|j	|	|d�\}
}|
rQd|
|_
nd|
|_
Wd�n1s`wYWqty�}zt�
td||�|�||f�WYd}~qd}~ww||fS)	Nz(Running module %s (%s) with frequency %szconfig-zrunning %s with frequency %s)rr>�parent)rNz%s ran successfullyz%s previously ranzRunning module %s (%s) failed)r=�cloudifyr^�debugr3rQrrB�runr]�message�	Exceptionr�logexc)rCrc�cc�failures�	which_ranr0rrNrO�	func_args�run_name�desc�myrep�ran�_r�errr�_run_modules�s>
�

�

�
���	��zModules._run_modulescCs&|||d�}|g}|�|�}|�|�S)N)r0rOrN)rir{)rCrfrOrN�	mod_to_berbrcrrr�
run_singles�

zModules.run_singlecCs|�|�}|�|�}|jjj}g}g}|j�dg�}g}g}	|D]A}
|
\}}}
}|dur-q |jd}t|
|j�s>|�	|�q |rX|t
gkrX||vrX||vrS|�	|�q |�	|�|	�	|||
|g�q |rmt�dd�
|��|ryt�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
        �unverified_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, )r[rir=�distrorr3r7r*r;rQrr^�info�joinr{)rC�section_namerbrc�distro_name�skipped�forced�
overridden�inapplicable_mods�active_modsr2r0r�_freq�_args�worked_distrosrrr�run_sectionsJ
	





��
zModules.run_section)NN)rrrrrD�propertyr�Configr3rrr[rrir{r}r�rrrrr<Ss

;0
)r<)$rI�typesr�typingrrrr�	cloudinitrrr	�loggingr
r�cloudinit.distrosr�cloudinit.helpersr
�cloudinit.reporting.eventsr�cloudinit.settingsr�cloudinit.stagesr�	getLoggerrr^r'rr)r1rS�boolr;r<rrrr�<module>s$