
    x[hK                     F   % S r SSKrSSKrSSKrSSKJrJr  SSKJrJ	r	J
r
JrJr  SSKJr  SSKJr  SSKJr  SSKJr  \R*                  " \5      r\rS	rS
r/ SQrSSS/SSSS.S\S/SSSS.S\S/SSSS.SS/ SSSS.SS/ SSSS.S.rSSS.S	/ SS.S.SS S!S".0S#S0S S!S".S$.S#S0S#S0S%.SSSS&.0SS'S00S	SSS(.S)S/SSS*.S+S,S-/S-S.S/.S0.S#S0S S!S".S$.S-0 0S#S0S	SS.S1S0S2.S#S0S	SS.S1S 0S2.S#S0SS	S&.S S!S".S2.S#S0S#S0S%.S#S0S	SS.S1S 0S2.SS'S00S3.r\\\4   \S4'   S5 H  r \S6   \\ '   M     S7 H  r \S8   \\ '   M     S9 H  r \S:   \\ '   M     S;\\S/S<.r!\\S='   \"" / S>Q5      r#S? r$S@\4SA jr%SLSB jr&SMSC jr'SD r(        SNSE jr)SF r*SG\SH\SI\SJ\+S@S4
SK jr,g)OzNTP: enable and configure ntp    N)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photonrhelrockysle_hpc	sle-microsles	TencentOSubuntu	virtuozzochronydz/etc/chrony.confchronyzchrony.conf.{distro})	check_execonfpathpackagesservice_nametemplate_nametemplatentpdntpzntp.conf.{distro}ntpdatez/etc/ntpd.confzntpd.conf.{distro}z/lib/systemd/systemd-timesyncdz-/etc/systemd/timesyncd.conf.d/cloud-init.confsystemd-timesyncdztimesyncd.conf)r.   r6   r7   openntpdr8   z/etc/chrony/chrony.conf)r0   r2   )r0   r1   r2   )r.   r6   z"/usr/lib/systemd/systemd-timesyncdz/etc/systemd/timesyncd.conf)r/   r0   r2   )r.   r8   )r6   r.   )r2   r0   r0   )r0   r2   r3   z/usr/local/etc/chrony.conf)r0   r1   r2   r3   z/usr/local/sbin/ntpdz/usr/local/etc/ntp.confr9   zntpd.conf.openbsd)r/   r0   r1   r2   r3   )r6   r.   r9   r/   )r.   r6   r8   )r   r   r   r   r   r   r   r   r   r   r    r$   r%   r)   r+   DISTRO_CLIENT_CONFIG)r!   r"   r#   r    )r   r   r&   r%   )r'   r(   r)   cc_ntp)iddistros	frequencyactivate_by_schema_keysmeta)r/   r0   r1   r2   c                     [         n[        R                  " [        5      nX;   a  [        R                  " X!U    /SS9nU$ )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)r:   copyNTP_CLIENT_CONFIGr	   mergemanydict)distrodcfgcfgs      9/usr/lib/python3/dist-packages/cloudinit/config/cc_ntp.pydistro_ntp_client_configsrK     s;      D
))%
&C~  #F|!4dCJ    returnc                 n   [        UR                  5      nU (       a.  U S:w  a(  [        R                  SU 5        UR	                  U 0 5      $ UR                  SS5      n0 nUS:X  a  UR                   HX  nUR	                  U5      n[        R                  " UR	                  S5      5      (       d  M@  [        R                  SU5        Un  O   U(       d7  UR                  S   n[        R                  SU5        UR	                  U0 5      nU$ [        R                  SU5        UR	                  U0 5      nU$ )	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 installedr   z<Selected distro preferred NTP client "%s", not yet installedz1Selected NTP client "%s" via distro system config)	rK   nameLOGdebugget
get_optionpreferred_ntp_clientsr   which)rP   rG   
distro_cfgdistro_ntp_client	clientcfgclientrI   s          rJ   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	rL   c                 X    [         R                  " U5      (       a  gUc  S/nU " U5        g)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.
Nr6   )r   rW   )install_funcr1   r/   s      rJ   install_ntp_clientr_   M  s+     zz)7rL   c                     [         R                  R                  U 5      (       a  [        R                  " X S-   5        gg)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r0   s    rJ   rename_ntp_confrf   ^  s-     
ww~~hH01  rL   c           	         / nU nU S:X  a  SnOU S:X  d  U S:X  a  Sn[        [        5       HN  nUR                  SR                  [	        U5      /U/-   S/-    Vs/ s H  oD(       d  M  UPM     sn5      5        MP     U$ s  snf )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)rG   namespool_distroxns        rJ   generate_server_namesrs   h  s     EK !	8	v4 ?#HH VH}47GGMGq1GM	
 $ L	 Ns   
A?(A?c	                    U(       d  / nU(       d  / nU(       d  / nU(       d  / nU(       d  U(       d  U S:X  a  gU(       d=  U S:X  a7  US:X  a1  [        U 5      n[        R                  SSR                  U5      5        O>U(       d7  U(       d0  [        U 5      n[        R                  SSR                  U5      5        U(       d  [	        S5      eU(       d  U(       d  [	        S	5      eUUUUS
.n	U(       a.  [
        R                  " SSS9n
U
S   n[        R                  " XxS9  [        R                  " XvU	5        U(       a  [        R                  " U5        gg)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   r5   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)rs   rR   rS   rm   
ValueErrorr   mkstempr	   
write_filer   render_to_filedel_file)distro_namer2   rv   rw   rx   ry   rb   template_fnr4   paramstfiles              rJ   write_ntp_config_templater     s   @ 5[E%9{h.<63I (4		9388G;LM%k2		8#((5/	
 ;<<x?@@ 	F ""*:7KAh6[7k" rL   c                    / n[         R                  [        U R                  5       5      5      nU(       a9  SR	                  [        U5      5      nUR                  SR                  US95        OA[        U R                  S5      U R                  S5      /5      (       d  UR                  S5        [        U R                  5       5       GH  u  pESU-   nUS:X  aB  [        U[        U[        5      /5      (       d   UR                  S	R                  XeS
95        MQ  MS  US:X  a7  [        U[        5      (       d   UR                  SR                  XeS
95        M  M  US;   a<  Uc  M  [        U[        5      (       d   UR                  SR                  XeS
95        M  M  [        U[        5      (       a  M  UR                  SR                  XeS
95        GM
     U(       a'  [        SR                  SR	                  U5      S95      eg)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})keysr4   r3   zJEither ntp:config:template or ntp:config:template_name values are requiredzntp:config:r0   z6Expected a config file path {keypath}. Found ({value}))keypathvaluer1   zHExpected a list of required package names for {keypath}. Found ({value}))r4   r3   Nz5Expected a string type for {keypath}. Found ({value})z$Invalid ntp configuration:\n{errors}
)errors)REQUIRED_NTP_CONFIG_KEYS
differencesetr   rm   sortedrl   formatanyrT   itemsall
isinstancern   listr~   )
ntp_configr   missingr   keyr   r   s          rJ   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( ; 
 	
 rL   rQ   rI   cloudargsc                    SU;  a  [         R                  SU 5        gUS   nUc  0 n[        U[        5      (       d,  [	        SR                  [        R                  " U5      S95      eUR                  SS5      n[        R                  " U5      (       a  [         R                  SU 5        g[        UR                  S	5      UR                  5      n[        R                  " XdR                  S
0 5      /SS9n[        U5        [        UR                  S5      S9  SnUR                  S5      (       d`  US   R!                  SUR                  R"                  5      nUR%                  U5      nU(       d  SUR                  S5      -  n	[	        U	5      e[         R                  SUR                  S5      5        [         R                  SUR                  S/ 5      5        [         R                  SUR                  S/ 5      5        [         R                  SUR                  S/ 5      5        [         R                  SUR                  S/ 5      5        ['        UR                  R"                  UR                  S5      UR                  S/ 5      UR                  S/ 5      UR                  S/ 5      UR                  S/ 5      UR                  S5      UUR                  S5      S9	  [)        UR                  R*                  US   US   S9  [        R,                  " 5       (       ao  UR                  S5      S :w  a:   UR                  R/                  S!S 5         UR                  R/                  S#S 5         UR                  R/                  S%US   5         UR                  R/                  S'US   5        g! [0        R2                   a    [         R5                  S"5         Nf = f! [0        R2                   a    [         R5                  S$5         Nf = f! [0        R2                   a  n
[         R7                  S&U
5        e Sn
A
ff = f! [0        R2                   a  n
[         R7                  S(U
5        e Sn
A
ff = f))zEnable and configure ntp.r6   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 cfgrP   configrB   r0   re   r4   r3   z{distro}z#No template found, not rendering %szservice_name: %sr2   zservers: %srv   z	pools: %srw   z	allow: %srx   z	peers: %sry   )r2   rv   rw   rx   ry   rb   r   r4   r1   r/   )r1   r/   r5   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)rR   rS   r   dictRuntimeErrorr   r   obj_namerT   r	   is_falser\   rG   rF   r   rf   replacerQ   get_template_filenamer   r_   install_packagesis_BSDmanage_servicer   ProcessExecutionErrorwarning	exception)rQ   rI   r   r   ntp_cfgr   ntp_client_configr   r3   msges              rJ   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   7N1 O  1P Q 1)OO )PPP?#P::P?Q2Q--Q2)Nr5   )N)NNNNNNNN)-__doc__rD   loggingra   typingr   r   	cloudinitr   r   r   r   r	   cloudinit.cloudr
   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr   	getLogger__name__rR   r>   NTP_CONFrk   r=   rE   r:   rn   __annotations__rG   r@   	frozensetr   rK   r\   r_   rf   rs   r   r   r   r    rL   rJ   <module>r      s   $   	   C C ! # . +!	F &J / G, K!, $- 6C+)C) ^ 2%

 ("

 	=5
 I
 >5
	 F
 I
	 	%1
 	1
 ("0
 5!
%3	
 01#&0
, I
 >5
	 	B
 I
 ("

 9
 I
 ("

 =
 I
 !'OD=5
	 F
 I
	 I
 ("

 =
 	1
II) d39o IV KF#7
#C  K 3F#7#?  3 'F#7#?  '  %w	j  %9 
/W /d"2> 


	J#Z:
z_ _6 _% _t _ _rL   