Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/modules.cpython-38.pyc

U

�Ad�-�@s�ddlZddlmZddlmZmZmZmZddlm	Z	m
Z
ddlmZddlm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZe�e�ZdZGd
d�de�Zdd�Zdd�Zee e!d�dd�Z"Gdd�d�Z#dS)�N)�
ModuleType)�Dict�List�
NamedTuple�Optional)�config�importer)�log)�
type_utils�util)�ALL_DISTROS)�ConfigMerger)�ReportEventStack)�FREQUENCIES)�InitZcc_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�}|��}|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_name&s
r'cCs�t|d�rd|jksd|jkr4td|�d|�d���|jdtkrdtd|�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_module2s"�����
�r.)�module_details�cfg�returncCs2t|jj�di��}|sdS|�|���s.dSdS)NZactivate_by_schema_keysTF)�	frozensetrr(�get�intersection�keys)r/r0Zactivate_by_schema_keys_keysrrr�
_is_activeHs�r6c@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|_|dkr(tdddd�}||_dS)Nzmodule-reporterzmodule-descF)r�descriptionZreporting_enabled)r8�	cfg_files�_cached_cfgr�reporter)�selfr8r:r<rrr�__init__Ts�zModules.__init__)r1cCs<|jdkr0t|jj|jj|j|jjd�}|j|_t�|j�S)N)�paths�
datasourceZadditional_fnsZbase_cfg)	r;r
r8r?r@r:r0�copy�deepcopy)r=Zmergerrrrr0as
�zModules.cfgcCs`g}||jkr|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
|kr�|d
��|d<d}d|k�r|d��|d<d|k�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��freqrN�argsFrTrz3Failed to read '%s' item in config, unknown type %s)r0r3�
isinstancer�appendr$�listr#�dict�	TypeErrorr
�obj_name)r=rZmodule_listZcfg_mods�item�contentsZvalidrrr�
_read_modulesosV


��


��zModules._read_modulesc	Cs�g}|D]�}|d}|�d�}|�d�p*g}t|�}|s:q|rX|tkrXt�d||�d}t�|dt�t	�gdg�\}}	|s�t�d||	�qt�
|d	�}
t|
|�|dkr�|
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.
        r-rErFz6Config specified module %s has an unknown frequency %sN��handlez,Could not find module named %s (searched %s)rr)rrrr)r3r'r�LOGZwarningr�find_moduler
rLr�
import_moduler.r(rHr)r=�raw_mods�mostly_modsZraw_modZraw_namerEr�mod_nameZmod_locsZlooked_locsr-rrr�_fixup_modules�sP
���

��zModules._fixup_modules)rVcCs|j��}g}g}|D]�\}}}}z�t�d|||�||j|t|g}	|�|�d|��}
d|
|f}t|
||jd�}|�8|j|
|j	|	|d�\}
}|
r�d|
|_
n
d|
|_
W5QRXWqtk
r�}z"t�
td||�|�||f�W5d}~XYqXq||fS)	Nz(Running module %s (%s) with frequency %szconfig-zrunning %s with frequency %s)rr9�parent)rEz%s ran successfullyz%s previously ranzRunning module %s (%s) failed)r8ZcloudifyrR�debugr0rHrr<�runrQ�message�	ExceptionrZlogexc)r=rVZccZfailuresZ	which_ranr-rrErFZ	func_args�run_nameZdescZmyrepZranZ_r�errr�_run_modules�sD
�

��
"zModules._run_modulescCs&|||d�}|g}|�|�}|�|�S)N)r-rFrE)rXr`)r=rWrFrEZ	mod_to_berUrVrrr�
run_singles�
zModules.run_singlecCs|�|�}|�|�}|jjj}g}g}|j�dg�}g}g}	|D]�}
|
\}}}
}|dkrZq@|jd}t|
|j�s||�	|�q@|r�|t
gkr�||kr�||kr�|�	|�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, )rOrXr8Zdistrorr0r3r(r6rHrrR�info�joinr`)r=Zsection_namerUrVZdistro_nameZskippedZforcedZ
overriddenZinapplicable_modsZactive_modsr/r-rZ_freqZ_argsZworked_distrosrrr�run_sectionsJ	






��zModules.run_section)NN)NN)rrrrr>�propertyrZConfigr0rrrOrrXr`rarerrrrr7Ss

;0)
r7)$rA�typesr�typingrrrrZ	cloudinitrrr	Zloggingr
rZcloudinit.distrosrZcloudinit.helpersr
Zcloudinit.reporting.eventsrZcloudinit.settingsrZcloudinit.stagesrZ	getLoggerrrRr&rr'r.rJ�boolr6r7rrrr�<module>	s"