HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ntp.cpython-311.pyc
�

܍~cGM��
�UdZddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
ddlmZddlmZdd	lmZmZdd
lmZeje��ZeZdZdZgd
�Zdddgdddd�dedgdddd�dedgdddd�ddgdddd�ddgdddd�d�Zddd�dgdd �d!�d"did"did#�dddd$�idd%diidddd&�d'dgddd(�d)d*d+gd+d,d-�d.�d"did/d0d1�d2�d+iid"diddd�d3did4�d"diddd�d3d/id4�d"diddd$�d/d0d1�d4�d"did"did#�d"diddd�d3d/id4�dd%diid5�
Zd6d7d8ed9��eed:��ed;��gedgd<�Z ee!d=<ee ��Ze"gd>���Z#d?�Z$d@�Z%dMdA�Z&dNdB�Z'dC�Z(						dOdD�Z)dE�Z*dFe+dGedHedIedJe,dKdfdL�Z-dS)PzNTP: enable and configure ntp�N)�Logger)�dedent)�log)�subp�
temp_utils�	templater�
type_utils�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEz
/etc/ntp.conf�)�	almalinux�alpine�centos�
cloudlinux�cos�debian�	eurolinux�fedora�freebsd�mariner�miraclelinux�openbsd�	openEuler�openmandriva�opensuse�photon�rhel�rocky�sles�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'r/r0�openntpdr1z/etc/chrony/chrony.conf)r)r+)r)r*r+)r'r/r+)r/r')r+r)r))r)r+r,z/usr/local/etc/chrony.conf)r)r*r+r,z/usr/local/sbin/ntpdz/usr/local/etc/ntp.confr2zntpd.conf.openbsd)r(r)r*r+r,)r/r'r2z"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r(r))r'r1r()r'r/r1)
rrrrrrrrrr r!r#r$�cc_ntp�NTPzenable and configure ntpaD        Handle ntp configuration. If ntp is not installed on the system and
        ntp configuration is specified, ntp will be installed. If there is a
        default ntp config file in the image or one is present in the
        distro's ntp package, it will be copied to a file with ``.dist``
        appended to the filename before any changes are made. A list of ntp
        pools and ntp servers can be provided under the ``ntp`` config key.
        If no ntp ``servers`` or ``pools`` are provided, 4 pools will be used
        in the format ``{0-3}.{distro}.pool.ntp.org``.z�        # Override ntp with chrony configuration on Ubuntu
        ntp:
          enabled: true
          ntp_client: chrony  # Uses cloud-init default chrony configuration
        a�        # Provide a custom ntp client configuration
        ntp:
          enabled: true
          ntp_client: myntpclient
          config:
             confpath: /etc/myntpclient/myntpclient.conf
             check_exe: myntpclientd
             packages:
               - myntpclient
             service_name: myntpclient
             template: |
                 ## template:jinja
                 # My NTP Client config
                 {% if pools -%}# pools{% endif %}
                 {% for pool in pools -%}
                 pool {{pool}} iburst
                 {% endfor %}
                 {%- if servers %}# servers
                 {% endif %}
                 {% for server in servers -%}
                 server {{server}} iburst
                 {% endfor %}
          pools: [0.int.pool.ntp.org, 1.int.pool.ntp.org, ntp.myorg.org]
          servers:
            - ntp.server.local
            - ntp.ubuntu.com
            - 192.168.23.2)�id�name�title�description�distros�examples�	frequency�activate_by_schema_keys�meta)r(r)r*r+c��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$sE�� �D�
�)�%�
&�
&�C�
��~�~�� �#�t�F�|�!4�d�C�C�C���J�c��t|j��}|r7|dkr1t�d|��|�|i��S|�dd��}i}|dkr�|jD]]}|�|��}tj|�d����rt�d|��|}n�^|s=|jd}t�d|��|�|��}n1t�d|��|�|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)	rIr6�LOG�debug�get�
get_option�preferred_ntp_clientsr�which)rMrE�
distro_cfg�distro_ntp_client�	clientcfg�clientrGs       rH�select_ntp_clientrX2sl��+�6�;�7�7�J��.�j�F�*�*��	�	�B�J�	
�	
�	
��~�~�j�"�-�-�-��)�)�,��?�?���I��F�"�"��2�	�	�F��.�.��(�(�C��z�#�'�'�+�.�.�/�/�
��	�	�A�6���� �	���
��	/��1�!�4�F��I�I�N��
�
�
�#���v�.�.�I���	�	�?��	
�	
�	
��N�N�#4�b�9�9�	��rJc�R�tj|��rdS|�dg}||��dS)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.
    Nr/)rrS)�install_funcr*r(s   rH�install_ntp_clientr[ds>���z�)���������7���L������rJc�x�tj�|��rtj||dz��dSdS)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_confrbusA��
�w�~�~�h���2���H�h��0�1�1�1�1�1�2�2rJc	��g}|}|dkrd}n|dks|dkrd}tdt��D]J}|�d�d�t	|��g|gzd	gzD�������K|S)
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�r�.c��g|]}|�|��S�rg)�.0�ns  rH�
<listcomp>z)generate_server_names.<locals>.<listcomp>�s��M�M�M�q�1�M��M�M�MrJzpool.ntp.org)�range�NR_POOL_SERVERS�append�join�str)rE�names�pool_distro�xs    rH�generate_server_namesrss���
�E��K�
����!���	�8�	�	�v��4�4���
�1�o�
&�
&�
�
��
����H�H�M�M�S��V�V�H��}�4��7G�G�M�M�M�
�
�	
�	
�	
�	
��LrJc��|sg}|sg}t|��dkrt|��dkr|dkrdSt|��dkrJ|dkrD|dkr>t|��}t�dd�|����nct|��dkrPt|��dkr=t|��}t�dd�|����|std	���|s|std
���||d�}|r4t
jdd
���}|d}tj	||���tj|||��|rtj|��dSdS)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 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.
    rrNrr.z%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�poolsztemplate_name-z.tmpl)�prefix�suffix�)�content)
�lenrsrNrOrn�
ValueErrorr�mkstempr
�
write_filer�render_to_file�del_file)	�distro_namer+rvrwr^�template_fnr-�params�tfiles	         rH�write_ntp_config_templater��s���4��������
�7�|�|�q���S��Z�Z�1�_�_���1E�1E����G�������8�#�#��F�"�"�(��4�4���	�	�9�3�8�8�G�;L�;L�M�M�M�M�	�W����	�	�s�5�z�z�Q���%�k�2�2���	�	�8�#�(�(�5�/�/�	
�	
�	
��=��;�<�<�<��A�x�A��?�@�@�@� �5�
1�
1�F��7��"�*:�7�K�K�K���A�h�����X�6�6�6�6�
��[�$��7�7�7��#��
�k�"�"�"�"�"�#�#rJc��g}t�t|�������}|rLd�t|����}|�d�|�����nLt|�	d��|�	d��g��s|�d��t|�
����D�],\}}d|z}|dkrOt|t|t��g��s*|�d	�||�
�����`|dkr@t|t��s*|�d�||�
������|d
vrC|���t|t��s*|�d�||�
������t|t��s*|�d�||�
������.|r6td�d�|��������dS)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})�keysr-r,zJEither 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}))r-r,Nz5Expected a string type for {keypath}. Found ({value})z$Invalid ntp configuration:\n{errors}�
)�errors)�REQUIRED_NTP_CONFIG_KEYS�
difference�setr�rn�sortedrm�format�anyrP�items�all�
isinstancero�listr})�
ntp_configr��missingr��keyr�r�s       rH�supplemental_schema_validationr��s����F�&�1�1�#�j�o�o�6G�6G�2H�2H�I�I�G��
��y�y�����)�)���
�
�6�=�=�4�=�H�H�	
�	
�	
�	
��	���
�	#�	#�Z�^�^�O�%D�%D�E���
�	�
�
�
�	
�	
�	
��Z�-�-�/�/�0�0���
��U��#�%���*�����z�%��5�5�6�7�7�
��
�
�'�'-�v�g�U�v�'K�'K������J�
�
��e�T�*�*�
��
�
�'�'-�v�g�U�v�'K�'K������1�
1�
1��}���e�S�)�)�
��
�
�'�'-�v�g�U�v�'K�'K������E�3�'�'�	��M�M�G�N�N�#�5�O���
�
�
���
��3�:�:��y�y��(�(�
;�
�
�
�
�	
�
�
rJr6rG�cloudr�args�returnc��d|vrt�d|��dS|d}|�i}t|t��s5t	d�t
j|��������|�dd��}tj
|��rt�d|��dSt|�d	��|j��}tj
||�d
i��gd���}t|��t|�d���
��d}|�d��sq|�d���d|jj��}	|�|	��}|s'd|�d��z}
t	|
���t'|jj|�d��|�dg��|�dg��|�d��||�d�����t)|jj|d|d���tj���r|�d��dkr�	|j�dd��n/#t0j$rt�d��YnwxYw	|j�dd��n/#t0j$rt�d��YnwxYw	|j�d|�d����n3#t0j$r!}t�d|���d}~wwxYw	|j�d |�d����dS#t0j$r!}t�d!|���d}~wwxYw)"zEnable and configure ntp.r/z8Skipping 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)rar-r,z{distro}z#No template found, not rendering %sr+rvrw)r+rvrwr^r�r-r*r()r*r(r.�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)rNrOr��dict�RuntimeErrorr�r	�obj_namerPr
�is_falserXrErDr�rb�replacer6�get_template_filenamer�r[�install_packages�is_BSD�manage_servicer�ProcessExecutionError�warning�	exception)r6rGr�rr��ntp_cfgr��ntp_client_configr�r,�msg�es            rH�handler�s[��
�C����	�	�F��	
�	
�	
�	���%�j�G������g��&�&�
��
$�$*�F��1D�W�1M�1M�F�$N�$N�
�
�	
��k�k�)�T�*�*�G��}�W�����	�	�=�t�D�D�D���*����L�!�!�5�<�����*�	�G�K�K��"�5�5�6������#�#4�5�5�5��.�2�2�:�>�>�?�?�?�?��K�� � ��,�,�
$�)�-�-�o�>�>�F�F����)�
�
�
��1�1�-�@�@���	$�5�#�'�'��8�8�9�
��s�#�#�#��
���&�*�*�>�:�:����I�r�*�*��k�k�'�2�&�&�
�
"�
"�:�
.�
.��"�&�&�z�2�2������
��%�"�:�.�#�K�0�����
�{�}�}��� � ��0�0�F�:�:�
@���+�+�F�F�;�;�;�;���-�
@�
@�
@����>�?�?�?�?�?�
@����
C���+�+�I�v�>�>�>�>���-�
C�
C�
C����A�B�B�B�B�B�
C����	��L�'�'��+�/�/��?�?�
�
�
�
���)�	�	�	��M�M�<�a�@�@�@������	�����
��#�#��'�+�+�N�;�;�	
�	
�	
�	
�	
���%�����
�
�>��B�B�B�
��������sT�$K�)K,�+K,�0L�)L8�7L8�<.M+�+N�:N�N�.O�O?�O:�:O?)Nr.)N)NNNNNN).�__doc__rBr]�loggingr�textwrapr�	cloudinitrrrrr	r
�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemar
r�cloudinit.settingsr�	getLogger�__name__rNr;�NTP_CONFrlr9rCrAr=�__annotations__�	frozensetr�rIrXr[rbrsr�r�ror�r�rgrJrH�<module>r�sg��$�#�#�����	�	�	�	�������������$�$�$�$�$�$�C�C�C�C�C�C�C�C�C�C�C�C�C�C�!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�+�+�+�+�+�+��g���!�!���	���������4�&��J� �/��
�����G��,��
�����K�!�,��
���$���-��
��6�C��+�)��
��C)�)��^2�%�
�
�
(��"�
�
�
�
�
�F�
�
�I�
�	��	�%�1�
�
��	��1�
��(�"�0�
�
�5�!�
�%�3�	
�
�0�1�#��&�0�
�
���,
�I�
�>�5�
�
�	��	�B��

�I�
�(�"�
�
�

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

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

�=�
�
�
�	��1�
��kz�z��H��
'��6�	:�
�
����
�	
�	
�	��
�	
�	
�'�P� %�w�s:�:��j�:�:�:�v�,�t�
�
��%�9�9�9�9����
���/�/�/�d����"2�2�2�2����>��
�	
��
�?#�?#�?#�?#�D:
�:
�:
�zZ�

�Z��Z�#(�Z�/5�Z�=A�Z�	�Z�Z�Z�Z�Z�ZrJ