+
    i5                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHtHtHt ^ RIHtHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHt ]P@                  ! ]!4      t"RR.t#^t$^t%^
t& ! R R]PN                  PP                  4      t)R t*R t+ ! R R]PX                  4      t-]-]P\                  33.t/R t0R# )    N)urlparse)ConnectionError)HTTPConnection)PoolManager)dmiperformancesources
url_helperutil)
EventScope	EventType)NoDHCPLeaseError)EphemeralDHCPv4EphemeralIPv6Network)DataSourceHostname)ProcessExecutionErrorzhttp://169.254.42.42zhttp://[fd00:42::42]c                   @   a a ] tR t^&t oRtV 3R ltRR ltRtVtV ;t	# )SourceAddressAdapterz>
Adapter for requests to choose the local address to bind to.
c                <   < Wn         \        \        V `  ! R/ VB  R # )N )source_addresssuperr   __init__)selfr   kwargs	__class__s   &&,F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceScaleway.pyr   SourceAddressAdapter.__init__+   s    ,"D2<V<    c                    \         P                  \        P                  \        P                  ^3.,           p\        VVVV P                  VR7      V n        R# )   )	num_poolsmaxsizeblockr   socket_optionsN)r   default_socket_optionssocket
SOL_SOCKETSO_REUSEPORTr   r   poolmanager)r   connectionsr#   r$   r%   s   &&&& r   init_poolmanager%SourceAddressAdapter.init_poolmanager/   sR    '>> 3 3Q7B
 
 '!..)
r   )r*   r   )F)
__name__
__module____qualname____firstlineno____doc__r   r,   __static_attributes____classdictcell____classcell__r   __classdict__s   @@r   r   r   &   s     =

 

r   r   c           	          \         P                  ! V RV^ VR R7      p\        P                  ! VP                  4      #   \         P
                   d   pTP                  R8X  d    Rp?R# h Rp?ii ; i)a%  
Retrieve user data or vendor data.

Scaleway user/vendor data API returns HTTP/404 if user/vendor data is not
set.

This function calls `url_helper.readurl` but instead of considering
HTTP/404 as an error that requires a retry, it considers it as empty
user/vendor data.

Also, be aware the user data/vendor API requires the source port to be
below 1024 to ensure the client is root (since non-root users can't bind
ports below 1024). If requests raises ConnectionError (EADDRINUSE), the
caller should retry to call this function on an other port.
Nc                     V P                   R 8g  ;'       d4    \        V P                  \        P                  P
                  4      '       * # )  )code
isinstancecauserequests
exceptionsr   )excs   &r   <lambda>%query_data_api_once.<locals>.<lambda>W   s8    SXX_ & &syy(*=*=*M*MNN&r   )datatimeoutretriessessionexception_cbr:   )r
   readurlr   decode_binarycontentsUrlErrorr;   )api_addressrD   requests_sessionrespr@   s   &&&  r   query_data_api_oncerO   <   sk     !! $
 !!$--00 88s?	s   <? A1A,+A,,A1c                   \        ^\        V^4      4       F  p \        P                  RW4       \        P
                  ! 4       pRp \        V4      P                  pTpV^ ,          R8X  d   V^R p\        P                  ! VR\        P                  R7      ^ ,          ^ ,          p	V	\        P                  8X  d   RpTP                  R\        Yd3R7      4       \        YTR	7      p
\        P                  R
T 4       T
u # 	  Xh  \         d     LUi ; i  \         P"                   d;   p\        P%                  RY4       \&        P(                  ! ^4       Tp Rp?EKK  Rp?ii ; i)a  Get user or vendor data.

Handle the retrying logic in case the source port is used.

Scaleway metadata service requires the source port of the client to
be a privileged port (<1024).  This is done to ensure that only a
privileged user on the system can access the metadata service.
z*Trying to get %s data (bind on port %d)...z0.0.0.0[N)protoz0::zhttp://)r   )rD   rM   z%s-data downloadedz%Error while trying to get %s data: %s)rangemaxLOGdebugr>   Sessionr   netlocr'   getaddrinfoIPPROTO_TCPAF_INET6
ValueErrormountr   rO   r
   rK   warningtimesleep)api_typerL   rE   rD   portrM   	localhosturl_addressaddress
addr_protorC   r@   last_excs   &&&&         r   query_data_apiri   d   sT    aWa)"	II<h  (//1!I&{3::%q>S()!B/G#//T););
 0 %I ""$Y4EF '?OD II*H5K9 *L N)   "" 	KK?OJJqMH	s=   -D	A6D?ADDDDDE'-.E""E'c                   0  a a ] tR t^t oRt]P                  ]P                  ]P                  ]P                  0/tV 3R ltV3R lV 3R lltR tR t]V3R lR l4       tR	 t]R
 4       t]R 4       tR tR tRR lt]R 4       t]R 4       tRtVtV ;t# )DataSourceScalewayScalewayc                  < \         \        V `  WV4       \        P                  ! \        P
                  ! VR R./ 4      .4      V n        \        V P                  P                  R\        4      4      V n
        \        V P                  P                  R\        4      4      V n        \        V P                  P                  R\        4      4      V n        \        P                   V n        \$        V n        RV n        RV n        RV n        RV n        RV n        RV P                  P3                  4       9   d-   V ;P&                  V P                  R,          ,          un        R# R# )
datasourcerl   rE   rD   max_waitNTmetadata_urls)r   rk   r   r   mergemanydictget_cfg_by_pathds_cfgintgetDEF_MD_RETRIESrE   DEF_MD_TIMEOUTrD   DEF_MD_MAX_WAITro   r	   UNSET_network_configDS_BASE_URLSrp   metadata_urluserdata_urlvendordata_urlephemeral_fixed_addresshas_ipv4keys)r   sys_cfgdistropathsr   s   &&&&r   r   DataSourceScaleway.__init__   s    $0%H(($$W|Z.H"M
 4;;??9nEF4;;??9nEFDKKOOJHI&}})  "'+$dkk..00$++o">> 1r   c                $   < V ^8  d   QhRS[ RR/# )   ci_pkl_versionreturnN)rt   )formatr7   s   "r   __annotate__DataSourceScaleway.__annotate__   s     9 9 9 9r   c                   < \         SV `  V4       R RRRR\        R\        RRRR/pV F(  p\	        W4      '       d   K  \        WW#,          4       K*  	  R# )r   Nr   Tro   rp   r}   r~   )r   	_unpicklerx   r{   hasattrsetattr)r   r   attr_defaultsattrr   s   &&  r   r   DataSourceScaleway._unpickle   sY    .)%t\Dd
 "D4&&M$78 "r   c                   \         P                  ! 4       p\        P                  ! VV P                  V P
                  RR7      w  r4V'       d7   \        P                  RV4       V R2V n        V R2V n	        V R2V n
        R# \        P                  RV\        \         P                  ! 4       V,
          4      4       \        h)	z?
Define metadata_url based upon api-metadata URL availability.
F)urlsro   rD   connect_synchronouslyz%s is reachablez/conf?format=jsonz/user_data/cloud-initz/vendor_data/cloud-initNz3Unable to reach api-metadata at %s after %s seconds)r`   	monotonicr
   wait_for_urlro   rD   rV   rW   r|   r}   r~   rt   r   )r   r   
start_time	avail_url_s   &&   r   _set_metadata_url$DataSourceScaleway._set_metadata_url   s    
 ^^%
!..]]LL"'	
	 II'3#,+-> ?D#,+-B CD%.K/F"GDIIEDNN$z12
 "!r   c                   \         P                  ! V P                  V P                  V P                  R 7      p\
        P                  ! \        P                  ! VP                  4      4      V n
        \        RV P                  V P                  V P                  4      V n        \        RV P                  V P                  V P                  4      V n        R# ))rD   rE   z	user-datazvendor-dataN)r
   rH   r|   rD   rE   jsonloadsr   rI   rJ   metadatari   r}   userdata_rawr~   vendordata_raw)r   rN   s   & r   _crawl_metadata"DataSourceScaleway._crawl_metadata   s    !!t||T\\
 

4#5#5dmm#DE***DLL$,,
 -4..dll
r   c                    < V ^8  d   QhRS[ /# )r   r   )bool)r   r7   s   "r   r   r      s      t r   c                     \         P                  ! R4      p V R8X  d   R# \        P                  P	                  R4      '       d   R# \
        P                  ! 4       pRV9   d   R# R# )z
There are three ways to detect if you are on Scaleway:

* check DMI data: not yet implemented by Scaleway, but the check is
  made to be future-proof.
* the initrd created the file /var/run/scaleway.
* "scaleway" is in the kernel cmdline.
zsystem-manufacturerrl   Tz/var/run/scalewayscalewayF)r   read_dmi_dataospathexistsr   get_cmdline)vendor_namecmdlines     r   	ds_detectDataSourceScaleway.ds_detect   sS     ''(=>*$77>>-..""$ r   c           	     >   V P                   '       d    \        V P                  V P                  P                  4      ;_uu_ 4       p\        P
                  ! R 4      ;_uu_ 4        V P                  V P                  4       RRR4       V P                  4        VR,          V n	        RV P                  R&   RRR4       V P                   '       g    \%        V P                  V P                  P                  4      ;_uu_ 4        \        P
                  ! R4      ;_uu_ 4        V P                  V P                  4       RRR4       V P                  4        RV P                  R&   RRR4       R# R#   + '       g   i     L; i  + '       g   i     L; i  \        \        \        3 d7   p\        P                  ! \         \#        T4      4       RT n          Rp?EL Rp?ii ; i  + '       g   i     L; i  + '       g   i     R# ; i  \         d     R# i ; i)	z7Setting api-metadata URL depending on IPv4 availabilityNzfixed-addressipv4
net_in_useFz7Setting api-metadata URL depending on IPv6 availabilityipv6T)r   r   r   fallback_interfacer   Timedr   rp   r   r   r   r   r   r   r   logexcrV   strr   )r   r   es   &  r   	_get_dataDataSourceScaleway._get_data  s   
 ===& %KKKK22  $**9  ..t/A/AB	
 ((*373HD028DMM,/. }}})KKKK22  %**,  ..t/A/AB	
 ((*28DMM,/ E 	  !% &
 CQ( !&&" 	   # s   2F F%E1	5F6F 2H G9"G&	>'G9%H 1F<FF	F F G#-+GG#&G61G99H
	H 
H HHc                   V P                   f:   \        P                  R\        P                  4       \        P                  V n         V P                   \        P                  8w  d   V P                   # / p/ pV P
                  R,           EF  pVR,          V P                  8X  dC   RVR&   RRRRR	R
/pRVP                  4       9   d   VR;;,          V.,          uu&   KV  V.VR&   K^  RVP                  4       9   d+   VR;;,          VR,           RVR,           23,          uu&   MVR,           RVR,           23VR&   VR,          R8X  g   K  R	VR,          RR/pRVP                  4       9   d   VR;;,          V.,          uu&   EK  V.VR&   EK
  	  W!V P                  P                  &   R^RV/V n         V P                   # )zH
Configure networking according to data received from the
metadata API.
z5Found None as cached _network_config. Resetting to %s
public_ipsrf   Tdhcp4zon-linktoz169.254.42.42/32viaz
62.210.0.1routes	addresses/netmaskfamilyinet6gatewayz::/0version	ethernets)
rz   rV   r_   r	   ry   r   r   r   r   r   )r   netcfgip_cfgiproutes   &    r   network_config!DataSourceScaleway.network_config5  s    'KKG $+==D 7==0'''----B)} < <<"&w t,<
 v{{},8$/$(-wF8$&++-/;'i=/2i=/:, ' /1m_Abm_+M*OF;'h<7*"ByM4@E6;;=0x(UG3(,17x(5 .6 28t{{--. )1k6B###r   c                    R # Nr   r   s   &r   launch_indexDataSourceScaleway.launch_indexg  s    r   c                (    V P                   R ,          # )idr   r   s   &r   get_instance_id"DataSourceScaleway.get_instance_idk  s    }}T""r   c                8   V P                   R ,           Uu. uF  qR,          NK  	  ppRp\        V4      pV P                   P                  R. 4       F?  pVP                  V4      '       g   K  VP	                  WTR P                  RR4      4       KA  	  V# u upi )ssh_public_keyskeyzAUTHORIZED_KEY=tagsNr    )r   lenru   
startswithappendreplace)r   r   ssh_keysakeypreplentags   &     r   get_public_ssh_keys&DataSourceScaleway.get_public_ssh_keysn  s    *.--8I*JK*J3JJ*JK#7|==$$VR0C>>'**OOCJ..sC89 1
  Ls   Bc                <    \        V P                  R ,          R4      # )hostnameF)r   r   )r   fqdn
resolve_ipmetadata_onlys   &&&&r   get_hostnameDataSourceScaleway.get_hostnamez  s    !$--
";UCCr   c                (    V P                   R ,          # )zoner   r   s   &r   availability_zone$DataSourceScaleway.availability_zone}  s    }}V$$r   c                T    V P                   R ,          P                  R4      ^ ,          # )r   -)r   
rpartitionr   s   &r   regionDataSourceScaleway.region  s!    }}V$//4Q77r   )rz   rs   r   r   ro   r   r|   rp   rE   rD   r   r}   r   r~   )FFF)r.   r/   r0   r1   dsnamer   NETWORKr   BOOT_NEW_INSTANCEBOOTBOOT_LEGACYdefault_update_eventsr   r   r   r   staticmethodr   r   propertyr   r   r   r   r   r   r   r3   r4   r5   r6   s   @@r   rk   rk      s     F''NN!!
?,9 9"4
  *0d /$ /$b  #
D % % 8 8 8r   rk   c                 8    \         P                  ! V \        4      # r   )r	   list_from_dependsdatasources)dependss   &r   get_datasource_listr    s    $$Wk::r   )1r   loggingr   r'   r`   urllib.parser   r>   requests.exceptionsr   urllib3.connectionr   urllib3.poolmanagerr   	cloudinitr   r   r	   r
   r   cloudinit.eventr   r   cloudinit.net.dhcpr   cloudinit.net.ephemeralr   r   cloudinit.sourcesr   cloudinit.subpr   	getLoggerr.   rV   r{   rv   rx   rw   adaptersHTTPAdapterr   rO   ri   
DataSourcerk   DEP_FILESYSTEMr  r  r   r   r   <module>r     s      	   !  / . + A A 1 / I 0 0!&(>?
8,,88 
,%P1hk8++ k8^ '0023
;r   