+
    i2                        ^ RI t ^ RI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 ^ RIHtHtHt ^ RIHtHt ^ RIHt ^ R	IHtHtHt ]P8                  ! ]4      tR
RRRR/RRRRRRR/RRRRRRRRRRRR./t ! R R]	4      t  ! R  R!]PB                  4      t" ! R" R#]"4      t#]#]PH                  33]"]PH                  ]PJ                  33.t&R$ R% lt'R# )&    N)	b64decode)suppress)Enum)AnyListTupleUnion)sources
url_helperutil)find_fallback_nicget_interfaces_by_mac)EphemeralIPNetwork)get_dmi_configget_local_instance_idis_on_akamai	base_urlsipv4zhttp://169.254.169.254ipv6zhttp://[fd00:a9fe:a9fe::1]pathstokenz	/v1/tokenmetadataz/v1/instanceuserdataz/v1/user-dataallow_local_stageTallow_init_stage
allow_dhcp
allow_ipv4
allow_ipv6preferred_mac_prefixeszf2:3c                   &    ] tR t^-tRt^ t^t^tRtR# )MetadataAvailabilityResultz^
Used to indicate how this instance should behave based on the availability
of metadata to it
 N)	__name__
__module____qualname____firstlineno____doc__NOT_AVAILABLE	AVAILABLEDEFER__static_attributes__r"       D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAkamai.pyr!   r!   -   s    
 MIEr,   r!   c                      a  ] tR t^8t o RtRtR tRV 3R lR lltV 3R lR ltV 3R lR	 lt	V 3R
 lR lt
V 3R lR ltRV 3R lR lltV 3R lR ltV 3R lR ltRtV tR# )DataSourceAkamaiAkamaiFc                   \         P                  R 4       \        P                  P	                  WW#4       \        4       V n        \        P                  ! \        4       \        P                  ! VRR./ 4      \        .4      V n        R# )zSetting up Akamai DataSource
datasourcer0   N)LOGdebugr
   
DataSource__init__dictr   r   mergemanydictr   get_cfg_by_pathBUILTIN_DS_CONFIGds_cfg)selfsys_cfgdistror   s   &&&&r-   r6   DataSourceAkamai.__init__<   sn    		01##D6A (( $$!8,
 "

r,   c                ,   < V ^8  d   QhRS[ RS[RS[ /# )   	path_nameuse_v6return)strbool)format__classdict__s   "r-   __annotate__DataSourceAkamai.__annotate__N   s"     - -C - -# -r,   c                8   WP                   R,          9  d   \        RP                  V4      4      hRpV'       g   V P                   R,          '       g   RpV P                   R,          V,          pV P                   R,          V,          pRP                  WE4      # )z
Looks up the path for a given name and returns a full url for it.  If
use_v6 is passed in, the IPv6 base url is used; otherwise the IPv4 url
is used unless IPv4 is not allowed in ds_cfg
r   zUnknown path name {}r   r   r   r   z{}{})r;   
ValueErrorrG   )r<   rB   rC   version_keybase_urlpaths   &&&   r-   
_build_urlDataSourceAkamai._build_urlN   sz     KK003::9EFF\22 K;;{+K8{{7#I.}}X,,r,   c                    < V ^8  d   QhRS[ /# rA   rD   r!   )rG   rH   s   "r-   rI   rJ   `   s     5 5$> 5r,   c                x   V P                   R,          '       g   V P                   R,          '       d3   V P                   R,          '       g?   V P                   R,          '       g&   \        P                  R4       \        P                  # V P
                  '       d   V P                  4       # V P                  4       # )z
Returns whether metadata should be retrieved at this stage, at the next
stage, or never, in the form of a MetadataAvailabilityResult.
r   r   r   r   z*Configuration prohibits fetching metadata.)r;   r3   infor!   r(   local_stage_should_fetch_data_local_should_fetch_data_networkr<   s   &r-   _should_fetch_data#DataSourceAkamai._should_fetch_data`   s     L))$++l2K2K/00KK 233 HHAB-;;;00222244r,   c                    < V ^8  d   QhRS[ /# rS   rT   )rG   rH   s   "r-   rI   rJ   t   s     4 4*D 4r,   c                L   V P                   R,          '       g&   \        P                  R4       \        P                  # V P                   R,          '       g?   V P                   R,          '       g&   \        P                  R4       \        P                  # \        P
                  # )zo
Returns whether metadata should be retrieved during the local stage, or
if it should wait for the init stage.
r   z)Configuration prohibits local stage setupr   r   z9Configuration does not allow for ephemeral network setup.r;   r3   rV   r!   r*   r)   rZ   s   &r-   rX   )DataSourceAkamai._should_fetch_data_localt   su    
 {{.//HH@A-333{{<((\1J1J HHK .333)333r,   c                    < V ^8  d   QhRS[ /# rS   rT   )rG   rH   s   "r-   rI   rJ      s     	4 	4,F 	4r,   c                    V P                   R,          '       g&   \        P                  R4       \        P                  # \        P
                  # )zC
Returns whether metadata should be fetched during the init stage.
r   z1Configuration does not allow for init stage setupr_   rZ   s   &r-   rY   +DataSourceAkamai._should_fetch_data_network   s9     {{-..HHHI-333)333r,   c                \   < V ^8  d   QhRS[ S[S[S[S[3,          S[3,          ,          /# rS   )r   r   r	   r   r   rF   )rG   rH   s   "r-   rI   rJ      s2     M( M(	eE#112D89	:M(r,   c           	     j   . pV P                   '       Ed1   \        4       pRpV P                  R,          pVP                  4        F8  w  rV\	        V Uu. uF  quP                  V4      NK  	  up4      '       g   K6  Tp M	  Vf    \        P                  R4       \        4       p. pV P                  R,          '       d+   VP                  \        V P                  VRRR7      R34       V P                  R,          '       dC   V P                  R	,          '       d*   VP                  \        V P                  VRR
7      R34       V# V P                  R,          '       d   VP                  \        4       R34       V P                  R,          '       d   VP                  \        4       R34       V# u upi )z
Returns a list of context managers which should be tried when setting
up a network context.  If we're running in init mode, this return a
noop since networking should already be configured.
Nr   zGFailed to find default interface, attempting DHCP on fallback interfacer   FT)r   r   r   r   )r   )rW   r   r;   itemsany
startswithr3   warningr   appendr   r>   noop)r<   network_context_managers
interfaces	interfacepreferred_prefixesmacinfprefixs   &       r-   _get_network_context_managers.DataSourceAkamai._get_network_context_managers   s     	! 
 /0JI!%-E!F&,,.:LM:L^^F+:LM  !$I /  ) ./	')${{<(((//* KK%!&!%	 
 {{<((T[[-F-F(//* KK%!%
 	6 ('! {{<(((// {{<(((// ('o Ns   F0
c                &   < V ^8  d   QhRS[ RS[ /# )rA   rC   rD   rF   )rG   rH   s   "r-   rI   rJ      s     B Bd Bt Br,   c           
     6    \         P                  ! V P                  RVR7      R^^^RR/R7      pVP                  ^8w  d#   \        P                  RVP                  4       R# \        V4      p\         P                  ! V P                  R	VR7      ^^^R
RRV/R7      p\        P                  ! \        V4      4      V n	        \         P                  ! V P                  RVR7      ^^^RV/R7      p\        V4      V n
         \        V P                  4      V n
        R#   \        P                   d"   p\        P                  RT4        Rp?R# Rp?ii ; i  \         P                   d-   p\        P                  RT'       d   RMRT4        Rp?R# Rp?ii ; i)z
Runs through the sequence of requests necessary to retrieve our
metadata and user data, creating a token for use in doing so, capturing
the results.
r   rC   PUTzMetadata-Token-Expiry-Seconds300)request_methodtimeoutsec_betweenretriesheadersz-Fetching token returned %s; not fetching dataTr   Acceptzapplication/jsonzMetadata-Token)r|   r}   r~   r   r   z*Failed to base64 decode userdata due to %sNz1Failed to retrieve metadata using IPv%s due to %s64F)r   readurlrP   coder3   rV   rE   jsonloadsr   userdata_rawr   binasciiErrorri   UrlError)r<   rC   token_responser   r   r   es   &&     r-   _fetch_metadata DataSourceAkamai._fetch_metadata   s   :	'//7$3U	N ""c)C"'' 'E "))
6:0$e	H !JJs8}5DM "))
6:$eH !$HDM$-d.?.?$@!  >> MH!LL M"" 		 KKC3
 		sC   A E $BE D E3E	E EE F,!FFc                    < V ^8  d   QhRS[ /# rS   rv   )rG   rH   s   "r-   rI   rJ   '  s     2 24 2r,   c                   \         P                  R4       \        4       '       g   \         P                  R4       R# \	        4       pRV/V n        V P                  4       pV\        P                  8w  dD   V\        P                  8X  d   \         P                  R4       R# \         P                  R4       R# V P                  4       pV Fh  w  rET;_uu_ 4        V P                  VR7      pV'       d6   V P
                  P                  R	V4      V P
                  R&    R
R
R
4        R#  R
R
R
4       Kj  	  \         P                  R4       R#   + '       g   i     K  ; i)zG
Overrides _get_data in the DataSource class to actually retrieve data
z#Getting data from Akamai DataSourcez#Not running on Akamai, not running.Fzinstance-idz5Metadata is not available, returning local data only.TzFConfigured not to fetch data at this stage; waiting for a later stage.rx   idNzHFailed to contact metadata service, falling back to local metadata only.)r3   r4   r   rV   r   r   r[   r!   r)   r(   rs   r   getri   )r<   local_instance_idavailabilityrl   managerrC   dones   &      r-   	_get_dataDataSourceAkamai._get_data'  s0    			78~~HH:;13,
 ..05???9GGGK HH! #'#E#E#G 7OG++6+:37==3D3D)4DMM-0  & #    8 KK!
 ' s   AEEc                    < V ^8  d   QhRS[ /# rS   rv   )rG   rH   s   "r-   rI   rJ   [  s     
 
D 
r,   c                L    \         P                  ! V P                  4       R4      # )zR
A local-only check to see if the instance id matches the id we see on
the system
zsystem-serial-number)r
   instance_id_matches_system_uuidget_instance_id)r<   r=   s   &&r-   check_instance_id"DataSourceAkamai.check_instance_id[  s&    
 66  "$:
 	
r,   )r;   r   r   N)F)r#   r$   r%   r&   dsnamerW   r6   rP   r[   rX   rY   rs   r   r   r   r+   __classdictcell__)rH   s   @r-   r/   r/   8   sk     FK
$- -$5 5(4 4*	4 	4M( M(^B BH2 2h
 
r,   r/   c                       ] tR tRtRtRtRtR# )DataSourceAkamaiLocalie  z
A subclass of DataSourceAkamai that runs the same functions, but during the
init-local stage.  This allows configuring networking via cloud-init, as
networking hasn't been configured yet.
Tr"   N)r#   r$   r%   r&   r'   rW   r+   r"   r,   r-   r   r   e  s     Kr,   r   c                N    V ^8  d   QhR\         \        P                  ,          /# rS   )r   r
   r5   )rG   s   "r-   rI   rI     s     ; ;D););$< ;r,   c                 8    \         P                  ! V \        4      # )N)r
   list_from_dependsdatasources)dependss   &r-   get_datasource_listr     s    $$Wk::r,   )(r   r   loggingbase64r   
contextlibr   rk   enumr   typingr   r   r   r	   	cloudinitr
   r   r   cloudinit.netr   r   cloudinit.net.ephemeralr    cloudinit.sources.helpers.akamair   r   r   	getLoggerr#   r3   r:   r!   r5   r/   r   DEP_FILESYSTEMDEP_NETWORKr   r   r"   r,   r-   <module>r      s       '  * * / / B 6  ! (, NO $$$ % 0 j
w)) j
Z	,  W3356 	""	
	 ;r,   