+
    iL                       a  RT t+0 t R t^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]P,                  ! ]4      t]tRt^t. R	NR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NtR(R)R*R+R,R-R(.R.R(R/R0R1R/R2R)R3R+]R-R4.R.R2R/R5R1R/R6R)R6R+]R-R6.R.R6R/R5R1R/R7R)R3R+R8R-. R.R3R/R9R1R/R:R)R;R+R<R-. R.R:R/R=R1R//t/ R
R(R+R>R.R*/R2R+RR-. R.R3//bRR:R)R?R+R@//bRR(R.R*/R:R)R?R+R@//bRR2R.R3/R(R.R*//bRR(R.R*R+R>//bRR(R+R>//bRR2R+RR.R3R/R5/R(R+RAR-R(.R.R*R/R0/R7R)RBR+RCR-R7.R.R7R/RD//bRR(R.R*/R:R)R?R+R@//bRR7/ /bRR(R.R*/R2R+RR.R3/R:R)R;//bRR(R.R*/R2R+RR.R3/R:R)R?//bRR(R.R*/R2R.R3R+R/R:R)R?R+R@//bRR:R)R?//bR R2R.R3/R(R.R*//bR$R(R.R*/R2R+RR.R3/R:R)R?//bR&R(R+R>//bt] ^ k RU F  t]R,          ]]&   K  	  RV F  t]R ,          ]]&   K  	  RW F  t]R$,          ]]&   K  	  RERFRG]RH]RIR2./t ] ^k ]!! . RXO4      t"RJ t#RK RL lt$RYRM lt%RZRN lt&RO t'R[RP lt(RQ t)RR RS lt*R# )\zNTP: enable and configure ntpN)DictMapping)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photonzraspberry-pi-osrhelrockysle_hpc	sle-microsles	TencentOSubuntu	virtuozzochrony	check_exechronydconfpathz/etc/chrony.confpackagesservice_nametemplate_namezchrony.conf.{distro}templatentpntpdntpseczntp.conf.{distro}ntpdateopenntpdz/etc/ntpd.confzntpd.conf.{distro}zsystemd-timesyncdz/lib/systemd/systemd-timesyncdz-/etc/systemd/timesyncd.conf.d/cloud-init.confztimesyncd.confz/etc/chrony/chrony.confz"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.confz/usr/local/etc/chrony.confz/usr/local/sbin/ntpdz/usr/local/etc/ntp.confzntpd.conf.openbsdidcc_ntpdistros	frequencyactivate_by_schema_keysc                    \         p\        P                  ! \        4      pW9   d!   \        P                  ! W!V ,          .RR7      pV# )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.
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_configsrH     s;      D
))%
&C~  #F|!4dCJ    c                $    V ^8  d   QhR\         /# )   return)r   )formats   "rG   __annotate__rN   !  s     / /W /rI   c                   \        VP                  4      pV '       d0   V R8w  d)   \        P                  RV 4       VP	                  V / 4      # VP                  RR4      p/ pVR8X  d   VP                   FY  pVP	                  V4      p\        P                  ! VP	                  R4      4      '       g   KA  \        P                  RV4       Tp M	  V'       g<   VP                  ^ ,          p\        P                  RV4       VP	                  V/ 4      pV# \        P                  RV4       VP	                  V/ 4      pV# )zDetermine 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 installedz<Selected distro preferred NTP client "%s", not yet installedz1Selected NTP client "%s" via distro system config)	rH   nameLOGdebugget
get_optionpreferred_ntp_clientsr   which)rQ   rD   
distro_cfgdistro_ntp_client	clientcfgclientrF   s   &&     rG   select_ntp_clientr]   !  s#    +6;;7J jF*		BJ	
 ~~j"-- )),?IF"22F..(Czz#''+.//		A6  	 3 11!4FIIN #vr2I  			?	
 NN#4b9	rI   c                R    \         P                  ! V4      '       d   R# V ! V4       R# )aP  Install 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.
N)r   rX   )install_funcr/   r,   s   &&&rG   install_ntp_clientr`   S  s     zz)rI   c                    \         P                  P                  V 4      '       d    \        P                  ! W R,           4       R# R# )zRename 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   &rG   rename_ntp_confrg   b  s-     
ww~~hH01  rI   c           	        . pT pV R8X  d   RpMV R8X  g   V R8X  d   Rp\        \        4       FV  pTP                  RP                  \	        V4      .V.,           R.,            Uu. uF  qD'       g   K  VNK  	  up4      4       KX  	  V# u upi )zGenerate 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'   r   r   r    .zpool.ntp.org)rangeNR_POOL_SERVERSappendjoinstr)rD   namespool_distroxns   &    rG   generate_server_namesrt   l  s     EK !	8	v4 ?#HH VH}47GGMGq1GM	
 $ L	 Ns   %	B
3B
c	                   V'       g   . pV'       g   . pV'       g   . pV'       g   . pV'       g   V'       g
   V R8X  d   R# V'       g@   V R8X  d9   VR8X  d2   \        V 4      p\        P                  RRP                  V4      4       M@V'       g9   V'       g1   \        V 4      p\        P                  RRP                  V4      4       V'       g   \	        R4      hV'       g   V'       g   \	        R	4      hR
VRVRVRV/p	V'       d9   \
        P                  ! RRR7      p
V
^,          p\        P                  ! WxR7       \        P                  ! WvV	4       V'       d   \        P                  ! V4       R# R# )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.
r   Nr   r4   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peersztemplate_name-z.tmpl)prefixsuffix)content)rt   rS   rT   rn   
ValueErrorr   mkstempr   
write_filer   render_to_filedel_file)distro_namer0   rw   rx   ry   rz   rc   template_fnr2   paramstfiles   &&&&&&&&&  rG   write_ntp_config_templater     s!   @ 5[E%9{h.<63I (4		9388G;LM%k2		8#((5/	
 ;<<x?@@ 	7	F ""*:7KAh6[7k" rI   c                L   . p\         P                  \        V P                  4       4      4      pV'       d=   RP	                  \        V4      4      pVP                  RP                  VR7      4       MB\        V P                  R4      V P                  R4      .4      '       g   VP                  R4       \        V P                  4       4       EF  w  rERV,           pVR8X  dG   \        V\        V\        4      .4      '       g$   VP                  R	P                  WeR
7      4       KZ  K\  VR8X  d<   \        V\        4      '       g$   VP                  RP                  WeR
7      4       K  K  VR9   dB   Vf   K  \        V\        4      '       g$   VP                  RP                  WeR
7      4       K  K  \        V\        4      '       d   K  VP                  RP                  WeR
7      4       EK"  	  V'       d+   \        RP                  RP	                  V4      R7      4      hR# )a;  Validate 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})keysr2   r1   zJEither ntp:config:template or ntp:config:template_name values are requiredzntp: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)r2   r1   )REQUIRED_NTP_CONFIG_KEYS
differencesetr   rn   sortedrm   rM   anyrU   itemsall
isinstancero   listr~   )
ntp_configr   missingr   keyr   r   s   &      rG   supplemental_schema_validationr     s    F&11#joo6G2HIGyy)6==4=H	
 	
	#Z^^O%DE  		
 Z--/0
#%*z%5677''-vgv'K 8
 JeT**''-vgv'K +
 11}eS))''-vgv'K *
 E3''MMGNN# O / 1: 3::yy( ; 
 	
 rI   c          
      L    V ^8  d   QhR\         R\        R\        R\        RR/# )rK   rR   rF   cloudargsrL   N)ro   r
   r	   r   )rM   s   "rG   rN   rN     s6     _ _ _6 _% _t _ _rI   c                ^	   RV9  d   \         P                  RV 4       R# VR,          pVf   / p\        V\        4      '       g0   \	        RP                  \        P                  ! V4      R7      4      hVP                  RR4      p\        P                  ! V4      '       d   \         P                  RV 4       R# \        VP                  R	4      VP                  4      p\        P                  ! WdP                  R
/ 4      .RR7      p\        V4       \        VP                  R4      R7       RpVP                  R4      '       gj   VR,          P!                  RVP                  P"                  4      pVP%                  V4      pV'       g$   RVP                  R4      ,          p	\	        V	4      h\         P                  RVP                  R4      4       \         P                  RVP                  R. 4      4       \         P                  RVP                  R. 4      4       \         P                  RVP                  R. 4      4       \         P                  RVP                  R. 4      4       \'        VP                  P"                  VP                  R4      VP                  R. 4      VP                  R. 4      VP                  R. 4      VP                  R. 4      VP                  R4      VVP                  R4      R7	       \)        VP                  P*                  VR,          VR,          R7       \        P,                  ! 4       '       du   VP                  R4      R 8w  d;    VP                  P/                  R!R 4        VP                  P/                  R#R 4        VP                  P/                  R%VR,          4        VP                  P/                  R'VR,          4       R#   \0        P2                   d    \         P5                  R"4        Li ; i  \0        P2                   d    \         P5                  R$4        Li ; i  \0        P2                   d   p
\         P7                  R&T
4       h Rp
?
ii ; i  \0        P2                   d   p
\         P7                  R(T
4       h Rp
?
ii ; i))zEnable and configure ntp.r3   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 cfgrQ   configr>   r.   rf   r2   r1   z{distro}z#No template found, not rendering %szservice_name: %sr0   zservers: %srw   z	pools: %srx   z	allow: %sry   z	peers: %srz   )r0   rw   rx   ry   rz   rc   r   r2   r/   r,   )r/   r,   r4   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)rS   rT   r   dictRuntimeErrorrM   r   obj_namerU   r   is_falser]   rD   rC   r   rg   replacerR   get_template_filenamer   r`   install_packagesis_BSDmanage_servicer   ProcessExecutionErrorwarning	exception)rR   rF   r   r   ntp_cfgr   ntp_client_configr   r1   msges   &&&&       rG   handler     s   C		F	
 	%jG g&&$$*F1D1DW1MF$N
 	
 kk)T*G}}W		=tD *L!5<< **	KK"56 ##45.22:>?K  ,,)/:BB))
 11-@5#''89  s##II "3"7"7"GHIImW[[B78IIk7;;w34IIk7;;w34IIk7;;w34&**>:Ir*kk'2&kk'2&kk'2&"":."&&z2
 %%":.#K0
 {{}}  0F:@++FF;C++Iv>	LL''+N;##'7	
 -- @>?@ -- CABC )) 	MM<a@	 %% >BsT   $O' P #Q #Q; '*PP*QQQ8Q33Q8;R,R''R,c                    V ^8  d   Qh/ ^ \         9   d   \        \        \        3,          ;R&   ^\         9   d
   \        ;R&   # )rK   r@   meta)__conditional_annotations__r   ro   r   )rM   s   "rG   rN   rN      sC     # #@N Nd39o NA $~ j  $rI   )r   r    r!   )r   r   r$   )r%   r&   )r,   r.   r/   r0   )Nr4   )N)NNNNNNNN),r   __doc__rA   loggingrb   typingr   r   	cloudinitr   r   r   r   r   cloudinit.cloudr	   cloudinit.configr
   cloudinit.config.schemar   cloudinit.settingsr   	getLogger__name__rS   r;   NTP_CONFrl   r:   rB   r@   rD   r   	frozensetr   rH   r]   r`   rg   rt   r   r   r   rN   )r   s   @rG   <module>r      sg   $   	   C C ! # . +!	      	 
     
                   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? F Y&XJ/D 
VHXJ,D YHYK	,D V$B-D 5CB+)DC) XN)1I
 	F

N) =5
N)$ I
 	=5
	%N)6 F
 	I
	7N)F 
I1
GN)R 1
SN)\ F0

 	4
I3	
 	/1J0
]N)D I
 	=5
	EN)V BWN)\ I
 	F
 	9
]N)t I
 	F
 	=
uN)L I
 	
OD=5
	MN)` =
aN)j F
 	I
	kN)z I
 	F
 	=
{N)R 1
SN)  N` KF#7
#C  K 3F#7#?  3 'F#7#?  ' 	(ww	  %9 
/d2:J#Z:
z_rI   