Current File : //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/modules.cpython-312.pyc
�

Ӈg�4��"�ddlZddlZddlmZddlmZddlmZmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZej8e�ZdZdd
gZ ddiZ!Gd�de	�Z"d�Z#d�Z$de"de%de&fd�Z'Gd�d�Z(y)�N)�	signature)�
ModuleType)�Dict�List�
NamedTuple�Optional)�config�importer�	lifecycle�performance�
type_utils�util)�ALL_DISTROS)�ConfigMerger)�ReportEventStack)�FREQUENCIES)�Init�cc_�cc_migrator�cc_rightscale_userdata�cc_ubuntu_advantage�
cc_ubuntu_proc�<�eZdZUeed<eed<eed<eeed<y)�
ModuleDetails�module�name�	frequency�run_argsN)�__name__�
__module__�__qualname__r�__annotations__�strr���:/usr/lib/python3/dist-packages/cloudinit/config/modules.pyrr2s����

�I��N��3�i�r%rc���|jdd�}|j�jd�r|dt|�dz
}|j	�}|sy|jt�s
t�|��}|S)N�-�_z.pyr�)�replace�lower�endswith�len�strip�
startswith�
MOD_PREFIX)r�
canon_names  r&�form_module_namer39sp�����c�3�'�J�����"�"�5�)���S��_�q�%8�:�
��!�!�#�J���� � ��,�)�:�6�
��r%c	�"�t|d�rd|jvsd|jvrtd|�d|�d���|jdtvr"td|�d|�d|jd�d���t|d	�rtd|�d|�d
���y)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.)�hasattrr5�
ValueErrorr)�modrs  r&�validate_moduler<Es����C�� ��c�h�h�&��C�H�H�$���s�e�=���/$�
$�
�	
��x�x���K�/���s�e�=���.I��x�x��$�%�Q�
(�
�	
��s�H����s�e�=���/G�
G�
�	
�r%�module_details�cfg�returnc��t|jjjdi��}|sy|j	|j��syy)N�activate_by_schema_keysTF)�	frozensetrr5�get�intersection�keys)r=r>�activate_by_schema_keys_keyss   r&�
_is_activerG[sL��#,����"�"�&�&�'@�"�E�$� �(��'�4�4�S�X�X�Z�@��r%c��eZdZddefd�Zedejfd��Zde	e
fd�Zde	efd�Z
de	efd	�Zdd
�Zd�Zy)
�ModulesN�initc�\�||_||_d|_|�tddd��}||_y)Nzmodule-reporterzmodule-descF)r�description�reporting_enabled)rJ�	cfg_files�_cached_cfgr�reporter)�selfrJrNrPs    r&�__init__zModules.__init__gs:����	�"���48�����'�&�)�"'��H�
!��
r%r?c�$�|j�ft|jj|jj|j
|jj��}|j|_tj|j�S)N)�paths�
datasource�additional_fns�base_cfg)	rOrrJrTrUrNr>�copy�deepcopy)rQ�mergers  r&r>zModules.cfgtsg�����#�!��i�i�o�o��9�9�/�/�#�~�~������	�F� &�z�z�D���}�}�T�-�-�.�.r%c	��g}||jvr|S|jj|�}|s|S|D�]T}|s�t|t�r"|j	d|j�i��9t|t�rui}t|�dk\r|dj�|d<t|�dk\r|dj�|d<t|�dk\r|dd|d<|s��|j	|���t|t�rei}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;�r��freqr*N�argsFrTrzFailed to read 'z' item in config, unknown type )r>rC�
isinstancer#�appendr/�listr.�dict�	TypeErrorr
�obj_name)rQr�module_list�cfg_mods�item�contents�valids       r&�
_read_moduleszModules._read_modules�s���#%���t�x�x�����8�8�<�<��%������$	�D����$��$��"�"��t�z�z�|���
�D�4�)����t�9��>�&*�1�g�m�m�o�H�U�O��t�9��>�'+�A�w�}�}��H�V�$��t�9��>�'+�A�B�x�H�V�$���&�&�x�0��D�4�)������T�>�&*�6�l�&8�&8�&:�H�U�O� �E��$�&�'+�K�'8�'>�'>�'@�H�V�$��T�>�'+�F�|�'9�r�H�V�$����&�&�x�0���Z�0�0��6�8���C$	�J�r%c	���g}|D�]_}|d}|jd�}|jd�xsg}t|�}|s�=|r'|tvrtjd|�d|��d��d}|t
vr.tjd	|�d
t
|�d�d��t
|}t
j|d
tjt�gdg�\}}	|s;|tvrtjd|dd�ntjd||	���
t
j|d�}
t!|
|�|�|
j"d}|j%t'|
|||�����b|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;r^r_zConfig specified module z has an unknown frequency z22.1��
deprecated�deprecated_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)rCr3rr�	deprecate�RENAMED_MODULESr
�find_moduler
rer	�REMOVED_MODULES�LOG�info�warning�
import_moduler<r5rar)rQ�raw_mods�mostly_mods�raw_mod�raw_namer^r�mod_name�mod_locs�looked_locsr;s           r&�_fixup_moduleszModules._fixup_modules�s������9	�G��u�~�H��;�;�v�&�D��{�{�6�*�0�b�H�'��1�H�����K�/��#�#�2�8�*�=&�&*�V�-�(.�����?�*��#�#�7��z��*�8�4�5�6>�>�(.�
�+�8�4��$,�$8�$8��2�z�2�2�6�:�;�h�Z�%�!�H�k����.��H�H�I� ������K�K�F� �#��
��(�(��!��5�C��C��*��|��x�x��,�������!�"�%�	�
�e9	�t�r%r{c	�|�|jj�}g}g}|D�]7\}}}}	tjd|||�|j	|�d|��}	d|	�d|��}
t|	|
|j��}||j||d�}|5t|j�}
|
j}t|�dk(r.tjdd	�
�|jdti�tj dd
��5}|j#|	|j||��\}}ddd�r|	�dj$d�d�|_n
d|	z|_ddd���:||fS#1swY�=xYw#1swY�xYw#t($r:}t+j,td||�|j	||f�Yd}~���d}~wwxYw)Nz(Running module %s (%s) with frequency %szconfig-zrunning z with frequency )rrL�parent)rr>�cloudr_�z%Config modules with a `log` parameterz23.2rm�logrp�skip)�log_mode)r^z ran successfully and took z.3fz secondsz%s previously ranzRunning module %s (%s) failed)rJ�cloudifyrv�debugrarrPr>rrq�
parametersr.rrr�updater�Timed�run�delta�message�	Exceptionr�logexc)rQr{�cc�failures�	which_ranr;rr^r_�run_name�desc�myrep�	func_args�func_signature�func_params�timer�ran�_r�es                   r&�_run_moduleszModules._run_moduless���
�Y�Y�
�
�
!�����	�%0�.	+�!�C��t�T�-
+��	�	�>��c�4��
� � ��&�$�T�F�+��9A�4�H��(�!�t�D�M�M���!��8�8�� �	�	��G�%.�s�z�z�%:�N�"0�";�";�K��;�'�1�,�!�+�+�'N�/5��"�(�(�%���6�$�*�*�2��?��5�"$�&�&�$�c�j�j�)�$�#)�#���R���'�j�)$�$)�K�K��#4�H�>��
�
)<�h�(F��
�)G��-.	+�^�8�$�$����G�G��,�
+����C�!@�$��L�����q�	�*�*��
+�sI�A!E8�A5E,�#E �$-E,�E8� E)�%E,�,E5	�1E8�8	F;�/F6�6F;c�X�|||d�}|g}|j|�}|j|�S)N)r;r_r^)r�r�)rQr~r_r^�	mod_to_berzr{s       r&�
run_singlezModules.run_single7s>�����
�	��;���)�)�(�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)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_modulesr6z?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, )rkr�rJ�distrorr>rCr5rGrarrvrw�joinr�)rQ�section_namerzr{�distro_name�skipped�forced�
overridden�inapplicable_mods�active_modsr=r;r�_freq�_args�worked_distross                r&�run_sectionzModules.run_sectionCs}���%�%�l�3���)�)�(�3���i�i�&�&�+�+�������X�X�\�\�"6��;�
�����)�	:�N�(6�%�S�$��u��{�� �X�X�i�0�N��n�d�h�h�7�!�(�(��.���.�[�M�"A��n�4��:�-����t�,� ��M�M�$�'�����T�5�%�8�9�'	:�*��H�H�����*�+�
�
��H�H�2�����!��
���H�H�7����6�9J�K�� � ��-�-r%)NN)rr r!rrR�propertyr	�Configr>rrrkrr�r�r�r�r$r%r&rIrIfsn��!�T�!��/�V�]�]�/��/�9�T�$�Z�9�vA�$�}�*=�A�F5%��]�(;�5%�n
.�8.r%rI))rX�logging�inspectr�typesr�typingrrrr�	cloudinitr	r
rrr
r�cloudinit.distrosr�cloudinit.helpersr�cloudinit.reporting.eventsr�cloudinit.settingsr�cloudinit.stagesr�	getLoggerrrvr1rursrr3r<rc�boolrGrIr$r%r&�<module>r�s�������3�3���*�*�7�*�!��g����!���
������?���
�J��	�
�,�}��4��D��U.�U.r%