+
    i                     $  a  R t 0 t R t^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt RRR	R
.R]RR./t] ^ k ]P                   ! ]4      t]! . R O4      tRtRtR!tR R ltR R ltR R ltR R ltR R ltR R ltR tR R ltR# )"	WireguardN)subputilCloud)Config)
MetaSchema)PER_INSTANCEidcc_wireguarddistrosubuntu	frequencyactivate_by_schema_keys	wireguardi  
c                $    V ^8  d   QhR\         /#    wg_intdict)formats   "?/usr/lib/python3/dist-packages/cloudinit/config/cc_wireguard.py__annotate__r      s     
 
4 
    c                   . p\         P                  \        V P                  4       4      4      pV'       d/   RP	                  \        V4      4      pVP                  RV 24       \        V P                  4       4       FK  w  rEVR8X  g   VR8X  g
   VR8X  g   K  \        V\        4      '       d   K4  VP                  RV RV 24       KM  	  V'       d(   \        R\         \        P	                  V4       24      hR	# )
a>  Validate user-provided wg:interfaces option values.

This function supplements flexible jsonschema validation with specific
value checks to aid in triage of invalid user-provided configuration.

@param wg_int: Dict of configuration value under 'wg:interfaces'.

@raises: ValueError describing invalid values provided.
z, z%Missing required wg:interfaces keys: nameconfig_pathcontentz$Expected a string for wg:interfaces:. Found z*Invalid wireguard interface configuration:N)REQUIRED_WG_INT_KEYS
differencesetkeysjoinsortedappenditems
isinstancestr
ValueErrorNL)r   errorsmissingr$   keyvalues   &     r   supplemental_schema_validationr1      s     F"--c&++-.@AGyy)=dVDEV\\^,
&=C=0C94DeS)):3%xwO - 8RWWV_<MN
 	
 r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   ;   s       r   c           
     H   \         P                  RV R,          4        \         P                  RV R,          4       \        P                  ! V R,          V R,          \        R7       R	#   \
         d.   p\        RT R,           R\         \        T4       24      ThR	p?ii ; i)
zWriting user-provided configuration into Wireguard
interface configuration file.

@param wg_int: Dict of configuration value under 'wg:interfaces'.

@raises: RuntimeError for issues writing of configuration file.
z"Configuring Wireguard interface %sr   z#Writing wireguard config to file %sr   r   )modez-Failure writing Wireguard configuration file :N)	LOGdebugr   
write_fileWG_CONFIG_FILE_MODE	ExceptionRuntimeErrorr,   r*   )r   es   & r   write_configr=   ;   s     II2F6NC			79NO=!6)#4;N	
  }%&atCF85
 	s   AA) )B!4(BB!c                0    V ^8  d   QhR\         R\        /# )r   r   cloud)r   r   )r   s   "r   r   r   P   s      d 5 r   c                    \         P                  RV R,          4       VP                  P                  RRV R,           24       \         P                  RV R,          4       VP                  P                  RRV R,           24       R#   \        P
                   d$   p\        R\         \        T4       24      ThRp?ii ; i)	zEnable and start Wireguard interface

@param wg_int: Dict of configuration value under 'wg:interfaces'.

@raises: RuntimeError for issues enabling WG interface.
zEnabling wg-quick@%s at bootr   enablez	wg-quick@z!Bringing up interface wg-quick@%srestartz0Failed enabling/starting Wireguard interface(s):N)	r6   r7   distromanage_servicer   ProcessExecutionErrorr;   r,   r*   )r   r?   r<   s   && r   	enable_wgrF   P   s    		0&.A##H	&.9I.JK		5vf~F##I6&>:J/KL%% >rd3q6(K
	s   BB
 
CB==Cc                $    V ^8  d   QhR\         /# r   wg_readinessprobeslist)r   s   "r   r   r   b   s     
 
$ 
r   c                    . p^ pV  F;  p\        V\        4      '       d   K  VP                  RV RV 24       V^,          pK=  	  V'       d(   \        R\         \        P                  V4       24      hR# )zBasic validation of user-provided probes

@param wg_readinessprobes: List of readinessprobe probe(s).

@raises: ValueError of wrong datatype provided for probes.
z(Expected a string for readinessprobe at r    z Invalid readinessProbe commands:N)r)   r*   r'   r+   r,   r%   )rI   r-   poscs   &   r   !readinessprobe_command_validationrO   b   sz     F
C!S!!MM:3%xsK 1HC   .rd2776?2CD
 	
 r   c                $    V ^8  d   QhR\         /# rH   rJ   )r   s   "r   r   r   x   s     
 
t 
r   c                ^   . pV  F<  p \         P                  R\        V4      4       \        P                  ! VRRR7       K>  	  V'       d(   \        R\         \        P                  V4       24      hR#   \        P                   d"   pTP                  T RT 24        Rp?K  Rp?ii ; i)zExecute provided readiness probe(s)

@param wg_readinessprobes: List of readinessprobe probe(s).

@raises: ProcessExecutionError for issues during execution of probes.
zRunning readinessprobe: '%s'Tcaptureshellz: Nz&Failed running readinessprobe command:)	r6   r7   r*   r   rE   r'   r;   r,   r%   )rI   r-   rN   r<   s   &   r   readinessproberU   x   s     F	'II4c!f=IIaT2   4RD8IJ
 	
  )) 	'MMQCr!+&&	's   8A66B,B''B,c                $    V ^8  d   QhR\         /# )r   r?   r   )r   s   "r   r   r      s      E r   c                   R.p\         P                  ! R4      '       d   R# \        P                  ! 4       \        8  d   VP                  R4        V P                  P                  4         T P                  P                  T4       R#   \         d    \        P                  ! \        R4       h i ; i  \         d    \        P                  ! \        R4       h i ; i)z}Install wireguard packages and tools

@param cloud: Cloud object

@raises: Exception for issues during package
installation.
zwireguard-toolswgNr   zPackage update failedz!Failed to install wireguard-tools)r   whichr   kernel_versionMIN_KERNEL_VERSIONr'   rC   update_package_sourcesr:   logexcr6   install_packages)r?   packagess   & r    maybe_install_wireguard_packagesr`      s     ""Hzz$ 11$++-%%h/	  C01
  C<=s   B
 -B5 
(B25(Cc            	         \         P                   ! RRRR7      p \        P                  ! RV P                  P	                  4       4      '       g1   \
        P                  R4       \         P                   ! RRRR7       R# R#   \         P                   d4   p\        P                  ! \
        R\         \        T4       24       h Rp?ii ; i)	zQLoad wireguard kernel module

@raises: ProcessExecutionError for issues modprobe
lsmodTrR   r   zLoading wireguard kernel modulezmodprobe wireguardz Could not load wireguard module:N)r   researchstdoutstripr6   r7   rE   r   r]   r,   r*   )outr<   s     r   load_wireguard_kernel_modulerh      s    
iiT:yycjj&6&6&899II78II*DE : %% C;B4AxHIs   AB .B C
.CC
c          
      L    V ^8  d   QhR\         R\        R\        R\        RR/# )r   r   cfgr?   argsreturnN)r*   r   r   rK   )r   s   "r   r   r      s6     $A $A $A6 $A% $At $A $Ar   c                    R pRV9   d    \         P                  R4       VR,          pM\         P                  RV 4       R # \        V4       \        4        VR,           F$  p\	        V4       \        V4       \        WR4       K&  	  RV9   d-   VR,          e"   VR,          p\        V4       \        V4       R # \         P                  R4       R # )Nr   z!Found Wireguard section in configz<Skipping module named %s, no 'wireguard' configuration found
interfacesrU   z+Skipping readinessprobe - no checks defined)	r6   r7   r`   rh   r1   r=   rF   rO   rU   )r   rj   r?   rk   
wg_sectionr   rI   s   &&&&   r   handlerp      s    Jc		56%
		J	
 	 %U+ "\**&v. 	V 	&  + 	J&'(4'(89)*<=)*		?@r   c                @    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   # )r   meta)__conditional_annotations__r   )r   s   "r   r   r      s     j  r   )r   r   r   )      )!rs   __doc__loggingrc   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr	   rr   	getLogger__name__r6   	frozensetr!   r9   r,   r[   r1   r=   rF   rO   rU   r`   rh   rp   r   )rs   s   @r   <module>r      s      	   ! # . + 	.z}	  ! !CD  	 
:*$
,
*<$Ar   