+
    i                         ^ RI t ^ RIt^ RIHt ^ RIHtHtHtHt ^ RI	t	^ RI
Ht ^ RIHt ^ RIHtHt ] P"                  ! ]4      tRtR t ! R	 R
4      tRRR^/R R lltR R ltRR R lltR R ltR# )    N)	monotonic)DictOptionalTypeUnion)util)report_diagnostic_event)UrlErrorreadurlzhttp://169.254.169.254/metadatac                 F    R RR\        \        P                  ! 4       4      /# )Metadatatruezx-ms-client-request-id)struuiduuid4)_urls   &>/usr/lib/python3/dist-packages/cloudinit/sources/azure/imds.py
headers_cbr      s!    F #djjl"3     c                   \   a  ] tR t^t o RtRRRRRRRR/V 3R lR	 lltV 3R
 lR ltRtV tR# )ReadUrlRetryHandlera7  Manager for readurl retry behavior using exception_callback().

:param logging_backoff: Backoff to limit logging.
:param max_connection_errors: Number of connection errors to retry on.
:param retry_codes: Set of http codes to retry on.
:param retry_deadline: Optional monotonic()-based deadline to retry until.
logging_backoff      ?max_connection_errorsNretry_codesretry_deadlinec                P   < V ^8  d   QhRS[ RS[S[,          RS[S[ ,          RR/# )   r   r   r   returnN)floatr   int)format__classdict__s   "r   __annotate__ ReadUrlRetryHandler.__annotate__%   s=     8 8 8  (}	8 !8 
8r   c               `    Wn         W n        W0n        W@n        R V n        ^ V n        RV n        R# )r   N)r   r   r   r   _logging_threshold_request_count_last_error)selfr   r   r   r   s   &$$$$r   __init__ReadUrlRetryHandler.__init__%   s4      /%:"&,"%37r   c                    < V ^8  d   QhRS[ /# r   r   )bool)r"   r#   s   "r   r$   r%   :   s     > >t >r   c                   V ;P                   ^,          un         \        V\        4      '       g%   \        RV,          \        P
                  R7       R# RpV P                  e   \        4       V P                  8  d   RpMRpV P                  eX   \        VP                  \        P                  4      '       d.   V ;P                  ^,          un        V P                  ^ 8:  d   RpM+VP                  e   VP                  V P                  9  d   RpV P                   V P                  8  d%   V ;P                  V P                  ,          un        MRpVP                  e0   V P                   VP                  8w  d   RpVP                  V n        MpV P                   eG   \        V P                   \"        4      '       d'   \        VP                  V P                   4      '       g   Rp\#        VP                  4      V n        V'       g	   V'       g/   \        RV P                   V3,          \        P
                  R7       V# )   z1Polling IMDS failed with unexpected exception: %rlogger_funcFTz1Polling IMDS failed attempt %d with exception: %r)r(   
isinstancer
   r	   LOGwarningr   r   r   causerequestsConnectionErrorcoder   r'   r   r)   type)r*   	exceptionlogretrys   &&  r   exception_callback&ReadUrlRetryHandler.exception_callback:   s   q )X..#CKK
 +t222EE
 %%1jOOX557
 7
 &&!+&))Q.NN&d&6&66E$"9"99##t';';;#C >>%9>>1#,>>  $d..55ioot/?/?@@C#IOO4De#C&&	23KK
 r   )r)   r'   r(   r   r   r   r   )i  i  i  i  )	__name__
__module____qualname____firstlineno____doc__r+   r?   __static_attributes____classdictcell__)r#   s   @r   r   r      sF     8 "%8 04	8

8 +/8 8*> >r   r   log_responseTtimeoutc          
      T    V ^8  d   QhR\         R\        R\        R\        R\        /# )r   urlretry_handlerrH   rI   r   )r   r   r/   r!   bytes)r"   s   "r   r$   r$   {   s<        	  '  	 
    r   c          	          \        V VP                  \        RVVR7      pVP                  #   \         d)   p\	        RT,          \
        P                  R7       h Rp?ii ; i)a  Fetch URL from IMDS.

:param url: url to fetch.
:param log_response: log responses in readurl().
:param retry_deadline: time()-based deadline to retry until.
:param timeout: Read/connection timeout in seconds for readurl().

:raises UrlError: on error fetching metadata.
Texception_cbr   infinitelog_req_resprI   z&Failed to fetch metadata from IMDS: %sr2   N)r   r?   r   r
   r	   r5   r6   contents)rK   rL   rH   rI   responseerrors   &$$$  r   
_fetch_urlrV   {   se     &99!%
   4u<	
 	s   - A #AA c                <    V ^8  d   QhR\         R\        R\        /# )r   rK   rL   r   )r   r   r   )r"   s   "r   r$   r$      s(      	 ' 
	r   c                   \        WR7      p \        P                  ! VP                  R4      4      #   \         d)   p\        RT,          \        P                  R7       h Rp?ii ; i)zFetch IMDS metadata.

:param url: url to fetch.
:param retry_deadline: time()-based deadline to retry until.

:raises UrlError: on error fetching metadata.
:raises ValueError: on error parsing metadata.
rL   zutf-8z&Failed to parse metadata from IMDS: %sr2   N)rV   r   	load_jsondecode
ValueErrorr	   r5   r6   )rK   rL   metadatarU   s   &$  r   _fetch_metadatar^      sW     #;H~~hoog677 4u<	
 	s   $3 A&#A!!A&c                R    V ^8  d   QhR\         R\        \        ,          R\        /# )r   r   r   r   )r    r   r!   r   )r"   s   "r   r$   r$      s(      2:3-	r   c                &   \        VV R7      p \        R,           p\        W2R7      #   \         d^   pTP                  R8X  dG   \        R\        P                  R7       \        TT R7      p\        R,           p\        Y2R7      u Rp?# h Rp?ii ; i)	zFetch extended metadata, falling back to non-extended as required.

:param retry_deadline: time()-based deadline to retry until.

:raises UrlError: on error fetching metadata.
:raises ValueError: on error parsing metadata.
)r   r   z./instance?api-version=2021-08-01&extended=truerY   i  z,Falling back to IMDS api-version: 2019-06-01r2   z /instance?api-version=2019-06-01N)r   IMDS_URLr^   r
   r:   r	   r5   r6   )r   r   rL   rK   rU   s   &&   r    fetch_metadata_with_api_fallbackrb      s     (3%MIIs@@ ::#>KK 0&;-M ??C"3DDs!   ( BABB
BBc                $    V ^8  d   QhR\         /# r.   )rM   )r"   s   "r   r$   r$      s       r   c            	         \         R,           p \        R^RR7      p\        V VP                  \        RR^R7      p\        RVP                  ^,            R	2\        P                  R
7       VP                  # )z`Fetch extended metadata, falling back to non-extended as required.

:raises UrlError: on error.
z'/reprovisiondata?api-version=2019-06-01g       @N)r   r   r   TFrO   zPolled IMDS z time(s)r2   )
ra   r   r   r?   r   r	   r(   r5   debugrS   )rK   handlerrT   s      r   fetch_reprovision_datarg      s}    
 >
>C!G
 //H 
w--a/09II r   )N)loggingr   timer   typingr   r   r   r   r8   	cloudinitr   cloudinit.sources.helpers.azurer	   cloudinit.url_helperr
   r   	getLoggerrA   r5   ra   r   r   rV   r^   rb   rg    r   r   <module>rp      ss   
    . .   C 2!,\ \~  	 
  F2@r   