File: //lib/python3/dist-packages/cloudinit/sources/azure/__pycache__/imds.cpython-310.pyc
o
x[h$ � @ s� d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl Z d dl
mZ d dlm
Z
d dlmZmZ e �e�ZdZdd � ZG d
d� d�Zdd
d�dededededef
dd�Zdededefdd�Z ddedee defdd�Zdefdd�ZdS )� N)� monotonic)�Dict�Optional�Type�Union)�util)�report_diagnostic_event)�UrlError�readurlzhttp://169.254.169.254/metadatac C s dt t�� �d�S )N�true)�Metadatazx-ms-client-request-id)�str�uuid�uuid4)�_url� r �>/usr/lib/python3/dist-packages/cloudinit/sources/azure/imds.py�
headers_cb s
�r c @ sL e Zd ZdZddddd�dedee dee d dfd
d�Zd efdd
�Z dS )�ReadUrlRetryHandleraK 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.
� �?N)� � � i� ��logging_backoff�max_connection_errors�retry_codes�retry_deadliner r r �returnc C s. || _ || _|| _|| _d| _d| _d | _d S )Nr r )r r r r �_logging_threshold�_request_count�_last_error)�selfr r r r r r r �__init__% s
zReadUrlRetryHandler.__init__c C s@ | j d7 _ t|t�std| tjd� dS d}| jd ur't� | jkr'd}nd}| jd urDt|j t
j�rD| jd8 _| jdkrCd}n
|jd urQ|j| j
vrQd}| j | jkr`| j| j9 _nd}|jd urt| j|jkrsd}|j| _n| jd u s�t| jt�r�t|j | j�s�d}t|j �| _|s�|s�td| j |f tjd� |S )N� z1Polling IMDS failed with unexpected exception: %r��logger_funcFTr z1Polling IMDS failed attempt %d with exception: %r)r �
isinstancer r �LOG�warningr r r �cause�requests�ConnectionError�coder r r r! �type)r"