x[h (UdZddlZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z dd ge d gd Ze ed <ej eZegd ZdZdZdZdefdZdefdZdedefdZdefdZdefdZdefdZdZ de!de dededdf dZ"y) WireguardN)subputil)Cloud)Config) MetaSchema) PER_INSTANCE cc_wireguardubuntu wireguard)iddistros frequencyactivate_by_schema_keysmeta)name config_pathcontenti )wg_intcg}tjt|j}|r.dj t |}|j d|t |jD]=\}}|dk(s |dk(s|dk(st|tr'|j d|d|?|r'tdttj |y ) aRValidate 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: rrrz$Expected a string for wg:interfaces:. Found z*Invalid wireguard interface configuration:N) REQUIRED_WG_INT_KEYS differencesetkeysjoinsortedappenditems isinstancestr ValueErrorNL)rerrorsmissingrkeyvalues ?/usr/lib/python3/dist-packages/cloudinit/config/cc_wireguard.pysupplemental_schema_validationr,sF"--c&++-.@AGyy) =dVDEV\\^, U &=C=0C94DeS) :3%xwO8RWWV_:J/KL  % %>rd3q6( K  sA6A99B/ B**B/wg_readinessprobescg}d}|D]/}t|tr|jd|d||dz }1|r'tdttj |y)zBasic validation of user-provided probes @param wg_readinessprobes: List of readinessprobe probe(s). @raises: ValueError of wrong datatype provided for probes. rz(Expected a string for readinessprobe at rz Invalid readinessProbe commands:N)r#r$r!r%r&r)rAr'poscs r+!readinessprobe_command_validationrFbs|F C !S! MM:3%xsK  1HC .rd2776?2C D  r-cDg}|D]:} tjdt|tj|dd<|r't dttj|y#tj$r }|j |d|Yd}~d}~wwxYw)zExecute provided readiness probe(s) @param wg_readinessprobes: List of readinessprobe probe(s). @raises: ProcessExecutionError for issues during execution of probes. zRunning readinessprobe: '%s'Tcaptureshellz: Nz&Failed running readinessprobe command:) r1r2r$rr?r!r6r&r)rAr'rEr7s r+readinessproberKxsF ' ' II4c!f = IIaT 2'4RD8I J  )) ' MMQCr!+ & & 's7A,,B?BBcdg}tjdrytjtkr|j d |j j |j j|y#t$rtjtdwxYw#t$rtjtdwxYw)zInstall wireguard packages and tools @param cloud: Cloud object @raises: Exception for issues during package installation. zwireguard-toolswgNr zPackage update failedz!Failed to install wireguard-tools) rwhichrkernel_versionMIN_KERNEL_VERSIONr!r=update_package_sourcesr5logexcr1install_packages)r9packagess r+ maybe_install_wireguard_packagesrUs""H zz$ 11 $ ++- %%h/  C01   C<= sA>"B&>%B#&%C c ~ tjddd}tjd|jj s.t j dtjdddyy#tj$r2}tjt dtt|d}~wwxYw) zYLoad wireguard kernel module @raises: ProcessExecutionError for issues modprobe lsmodTrHr zLoading wireguard kernel modulezmodprobe wireguardz Could not load wireguard module:N) rresearchstdoutstripr1r2r?rrRr&r$)outr7s r+load_wireguard_kernel_moduler]s iiT:yycjj&6&6&89 II7 8 II*D E:  % % C;B4AxHI sA3A77B< -B77B<rcfgargsreturncjd}d|vrtjd|d}ntjd|yt|t|dD]$}t |t |t ||&d|vr!|d|d}t|t|ytjdy)Nr z!Found Wireguard section in configzrss !#.+ z +} jg! !CD  4 :*d5$ $ , t *E< $A$A6$A%$At$A$Ar-