%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ntp.cpython-312.pyc

�

���f�K���UdZddlZddlZddlZddlmZmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZej$e�ZeZdZd	Zgd
�Zddd
gd
ddd�dedgdddd�dedgdddd�ddgdddd�ddgdddd�d�Zddd�dgdd�d�ddd d!�id"didd d!�d#�d"did"did$�d
ddd%�id
d&diidddd'�d(d
gddd)�d*d+d,gd,d-d.�d/�d"didd d!�d#�d,iid"diddd�d0did1�d"diddd�d0did1�d"diddd%�dd d!�d1�d"did"did$�d"diddd�d0did1�d
d&diid2�Zd3D]
Zed4ee<�d5D]
Zed6ee<�d7D]
Zed8ee<�d9eedgd:�Zeed;<egd<��Zd=�Z d>�Z!dJd?�Z"dKd@�Z#dA�Z$								dLdB�Z%dC�Z&dDe'dEe
dFedGe(dHdf
dI�Z)y)MzNTP: enable and configure ntp�N)�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�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,r4r5�openntpdr6z/etc/chrony/chrony.conf)r.r0)r.r/r0)r,r4z"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r-r.r0)r,r6)r4r,)r0r.r.)r.r0r1z/usr/local/etc/chrony.conf)r.r/r0r1z/usr/local/sbin/ntpdz/usr/local/etc/ntp.confr7zntpd.conf.openbsd)r-r.r/r0r1)r4r,r7r-)r,r4r6)rrrrrrrrrrrr"r#r'r))rr r!r)r
rr#)r%r&r'�cc_ntp)�id�distros�	frequency�activate_by_schema_keys�meta)r-r.r/r0c��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)�DISTRO_CLIENT_CONFIG�copy�NTP_CLIENT_CONFIGr�
mergemanydict)�distro�dcfg�cfgs   �9/usr/lib/python3/dist-packages/cloudinit/config/cc_ntp.py�distro_ntp_client_configsrIs?�� �D�
�)�)�%�
&�C�
��~�� � �#�t�F�|�!4�d�C���J�c�D�t|j�}|r-|dk7r(tjd|�|j	|i�S|jdd�}i}|dk(r�|jD]Q}|j	|�}tj|j	d��s�9tjd|�|}n|s6|jd}tjd|�|j	|�}|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_clientr-z+Selected NTP client "%s", already installedrz<Selected distro preferred NTP client "%s", not yet installedz1Selected NTP client "%s" via distro system config)	rI�name�LOG�debug�get�
get_option�preferred_ntp_clientsr�which)rMrE�
distro_cfg�distro_ntp_client�	clientcfg�clientrGs       rH�select_ntp_clientrYs#��+�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�.�I���
	�	�	�?��	
��N�N�#4�b�9�	��rJc�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.
    Nr4)rrT)�install_funcr/r-s   rH�install_ntp_clientr\Ls(���z�z�)������7����rJc�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�r.s rH�rename_ntp_confrc]s,��
�w�w�~�~�h�����H�h��0�1� rJc	���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'rrr��.zpool.ntp.org)�range�NR_POOL_SERVERS�append�join�str)rE�names�pool_distro�x�ns     rH�generate_server_namesrpgs���
�E��K�
���!��	�8�	�v��4���
�?�
#�
��
����H�H� ��V�H��}�4��7G�G�M�q�1��M�
�	
�
��L��	Ns�A2�A2c	��|sg}|sg}|sg}|sg}t|�dk(rt|�dk(r|dk(ryt|�dk(r;|dk(r6|dk(r1t|�}tjddj	|��nLt|�dk(r>t|�dk(r0t|�}tjddj	|��|std	��|s
|std
��||||d�}	|r3t
jdd
��}
|
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.
    rrNrr3z%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)
�lenrprOrPrj�
ValueErrorr�mkstempr�
write_filer�render_to_file�del_file)�distro_namer0rsrtrurvr_�template_fnr2�params�tfiles           rH�write_ntp_config_templater��sJ��@������������
�7�|�q��S��Z�1�_���1E���G�����8�#��F�"�(��4���	�	�9�3�8�8�G�;L�M�	�W���	�s�5�z�Q��%�k�2���	�	�8�#�(�(�5�/�	
���;�<�<��x��?�@�@�����	�F���"�"�*:�7�K���A�h������X�6�
���[�$��7���
�
�k�"�rJc���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})�keysr2r1zJEither ntp:config:template or ntp:config:template_name values are requiredzntp:config:r.z6Expected a config file path {keypath}. Found ({value}))�keypath�valuer/zHExpected a list of required package names for {keypath}. Found ({value}))r2r1Nz5Expected a string type for {keypath}. Found ({value})z$Invalid ntp configuration:\n{errors}�
)�errors)�REQUIRED_NTP_CONFIG_KEYS�
difference�setr�rj�sortedri�format�anyrQ�items�all�
isinstancerk�listr|)�
ntp_configr��missingr��keyr�r�s       rH�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��(�
;�
�
�	
�rJrNrG�cloud�args�returnc
�	�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�sg|jd�j!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,�rz|jd�d k7r:	|jj/d!d �	|jj/d#d �	|jj/d%|jd��	|jj/d'|jd��y#t0j2$rtj5d"�Y��wxYw#t0j2$rtj5d$�Y��wxYw#t0j2$r}
tj7d&|
��d}
~
wwxYw#t0j2$r}
tj7d(|
��d}
~
wwxYw))zEnable and configure ntp.r4z8Skipping 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 cfgrM�configr?r.rbr2r1z{distro}z#No template found, not rendering %szservice_name: %sr0zservers: %srsz	pools: %srtz	allow: %sruz	peers: %srv)r0rsrtrurvr_r�r2r/r-)r/r-r3�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)rOrPr��dict�RuntimeErrorr�r�obj_namerQr�is_falserYrErDr�rc�replacerN�get_template_filenamer�r\�install_packages�is_BSD�manage_servicer�ProcessExecutionError�warning�	exception)rNrGr�r��ntp_cfgr��ntp_client_configr�r1�msg�es           rH�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�� � ��,�)�-�-�o�>�F�F�����)�)�
�
��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�;�	
���-�-�
@����>�?�
@���-�-�
C����A�B�
C���)�)�	��M�M�<�a�@���	���%�%���
�
�>��B�
���sT�2O�O2�,+P �+Q�(O/�.O/�2(P�P� Q�3Q
�
Q�R�%Q<�<R)Nr3)N)NNNNNNNN)*�__doc__rB�loggingr^�	cloudinitrrrrr�cloudinit.cloudr�cloudinit.configr	�cloudinit.config.schemar
�cloudinit.settingsr�	getLogger�__name__rOr;�NTP_CONFrhr:rCrArEr=�__annotations__�	frozensetr�rIrYr\rcrpr�r�rkr�r��rJrH�<module>r�s���$���	�C�C�!�#�.�+��g����!���	�������F�&��J� �/��
����G��,��
����K�!�,��
��$���-��
�6�C��+�)��
�C)��^2�%�
�
(��"�
�
�	�=�5�
�
�
�I�
�>�5�
�	�
�F�
�
�I�
�	�	�%�1�
��	��1�
��(�"�0�
�5�!�
�%�3�	
�0�1�#��&�0�
��,
�I�
�>�5�
�	�	�B��

�I�
�(�"�
�

�9�
��
�I�
�(�"�
�

�=�
��
�I�
�!'�O�D�=�5�
�	�
�F�
�
�I�
�	
�
�I�
�(�"�
�

�=�
�
�	��1�
��II��VK�D�F�#7�
�#C��� �D�*�@�F�#7��#?��� �@�'�@�F�#7��#?��� �@���� %�w�	��j��%�9���
�/�d�"2��>��
�
�
�	
��
�N#�b:
�z_��_�6�_�%�_�t�_��_rJ

Zerion Mini Shell 1.0