404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.225.72.181: ~ $
3

�~�f�R�@s
UdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZddlmZeje�ZeZd	Zd
Zddd
ddddddddddddddddddd d!d"d#d$d%d&gZd'd(d)gd)d*dd+�d,ed-gd-d.dd+�d/ed/gd/d.dd+�d,d0gd,d1dd+�d2d3gd4d5dd+�d6�Zd7d'd8�d	gd,d9�d:�d)d'd7d;�id)d<d7iid	d,d.d=�d>d)gd'd*d?�d@dAdBgdBdCdD�dE�dFd'idGdHdI�dJ�dBiidFd'id	d,d8�dKd2idL�dFd'id	d,d8�dKdGidL�dFd'id,d	d;�dGdHdI�dL�dFd,idFd'idM�dFd'id	d,d8�dKdGidL�d)d<d7iidN�ZxdhD]Zedee<�q WxdiD]Zedee<�q<WxdjD]Zed#ee<�qXWdOdPdQedR�eedS�edT�ged-gdU�Zeee�Ze dKd<dVdFg�Z!dWdX�Z"dYdZ�Z#dkd[d\�Z$dld]d^�Z%d_d`�Z&dmdadb�Z'dcdd�Z(e)ee
e*dde�dfdg�Z+dS)nzNTP: enable and configure ntp�N)�dedent)�subp�
temp_utils�	templater�
type_utils�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEz
/etc/ntp.conf��	almalinux�alpine�centos�
cloudlinux�cos�debian�	eurolinuxZfedora�freebsd�marinerZmiraclelinux�openbsdZ	openeulerZOpenCloudOS�openmandriva�opensuse�opensuse-microos�opensuse-tumbleweed�
opensuse-leap�photon�rhelZrocky�sle_hpc�	sle-micro�slesZ	TencentOS�ubuntuZ	virtuozzoZchronydz/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.confzsystemd-timesyncdztimesyncd.conf)r#r+r,�openntpdzsystemd-timesyncdz/etc/chrony/chrony.conf)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.confr-zntpd.conf.openbsd)r$r%r&r'r()r+r#r-r'z"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r$r%)r#zsystemd-timesyncdr$)r#r+zsystemd-timesyncd)r+r#)rrrrrrrrrrr!r"Zcc_ntpZNTPzenable 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
        aY        # 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 %}
                 {% if peers -%}# peers{% endif %}
                 {% for peer in peers -%}
                 peer {{peer}}
                 {% endfor %}
                 {% if allow -%}# allow{% endif %}
                 {% for cidr in allow -%}
                 allow {{cidr}}
                 {% 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
          allow:
            - 192.168.23.0/32
          peers:
            - km001
            - km002)�id�name�title�description�distrosZexamples�	frequencyZactivate_by_schema_keysr&cCs0t}tjt�}||kr,tj|||gdd�}|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)�distroZdcfg�cfg�r;�/usr/lib/python3.6/cc_ntp.py�distro_ntp_client_configs7s

r=cCs�t|j�}|r.|dkr.tjd|�|j|i�S|jdd�}i}|dkr�x:|jD]0}|j|�}tj|jd��rNtjd|�|}PqNW|s�|jd}tjd|�|j|�}ntjd|�|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)	r=r/�LOG�debug�getZ
get_optionZpreferred_ntp_clientsr�which)r?r9Z
distro_cfgZdistro_ntp_clientZ	clientcfgZclientr:r;r;r<�select_ntp_clientEs4



rDcCs(tj|�rdS|dkrdg}||�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+)rrC)Zinstall_funcr&r$r;r;r<�install_ntp_clientws
	
rEcCs tjj|�rtj||d�dS)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%r;r;r<�rename_ntp_conf�srJcCsng}|}|dkrd}n|dks&|dkr*d}x>tdt�D]0}|jdjdd	�t|�g|gd
gD���q6W|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�.cSsg|]}|r|�qSr;r;)�.0�nr;r;r<�
<listcomp>�sz)generate_server_names.<locals>.<listcomp>zpool.ntp.org)�range�NR_POOL_SERVERS�append�join�str)r9�namesZpool_distro�xr;r;r<�generate_server_names�s(rWc	Cs(|sg}|sg}|sg}|s g}t|�dkrDt|�dkrD|dkrDdSt|�dkr||dkr||dkr|t|�}tjddj|��n2t|�dkr�t|�dkr�t|�}tjddj|��|s�td	��|r�|r�td
��||||d�}	|�rtjdd
d�}
|
d}tj	||d�t
j|||	�|�r$tj|�dS)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.
    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�pools�allow�peersztemplate_name-z.tmpl)�prefix�suffix�)Zcontent)
�lenrWr@rArS�
ValueErrorrZmkstemprZ
write_filerZrender_to_fileZdel_file)Zdistro_namer'rYrZr[r\rG�template_fnr)ZparamsZtfiler;r;r<�write_ntp_config_template�sD  rccCsLg}tjt|j���}|r<djt|��}|jdj|d��n"t|j	d�|j	d�g�s^|jd�x�t|j
��D]�\}}d|}|dkr�t|t|t
�g�s�|jd	j||d
��ql|dkr�t|t�s�|jdj||d
��ql|dk�r
|d
kr�qlt|t
��s(|jdj||d
��qlt|t
�sl|jdj||d
��qlW|�rHtdjdj|�d���d
S)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})Nz5Expected a string type for {keypath}. Found ({value})z$Invalid ntp configuration:\n{errors}�
)�errors)r)r()�REQUIRED_NTP_CONFIG_KEYS�
difference�setrdrS�sortedrR�format�anyrB�items�all�
isinstancerT�listra)Z
ntp_configrhZmissingrd�keyrfrer;r;r<�supplemental_schema_validationsJ



rt)r/r:�cloud�args�returnc.Cs�d|krtjd|�dS|d}|dkr,i}t|t�sLtdjtj|�d���|jdd�}t	j
|�rrtjd|�dSt|jd	�|j�}t	j
||jd
i�gdd�}t|�t|jd�d
�d}|jd��s|jd�jd|jj�}|j|�}|�sd|jd�}	t|	��tjd|jd��tjd|jdg��tjd|jdg��tjd|jdg��tjd|jdg��t|jj|jd�|jdg�|jdg�|jdg�|jdg�|jd�||jd�d�	t|jj|d|dd�t	j��r�|jd�d k�rTy|jjd!d �Wn"tjk
�rtjd"�YnXy|jjd#d �Wn"tjk
�rRtjd$�YnXy|jjd%|jd��Wn4tjk
�r�}
ztjd&|
��WYdd}
~
XnXy|jjd'|jd��Wn4tjk
�r�}
ztjd(|
��WYdd}
~
XnXdS))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)Z_type�enabledTz)Skipping module named %s, disabled by cfgr?�config)r4r%)r%r)r(z{distro}z#No template found, not rendering %szservice_name: %sr'zservers: %srYz	pools: %srZz	allow: %sr[z	peers: %sr\)r'rYrZr[r\rGrbr)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)r@rArq�dict�RuntimeErrorrmrZobj_namerBrZis_falserDr9r8rtrJ�replacer/Zget_template_filenamercrEZinstall_packagesZis_BSDZmanage_servicerZProcessExecutionErrorZwarningZ	exception)r/r:rurvZntp_cfgrxZntp_client_configrbr(�msg�er;r;r<�handle=s�








r�)rrr)rrr)rr )Nr*)N)NNNNNNNN),�__doc__r6ZloggingrF�textwraprZ	cloudinitrrrrrZcloudinit.cloudrZcloudinit.configr	Zcloudinit.config.schemar
rZcloudinit.settingsrZ	getLogger�__name__r@r3ZNTP_CONFrQr2r7r5r9�meta�	frozensetrir=rDrErJrWrcrtrTrrr�r;r;r;r<�<module>s2











		)2



H=

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 128 B 0644
__init__.cpython-36.pyc File 128 B 0644
cc_ansible.cpython-36.opt-1.pyc File 8.63 KB 0644
cc_ansible.cpython-36.pyc File 8.63 KB 0644
cc_apk_configure.cpython-36.opt-1.pyc File 4.51 KB 0644
cc_apk_configure.cpython-36.pyc File 4.51 KB 0644
cc_apt_configure.cpython-36.opt-1.pyc File 30.42 KB 0644
cc_apt_configure.cpython-36.pyc File 30.42 KB 0644
cc_apt_pipelining.cpython-36.opt-1.pyc File 2.44 KB 0644
cc_apt_pipelining.cpython-36.pyc File 2.44 KB 0644
cc_bootcmd.cpython-36.opt-1.pyc File 2.51 KB 0644
cc_bootcmd.cpython-36.pyc File 2.51 KB 0644
cc_byobu.cpython-36.opt-1.pyc File 3.04 KB 0644
cc_byobu.cpython-36.pyc File 3.04 KB 0644
cc_ca_certs.cpython-36.opt-1.pyc File 7.05 KB 0644
cc_ca_certs.cpython-36.pyc File 7.05 KB 0644
cc_chef.cpython-36.opt-1.pyc File 9.13 KB 0644
cc_chef.cpython-36.pyc File 9.13 KB 0644
cc_disable_ec2_metadata.cpython-36.opt-1.pyc File 1.72 KB 0644
cc_disable_ec2_metadata.cpython-36.pyc File 1.72 KB 0644
cc_disk_setup.cpython-36.opt-1.pyc File 23.1 KB 0644
cc_disk_setup.cpython-36.pyc File 23.1 KB 0644
cc_fan.cpython-36.opt-1.pyc File 2.74 KB 0644
cc_fan.cpython-36.pyc File 2.74 KB 0644
cc_final_message.cpython-36.opt-1.pyc File 3.07 KB 0644
cc_final_message.cpython-36.pyc File 3.07 KB 0644
cc_growpart.cpython-36.opt-1.pyc File 15.91 KB 0644
cc_growpart.cpython-36.pyc File 15.91 KB 0644
cc_grub_dpkg.cpython-36.opt-1.pyc File 4.92 KB 0644
cc_grub_dpkg.cpython-36.pyc File 4.92 KB 0644
cc_install_hotplug.cpython-36.opt-1.pyc File 3.25 KB 0644
cc_install_hotplug.cpython-36.pyc File 3.25 KB 0644
cc_keyboard.cpython-36.opt-1.pyc File 1.98 KB 0644
cc_keyboard.cpython-36.pyc File 1.98 KB 0644
cc_keys_to_console.cpython-36.opt-1.pyc File 3.11 KB 0644
cc_keys_to_console.cpython-36.pyc File 3.11 KB 0644
cc_landscape.cpython-36.opt-1.pyc File 4.71 KB 0644
cc_landscape.cpython-36.pyc File 4.71 KB 0644
cc_locale.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_locale.cpython-36.pyc File 1.58 KB 0644
cc_lxd.cpython-36.opt-1.pyc File 13.04 KB 0644
cc_lxd.cpython-36.pyc File 13.04 KB 0644
cc_mcollective.cpython-36.opt-1.pyc File 4.24 KB 0644
cc_mcollective.cpython-36.pyc File 4.24 KB 0644
cc_migrator.cpython-36.opt-1.pyc File 2.92 KB 0644
cc_migrator.cpython-36.pyc File 2.92 KB 0644
cc_mounts.cpython-36.opt-1.pyc File 14.08 KB 0644
cc_mounts.cpython-36.pyc File 14.08 KB 0644
cc_ntp.cpython-36.opt-1.pyc File 13.15 KB 0644
cc_ntp.cpython-36.pyc File 13.15 KB 0644
cc_package_update_upgrade_install.cpython-36.opt-1.pyc File 3.78 KB 0644
cc_package_update_upgrade_install.cpython-36.pyc File 3.78 KB 0644
cc_phone_home.cpython-36.opt-1.pyc File 4.1 KB 0644
cc_phone_home.cpython-36.pyc File 4.1 KB 0644
cc_power_state_change.cpython-36.opt-1.pyc File 6.24 KB 0644
cc_power_state_change.cpython-36.pyc File 6.24 KB 0644
cc_puppet.cpython-36.opt-1.pyc File 9.46 KB 0644
cc_puppet.cpython-36.pyc File 9.46 KB 0644
cc_reset_rmc.cpython-36.opt-1.pyc File 3.59 KB 0644
cc_reset_rmc.cpython-36.pyc File 3.59 KB 0644
cc_resizefs.cpython-36.opt-1.pyc File 7.02 KB 0644
cc_resizefs.cpython-36.pyc File 7.02 KB 0644
cc_resolv_conf.cpython-36.opt-1.pyc File 4.27 KB 0644
cc_resolv_conf.cpython-36.pyc File 4.27 KB 0644
cc_rh_subscription.cpython-36.opt-1.pyc File 12.06 KB 0644
cc_rh_subscription.cpython-36.pyc File 12.06 KB 0644
cc_rightscale_userdata.cpython-36.opt-1.pyc File 2.77 KB 0644
cc_rightscale_userdata.cpython-36.pyc File 2.77 KB 0644
cc_rsyslog.cpython-36.opt-1.pyc File 10.34 KB 0644
cc_rsyslog.cpython-36.pyc File 10.34 KB 0644
cc_runcmd.cpython-36.opt-1.pyc File 2.43 KB 0644
cc_runcmd.cpython-36.pyc File 2.43 KB 0644
cc_salt_minion.cpython-36.opt-1.pyc File 4.36 KB 0644
cc_salt_minion.cpython-36.pyc File 4.36 KB 0644
cc_scripts_per_boot.cpython-36.opt-1.pyc File 1.4 KB 0644
cc_scripts_per_boot.cpython-36.pyc File 1.4 KB 0644
cc_scripts_per_instance.cpython-36.opt-1.pyc File 1.57 KB 0644
cc_scripts_per_instance.cpython-36.pyc File 1.57 KB 0644
cc_scripts_per_once.cpython-36.opt-1.pyc File 1.51 KB 0644
cc_scripts_per_once.cpython-36.pyc File 1.51 KB 0644
cc_scripts_user.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_scripts_user.cpython-36.pyc File 1.58 KB 0644
cc_scripts_vendor.cpython-36.opt-1.pyc File 2.04 KB 0644
cc_scripts_vendor.cpython-36.pyc File 2.04 KB 0644
cc_seed_random.cpython-36.opt-1.pyc File 4.07 KB 0644
cc_seed_random.cpython-36.pyc File 4.07 KB 0644
cc_set_hostname.cpython-36.opt-1.pyc File 4 KB 0644
cc_set_hostname.cpython-36.pyc File 4 KB 0644
cc_set_passwords.cpython-36.opt-1.pyc File 8.4 KB 0644
cc_set_passwords.cpython-36.pyc File 8.4 KB 0644
cc_snap.cpython-36.opt-1.pyc File 5.94 KB 0644
cc_snap.cpython-36.pyc File 5.94 KB 0644
cc_spacewalk.cpython-36.opt-1.pyc File 2.87 KB 0644
cc_spacewalk.cpython-36.pyc File 2.87 KB 0644
cc_ssh.cpython-36.opt-1.pyc File 11.02 KB 0644
cc_ssh.cpython-36.pyc File 11.02 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.opt-1.pyc File 3.54 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.pyc File 3.54 KB 0644
cc_ssh_import_id.cpython-36.opt-1.pyc File 3.85 KB 0644
cc_ssh_import_id.cpython-36.pyc File 3.85 KB 0644
cc_timezone.cpython-36.opt-1.pyc File 1.24 KB 0644
cc_timezone.cpython-36.pyc File 1.24 KB 0644
cc_ubuntu_advantage.cpython-36.opt-1.pyc File 12.42 KB 0644
cc_ubuntu_advantage.cpython-36.pyc File 12.42 KB 0644
cc_ubuntu_autoinstall.cpython-36.opt-1.pyc File 3.89 KB 0644
cc_ubuntu_autoinstall.cpython-36.pyc File 3.89 KB 0644
cc_ubuntu_drivers.cpython-36.opt-1.pyc File 3.63 KB 0644
cc_ubuntu_drivers.cpython-36.pyc File 3.63 KB 0644
cc_update_etc_hosts.cpython-36.opt-1.pyc File 4.3 KB 0644
cc_update_etc_hosts.cpython-36.pyc File 4.3 KB 0644
cc_update_hostname.cpython-36.opt-1.pyc File 3.01 KB 0644
cc_update_hostname.cpython-36.pyc File 3.01 KB 0644
cc_users_groups.cpython-36.opt-1.pyc File 7.58 KB 0644
cc_users_groups.cpython-36.pyc File 7.58 KB 0644
cc_wireguard.cpython-36.opt-1.pyc File 8.39 KB 0644
cc_wireguard.cpython-36.pyc File 8.39 KB 0644
cc_write_files.cpython-36.opt-1.pyc File 5.61 KB 0644
cc_write_files.cpython-36.pyc File 5.61 KB 0644
cc_write_files_deferred.cpython-36.opt-1.pyc File 1.73 KB 0644
cc_write_files_deferred.cpython-36.pyc File 1.73 KB 0644
cc_yum_add_repo.cpython-36.opt-1.pyc File 6.03 KB 0644
cc_yum_add_repo.cpython-36.pyc File 6.03 KB 0644
cc_zypper_add_repo.cpython-36.opt-1.pyc File 5.66 KB 0644
cc_zypper_add_repo.cpython-36.pyc File 5.66 KB 0644
modules.cpython-36.opt-1.pyc File 7.31 KB 0644
modules.cpython-36.pyc File 7.31 KB 0644
schema.cpython-36.opt-1.pyc File 39.45 KB 0644
schema.cpython-36.pyc File 39.45 KB 0644