fRUdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z ddl m Z ddlmZddlmZmZddlmZej*eZeZd Zd Zgd Zd d dgdddddedgdddddedgddddddgddddddgdddddZdd dd gdddd did d id!dd dd"idd#diid ddd$d%dgd dd&d'd(d)gd)d*d+d,d d id-d.d/d0d)iid d id ddd1did2d d id ddd1d-id2d d idd d"d-d.d/d2d did d id!d d id ddd1d-id2dd#diid3 Zd4D] Zed5ee< d6D] Zed7ee< d8d9d:ed;eed<ed=gedgd>Zee d?<eeZe!gd@Z"dAZ#dBZ$dNdCZ%dOdDZ&dEZ' dPdFZ(dGZ)dHe*dIedJe dKe+dLdf dMZ,y)QzNTP: enable and configure ntpN)dedent)subp temp_utils templater type_utilsutil)Cloud)Config) MetaSchema get_meta_doc) PER_INSTANCEz /etc/ntp.conf) almalinuxalpinecentos cloudlinuxcosdebian eurolinuxfedorafreebsdmariner miraclelinuxopenbsd openeuler OpenCloudOS openmandrivaopensuseopensuse-microosopensuse-tumbleweed opensuse-leapphotonrhelrockysle_hpc sle-microsles TencentOSubuntu virtuozzochronydz/etc/chrony.confchronyzchrony.conf.{distro}) check_execonfpathpackages service_name template_nametemplatentpdntpzntp.conf.{distro}ntpdatez/etc/ntpd.confzntpd.conf.{distro}z/lib/systemd/systemd-timesyncdz-/etc/systemd/timesyncd.conf.d/cloud-init.confsystemd-timesyncdztimesyncd.conf)r,r4r5openntpdr6z/etc/chrony/chrony.conf)r.r0)r.r/r0)r,r4r0)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,r7z"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r-r.)r,r6r-)r,r4r6) rrrrrrrrrr"r#r'r))rr r!r)r%r&r'cc_ntpNTPzenable 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)idnametitle descriptiondistrosexamples frequencyactivate_by_schema_keysmeta)r-r.r/r0ct}tjt}||vrtj|||gd}|S)zConstruct 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)DISTRO_CLIENT_CONFIGcopyNTP_CLIENT_CONFIGr mergemanydict)distrodcfgcfgs 9/usr/lib/python3/dist-packages/cloudinit/config/cc_ntp.pydistro_ntp_client_configsrN<s? D ))% &C ~  #tF|!4dC JcDt|j}|r-|dk7r(tjd||j |iS|j dd}i}|dk(r|j D]Q}|j |}tj|j ds9tjd||}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 installedrzt|dk(r0t|}tjddj ||s t d |s |s t d ||||d } |r3t jd d } | d}tj||tj||| |rtj|yy)aRender 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)serverspoolsallowpeersztemplate_name-z.tmpl)prefixsuffix)content) lenrtrSrTrn ValueErrorrmkstempr write_filerrender_to_filedel_file) distro_namer0rwrxryrzrc template_fnr2paramstfiles rMwrite_ntp_config_templatersJ@     7|qSZ1_1E G  8 # F "( 4 9388G;LM W s5zQ%k2 8#((5/  ;<< x?@@ F ""*:7KAh   X6 [$7 k"rOcg}tjt|j}|r?K   ,)--o>FF  )) 11-@ 5#''89 s# #II "3"7"7"GHIImW[[B78IIk7;;w34IIk7;;w34IIk7;;w34 &**>: Ir*kk'2&kk'2&kk'2&  " ": ."&&z2  %%":.#K0  {{}   0F : @ ++FF; C ++Iv>  LL ' '+//?   ## '++N; -- @ >? @-- C AB C))  MMB sT2OO2,+P +Q(O/.O/2(PP Q3Q  QR%Q<<R)Nr3)N)NNNNNNNN)-__doc__rGloggingrbtextwrapr cloudinitrrrrrcloudinit.cloudr cloudinit.configr cloudinit.config.schemar r cloudinit.settingsr getLogger__name__rSr@NTP_CONFrlr>rHrFrJrB__annotations__ frozensetrrNr]r`rgrtrrrorrrOrMrs$  CC!#<+g!   B&J / G,  K!, $- 6C+) C)^2% ("  F  I  %1    1 ("0 5! %3  01# &0  , I >5  B I (" 9   I (" =   I !'OD=5  F  I   I (" =    1 kzxKDF#7 #C D'@F#7#? @   ' :    ( * 4j %wMGjGP t %9 /d"2>      N#b: z__6_%_t__rO