Current File : //lib/python2.7/site-packages/cloudinit/config/cc_ntp.pyc
�
oB�]c
@sdZddlmZmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	l
Z
dd	lZdd	lZdd
lmZeje�ZeZdZdZd
ddddddgZiidd6dd6dgd6dd6dd6d	d6d6idd6ed6dgd6dd6d d6d	d6d6id!d6ed6d!gd6d!d6d d6d	d6d!6id"d6d#d6gd6d$d6d%d6d	d6d$6Ziiid&d6d6d6iidd6d6idd6dd6d6id'd6d$6d6iidd6d6idd6dd6d6id'd6d$6d6iid&d6d6d6Zi	d(d)6d*d+6d,d-6ed.�d/6ed06ed1�ed2�gd36ed46d5d66iid5d7gd66iid8d66id9d66d:d;6d<6ed=6ed>�d/6d?6id8d66id9d66d:d;6d<6ed=6ed@�d/6dA6id9d66dBdC6edD�d/6dE6idFd66edC6edG�d/6dH6iedI�d/6d5gd66iid9d66edJ�d/6d6id9d66edK�d/6d6id8d66id9d66d<6ed=6edL�d/6d6id9d66edM�d/6d6id9d66edN�d/6d6dO6gdP6dQdR6edS6dT6dO6gdP6edS6d6dO6Zeddddg�Z ee�ZdU�Z!dV�Z"d	ddW�Z#d	dX�Z$dY�Z%d	d	d	d	d	dZ�Z&ed[�Z'd\�Z(d]�Z)d	S(^sNTP: enable and configure ntpi����(tget_schema_doctvalidate_cloudconfig_schema(tlog(tPER_INSTANCE(t
temp_utils(t	templater(t
type_utils(tutilN(tdedents
/etc/ntp.confitcentostdebiantfedoratopensusetrheltslestubuntutchronydt	check_exes/etc/chrony.conftconfpathtchronytpackagestservice_nameschrony.conf.{distro}t
template_namettemplatetntpdtntpsntp.conf.{distro}tntpdates/lib/systemd/systemd-timesyncds-/etc/systemd/timesyncd.conf.d/cloud-init.confssystemd-timesyncdstimesyncd.confs/etc/chrony/chrony.confs"/usr/lib/systemd/systemd-timesyncdtcc_ntptidtNTPtnamesenable and configure ntpttitles,        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 ``/etc/ntp.conf.dist``
        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``.tdescriptiontdistross�        # Override ntp with chrony configuration on Ubuntu
        ntp:
          enabled: true
          ntp_client: chrony  # Uses cloud-init default chrony configuration
        s�        # 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.2texamplest	frequencytobjectttypetnulltarraytstringthostnametformattitemstuniqueItemss�                        List of ntp pools. If both pools and servers are
                         empty, 4 default pool servers will be provided of
                         the format ``{0-3}.{distro}.pool.ntp.org``.tpoolss�                        List of ntp servers. If both pools and servers are
                         empty, 4 default pool servers will be provided with
                         the format ``{0-3}.{distro}.pool.ntp.org``.tserverstautotdefaults�                        Name of an NTP client to use to configure system NTP.
                         When unprovided or 'auto' the default client preferred
                         by the distribution will be used. The following
                         built-in client names can be used to override existing
                         configuration defaults: chrony, ntp, ntpdate,
                         systemd-timesyncd.t
ntp_clienttbooleans�                        Attempt to enable ntp clients if set to True.  If set
                         to False, ntp client will not be configured or
                         installedtenabledsv                        Configuration settings or overrides for the
                         ``ntp_client`` specified.s                                The path to where the ``ntp_client``
                                 configuration is written.s�                                The executable name for the ``ntp_client``.
                                 For example, ntp service ``check_exe`` is
                                 'ntpd' because it runs the ntpd binary.s�                                List of packages needed to be installed for the
                                 selected ``ntp_client``.s�                                The systemd or sysvinit service name used to
                                 start and stop the ``ntp_client``
                                 service.sP                                Inline template allowing users to define their
                                 own ``ntp_client`` configuration template.
                                 The value must start with '## template:jinja'
                                 to enable use of templating support.
                                t
propertiestrequiredit
minPropertiestadditionalPropertiestconfigcCsGt}tjt�}||krCtj|||gdt�}n|S(s�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.
    treverse(tDISTRO_CLIENT_CONFIGtcopytNTP_CLIENT_CONFIGRt
mergemanydicttTrue(tdistrotdcfgtcfg((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytdistro_ntp_client_configss
"cCst|j�}|rA|dkrAtjd|�|j|i�S|jdd�}i}|dkr�xR|jD]G}|j|�}tj|jd��rotjd|�|}PqoqoW|s|jd}tjd|�|j|�}qn"tjd|�|j|i�}|S(	s
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.
    R/s4Selected NTP client "%s" via user-data configurationR1Rs+Selected NTP client "%s", already installedis<Selected distro preferred NTP client "%s", not yet installeds1Selected NTP client "%s" via distro system config(	RBRtLOGtdebugtgett
get_optiontpreferred_ntp_clientsRtwhich(R1R?t
distro_cfgtdistro_ntp_clientt	clientcfgtclientRA((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytselect_ntp_clients2
		
	cCs9tj|�rdS|dkr+dg}n||�dS(shInstall 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(RRHtNone(tinstall_funcRR((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytinstall_ntp_clientLs
	cCs-tjj|�r)tj||d�ndS(s�Rename any existing ntp client config file

    @param confpath: string. Specify a path to an existing ntp client
    configuration file.
    s.distN(tostpathtexistsRtrename(R((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytrename_ntp_conf]scCs\g}|}|dkr!d}nx4tdt�D]#}d||f}|j|�q1W|S(s�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.
    RRis%d.%s.pool.ntp.org(trangetNR_POOL_SERVERStappend(R?tnamestpool_distrotxR((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytgenerate_server_namesgs	cCs|sg}n|sg}nt|�dkrjt|�dkrjt|�}tjddj|��n|std��n|r�|r�td��ni|d6|d6}|r�tjdd	d
d�}|d}tj	|d
|�nt
j|||�|rtj|�ndS(s�Render a ntp client configuration for the specified client.

    @param distro_name: string.  The distro class name.
    @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.
    is*Adding distro default ntp pool servers: %st,s Invalid value for path parameters$Not template_fn or template providedR.R-tprefixstemplate_name-tsuffixs.tmplitcontentN(
tlenR\RCRDtjoint
ValueErrorRtmkstempRt
write_fileRtrender_to_filetdel_file(tdistro_nameR.R-RRttemplate_fnRtparamsttfile((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytwrite_ntp_config_templatezs(		$
cCs>|rdd|g}nd|dg}tj|dt�dS(s%Restart or reload an ntp system service.

    @param service: A string specifying the name of the service to be affected.
    @param systemd: A boolean indicating if the distro uses systemd, defaults
    to False.
    @returns: A tuple of stdout, stderr results from executing the action.
    t	systemctlsreload-or-restarttservicetrestarttcaptureN(RtsubpR>(Rntsystemdtcmd((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pyt
reload_ntp�scCs�g}tjt|j���}|rXdjt|��}|jdjd|��n4t|j	d�|j	d�g�s�|jd�nxBt|j
��D].\}}d|}|dkrt|t|t
j�g�s�|jd	jd
|d|��q�q�|dkrDt|t�s�|jd
jd
|d|��q�q�|dkr�|dkrbq�nt|t
j�s�|jdjd
|d|��q�q�t|t
j�s�|jdjd
|d|��q�q�W|r�tdjddj|����ndS(sOValidate 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.
    s, s(Missing required ntp:config keys: {keys}tkeysRRsJEither ntp:config:template or ntp:config:template_name values are requiredsntp:config:Rs6Expected a config file path {keypath}. Found ({value})tkeypathtvalueRsHExpected a list of required package names for {keypath}. Found ({value})s5Expected a string type for {keypath}. Found ({value})s$Invalid ntp configuration:\n{errors}terrorss
N(stemplates
template_name(tREQUIRED_NTP_CONFIG_KEYSt
differencetsetRuRbtsortedRXR*tanyRER+tallt
isinstancetsixtstring_typestlistRNRc(t
ntp_configRxtmissingRutkeyRwRv((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pytsupplemental_schema_validation�sH


				c
CsSd|kr tjd|�dS|d}|dkr?i}nt|t�srtdjdtj|����nt	|t
�|jdt�}t
j|�r�tjd|�dSt|jd�|j�}t
j||jd	i�gd
t�}t|�td|jd��d}|jd�s�|jd
�jd|jj�}	|j|	�}|s�d|jd
�}
t|
��q�nt|jjd|jdg�d|jdg�d|jd�d|d|jd��t|jjd|dd|d�y!t|dd|jj��Wn)t
jk
rN}tjd|��nXdS(sEnable and configure ntp.Rs8Skipping module named %s, not present or disabled by cfgNsL'ntp' key existed in config, but not a dictionary type, is a {_type} insteadt_typeR3s)Skipping module named %s, disabled by cfgR1R8R9RRRs{distro}s#No template found, not rendering %sR.R-RRRiRRRRrs&Failed to reload/start ntp service: %s(RCRDRNRtdicttRuntimeErrorR*Rtobj_nameRtschemaRER>Rtis_falseRMR?R=R�RUtreplaceRtget_template_filenameRlRPtinstall_packagesRttuses_systemdtProcessExecutionErrort	exception(RRAtcloudRt_argstntp_cfgR3tntp_client_configRiRtmsgte((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pythandle�s\

		
!


(*t__doc__tcloudinit.config.schemaRRt	cloudinitRtloggingtcloudinit.settingsRRRRRR;RQR�ttextwrapRt	getLoggert__name__RCR#tNTP_CONFRWR!RNR<R:R>tFalseR�t	frozensetRyRBRMRPRUR\RlRtR�R�(((s;/usr/lib/python2.7/site-packages/cloudinit/config/cc_ntp.pyt<module>s:







		-
	-	2