HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ntp.cpython-312.pyc
�

쑛h1L��x�UdZddlZddlZddlZddlmZmZddlmZm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZej*e�ZeZd	Zd
Zgd�Zdd
dgdddd�dedgdddd�dedgdddd�ddgdddd�ddgdddd�d�Zidddd�d	gdd�d ��d!dd"d#d$�i�d%d&did"d#d$�d'��d(d&did&did)��d*dddd+�i�d,dd-dii�d.d	ddd/�d0dgddd1�d2d3d4gd4d5d6�d7��d8d&did"d#d$�d'��d9d4ii�d:d&did	dd�d;did<��d=d&did	dd�d;d"id<��d>d&didd	d+�d"d#d$�d<��d?dd-dii�d@d&did&did)��dAd&did	dd�d;d"id<��dBdd-dii�ZeeefedC<dDD]
Z ed=ee <�dED]
Z ed@ee <�dFD]
Z edAee <�dGeedgdH�Z!eedI<e"gdJ��Z#dK�Z$dLefdM�Z%dXdN�Z&dYdO�Z'dP�Z(								dZdQ�Z)dR�Z*dSedTedUedVe+dLdf
dW�Z,y)[zNTP: enable and configure ntp�N)�Dict�Mapping)�subp�
temp_utils�	templater�
type_utils�util)�Cloud)�Config)�
MetaSchema)�PER_INSTANCEz
/etc/ntp.conf�)�	almalinux�alpine�aosc�
azurelinux�centos�
cloudlinux�cos�debian�	eurolinux�fedora�freebsd�mariner�miraclelinux�openbsd�	openeuler�OpenCloudOS�openmandriva�opensuse�opensuse-microos�opensuse-tumbleweed�
opensuse-leap�photon�raspberry-pi-os�rhel�rocky�sle_hpc�	sle-micro�sles�	TencentOS�ubuntu�	virtuozzo�chronydz/etc/chrony.conf�chronyzchrony.conf.{distro})�	check_exe�confpath�packages�service_name�
template_name�template�ntpd�ntpzntp.conf.{distro}�ntpdatez/etc/ntpd.confzntpd.conf.{distro}z/lib/systemd/systemd-timesyncdz-/etc/systemd/timesyncd.conf.d/cloud-init.conf�systemd-timesyncdztimesyncd.conf)r/r7r8�openntpdr9rz/etc/chrony/chrony.conf)r1r3)r1r2r3)r/r7rz"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r0r1rr3)r/r9r)r7r/r)r3r1rr1r)r1r3r4z/usr/local/etc/chrony.conf)r1r2r3r4z/usr/local/sbin/ntpdz/usr/local/etc/ntp.confr:zntpd.conf.openbsd)r0r1r2r3r4)r7r/r:rrrr0)r/r7r9r r$r%r&r*r,�DISTRO_CLIENT_CONFIG)r!r"r#)rrr')r(r)�cc_ntp)�id�distros�	frequency�activate_by_schema_keys�meta)r0r1r2r3c��t}tjt�}||vrtj|||gd��}|S)z�Construct a distro-specific ntp client config dictionary by merging
       distro specific changes into base config.

    @param distro: String providing the distro class name.
    @returns: Dict of distro configurations for ntp clients.
    T��reverse)r;�copy�NTP_CLIENT_CONFIGr	�
mergemanydict)�distro�dcfg�cfgs   �9/usr/lib/python3/dist-packages/cloudinit/config/cc_ntp.py�distro_ntp_client_configsrLs?�� �D�
�)�)�%�
&�C�
��~�� � �#�t�F�|�!4�d�C���J��returnc�F�t|j�}|r-|dk7r(tjd|�|j	|i�S|jdd�}i}|dk(r�|jD]Q}|j	|�}tj|j	d��s�9tjd|�|}n|s7|jd}tjd|�|j	|i�}|Stjd|�|j	|i�}|S)	a
Determine which ntp client is to be used, consulting the distro
       for its preference.

    @param ntp_client: String name of the ntp client to use.
    @param distro: Distro class instance.
    @returns: Dict of the selected ntp client or {} if none selected.
    �autoz4Selected NTP client "%s" via user-data configuration�
ntp_clientr0z+Selected NTP client "%s", already installedrz<Selected distro preferred NTP client "%s", not yet installedz1Selected NTP client "%s" via distro system config)	rL�name�LOG�debug�get�
get_option�preferred_ntp_clientsr�which)rQrH�
distro_cfg�distro_ntp_client�	clientcfg�clientrJs       rK�select_ntp_clientr]!s%��+�6�;�;�7�J��j�F�*��	�	�B�J�	
��~�~�j�"�-�-��)�)�,��?���I��F�"��2�2�	�F��.�.��(�C��z�z�#�'�'�+�.�/��	�	�A�6�� �	��	���1�1�!�4�F��I�I�N��
�#���v�r�2�I���
	�	�	�?��	
��N�N�#4�b�9�	��rMc�J�tj|�ry|�dg}||�y)ahInstall ntp client package if not already installed.

    @param install_func: function.  This parameter is invoked with the contents
    of the packages parameter.
    @param packages: list.  This parameter defaults to ['ntp'].
    @param check_exe: string.  The name of a binary that indicates the package
    the specified package is already installed.
    Nr7)rrX)�install_funcr2r0s   rK�install_ntp_clientr`Ss(���z�z�)������7����rMc�v�tjj|�rtj||dz�yy)z�Rename any existing ntp client config file

    @param confpath: string. Specify a path to an existing ntp client
    configuration file.
    z.distN)�os�path�existsr	�rename�r1s rK�rename_ntp_confrgds,��
�w�w�~�~�h�����H�h��0�1� rMc	���g}|}|dk(rd}n|dk(s|dk(rd}tt�D]E}|jdjt	|�g|gzdgzD�cgc]}|s�|��	c}���G|Scc}w)z�Generate a list of server names to populate an ntp client configuration
    file.

    @param distro: string.  Specify the distro name
    @returns: list: A list of strings representing ntp servers for this distro.
    r*r rr��.zpool.ntp.org)�range�NR_POOL_SERVERS�append�join�str)rH�names�pool_distro�x�ns     rK�generate_server_namesrtns���
�E��K�
���!��	�8�	�v��4���
�?�
#�
��
����H�H� ��V�H��}�4��7G�G�M�q�1��M�
�	
�
��L��	Ns�A2�A2c	�(�|sg}|sg}|sg}|sg}|s|s|dk(ry|s;|dk(r6|dk(r1t|�}tjddj|��n4|s2|s0t|�}tjddj|��|st	d��|s
|st	d	��||||d
�}	|r3tjdd�
�}
|
d}tj||��tj|||	�|rtj|�yy)a�Render a ntp client configuration for the specified client.

    @param distro_name: string.  The distro class name.
    @param service_name: string. The name of the NTP client service.
    @param servers: A list of strings specifying ntp servers. Defaults to empty
    list.
    @param pools: A list of strings specifying ntp pools. Defaults to empty
    list.
    @param allow: A list of strings specifying a network/CIDR. Defaults to
    empty list.
    @param peers: A list nodes that should peer with each other. Defaults to
    empty list.
    @param path: A string to specify where to write the rendered template.
    @param template_fn: A string to specify the template source file.
    @param template: A string specifying the contents of the template. This
    content will be written to a temporary file before being used to render
    the configuration file.

    @raises: ValueError when path is None.
    @raises: ValueError when template_fn is None and template is None.
    rNrr6z%Adding distro default ntp servers: %s�,z*Adding distro default ntp pool servers: %sz Invalid value for path parameterz$Not template_fn or template provided)�servers�pools�allow�peersztemplate_name-z.tmpl)�prefix�suffix�)�content)rtrSrTrn�
ValueErrorr�mkstempr	�
write_filer�render_to_file�del_file)�distro_namer3rwrxryrzrc�template_fnr5�params�tfiles           rK�write_ntp_config_templater��s��@�������������5�[�E�%9���{�h�.�<�6�3I�(��4���	�	�9�3�8�8�G�;L�M���%�k�2���	�	�8�#�(�(�5�/�	
���;�<�<��x��?�@�@�����	�F���"�"�*:�7�K���A�h������X�6�
���[�$��7���
�
�k�"�rMc���g}tjt|j���}|r<dj	t|��}|j
dj|���n<t|jd�|jd�g�s|j
d�t|j��D]�\}}d|z}|dk(r?t|t|t�g�r�,|j
d	j||�
���O|dk(r4t|t�r�e|j
dj||�
����|d
vr7|���t|t�r��|j
dj||�
����t|t�r��|j
dj||�
����|r*tdjdj	|�����y)aOValidate user-provided ntp:config option values.

    This function supplements flexible jsonschema validation with specific
    value checks to aid in triage of invalid user-provided configuration.

    @param ntp_config: Dictionary of configuration value under 'ntp'.

    @raises: ValueError describing invalid values provided.
    z, z(Missing required ntp:config keys: {keys})�keysr5r4zJEither ntp:config:template or ntp:config:template_name values are requiredzntp:config:r1z6Expected a config file path {keypath}. Found ({value}))�keypath�valuer2zHExpected a list of required package names for {keypath}. Found ({value}))r5r4Nz5Expected a string type for {keypath}. Found ({value})z$Invalid ntp configuration:\n{errors}�
)�errors)�REQUIRED_NTP_CONFIG_KEYS�
difference�setr�rn�sortedrm�format�anyrU�items�all�
isinstancero�listr)�
ntp_configr��missingr��keyr�r�s       rK�supplemental_schema_validationr��s����F�&�1�1�#�j�o�o�6G�2H�I�G���y�y����)���
�
�6�=�=�4�=�H�	
��	���
�	#�Z�^�^�O�%D�E��	�
�
�
�	
��Z�-�-�/�0��
��U��#�%���*����z�%��5�6�7��
�
�'�'-�v�g�U�v�'K���J�
��e�T�*��
�
�'�'-�v�g�U�v�'K���1�
1��}���e�S�)��
�
�'�'-�v�g�U�v�'K���E�3�'��M�M�G�N�N�#�5�O��
�/�:��3�:�:��y�y��(�
;�
�
�	
�rMrRrJ�cloud�argsc
��d|vrtjd|�y|d}|�i}t|t�s.t	djt
j|�����|jdd�}tj|�rtjd|�yt|jd	�|j�}tj||jd
i�gd��}t|�t|jd��
�d}|jd�s[|dj!d|jj"�}|j%|�}|sd|jd�z}	t	|	��tjd|jd��tjd|jdg��tjd|jdg��tjd|jdg��tjd|jdg��t'|jj"|jd�|jdg�|jdg�|jdg�|jdg�|jd�||jd���	t)|jj*|d|d��tj,�rn|jd�d k7r:	|jj/d!d �	|jj/d#d �	|jj/d%|d�	|jj/d'|d�y#t0j2$rtj5d"�Y��wxYw#t0j2$rtj5d$�Y��wxYw#t0j2$r}
tj7d&|
��d}
~
wwxYw#t0j2$r}
tj7d(|
��d}
~
wwxYw))zEnable and configure ntp.r7z8Skipping module named %s, not present or disabled by cfgNzL'ntp' key existed in config, but not a dictionary type, is a {_type} instead)�_type�enabledTz)Skipping module named %s, disabled by cfgrQ�configrCr1rfr5r4z{distro}z#No template found, not rendering %szservice_name: %sr3zservers: %srwz	pools: %srxz	allow: %sryz	peers: %srz)r3rwrxryrzrcr�r5r2r0)r2r0r6�stopz Failed to stop base ntpd service�disablez#Failed to disable base ntpd service�enablez Failed to enable ntp service: %s�reloadz&Failed to reload/start ntp service: %s)rSrTr��dict�RuntimeErrorr�r�obj_namerUr	�is_falser]rHrGr�rg�replacerR�get_template_filenamer�r`�install_packages�is_BSD�manage_servicer�ProcessExecutionError�warning�	exception)rRrJr�r��ntp_cfgr��ntp_client_configr�r4�msg�es           rK�handler�s����C���	�	�F��	
�	��%�j�G������g��&��
$�$*�F��1D�1D�W�1M�F�$N�
�	
��k�k�)�T�*�G��}�}�W���	�	�=�t�D��*����L�!�5�<�<����*�*�	�G�K�K��"�5�6����#�#4�5��.�2�2�:�>�?��K�� � ��,�)�/�:�B�B�����)�)�
�
��1�1�-�@���5�#�'�'��8�9�
��s�#�#��I�I� �"3�"7�"7��"G�H��I�I�m�W�[�[��B�7�8��I�I�k�7�;�;�w��3�4��I�I�k�7�;�;�w��3�4��I�I�k�7�;�;�w��3�4��
�����&�*�*�>�:����I�r�*��k�k�'�2�&��k�k�'�2�&��k�k�'�2�&�
�
"�
"�:�
.��"�&�&�z�2�
��
���%�%�"�:�.�#�K�0��
�{�{�}�� � ��0�F�:�
@����+�+�F�F�;�
C����+�+�I�v�>�	��L�L�'�'��+�N�;�
��
���#�#��'��7�	
���-�-�
@����>�?�
@���-�-�
C����A�B�
C���)�)�	��M�M�<�a�@���	���%�%���
�
�>��B�
���sT�&N �O� O<�P.� (O�
O�(O9�8O9�<P+�P&�&P+�.Q�Q�Q)Nr6)N)NNNNNNNN)-�__doc__rE�loggingrb�typingrr�	cloudinitrrrrr	�cloudinit.cloudr
�cloudinit.configr�cloudinit.config.schemar�cloudinit.settingsr
�	getLogger�__name__rSr?�NTP_CONFrlr>rFr;ro�__annotations__rHrA�	frozensetr�rLr]r`rgrtr�r�r�r��rMrK�<module>r�s���$���	� �C�C�!�#�.�+��g����!���	����� ��H�&��J� �/��
����G��,��
����K�!�,��
��$���-��
�6�C��+�)��
�C)��XN)��1�%�
�
(��"�
�
�N)���=�5�
�
�N)�$��I�
�>�5�
�	�%N)�6
��F�
�
�I�
�	�7N)�F
��%�1�
��GN)�R
���1�
��SN)�\�'�"�0�
�5�!�
�%�3�	
�0�1�#��&�0�
��]N)�D��I�
�>�5�
�	�EN)�V��B��WN)�\��I�
�(�"�
�

�9�
��]N)�t��I�
�(�"�
�

�=�
��uN)�L
��I�
�!'�O�D�=�5�
�	�MN)�`���1�
��aN)�j��F�
�
�I�
�	
�kN)�z��I�
�(�"�
�

�=�
�
�{N)�R
���1�
��SN)��d�3��9�o�N�`K�D�F�#7�
�#C��� �D�3�@�F�#7��#?��� �@�'�@�F�#7��#?��� �@���� %�w�	��j��%�9���
�/�W�/�d�"2��>��
�
�
�	
��
�J#�Z:
�z_��_�6�_�%�_�t�_��_rM