관리-도구
편집 파일: imds.cpython-39.opt-1.pyc
a '�Dg. � @ 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�eeeeed�dd�Zeeed�dd�Zdeee ed�dd�Zed�dd�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)ZMetadatazx-ms-client-request-id)�str�uuidZuuid4)Z_url� r �@/usr/lib/python3.9/site-packages/cloudinit/sources/azure/imds.py� headers_cb s �r c @ sF e Zd ZdZddddd�eee ee dd�dd�Zed �d d�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_deadline)r 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__�r c C sJ | j d7 _ t|t�s.td| tjd� dS d}| jd urNt� | jkrNd}nd}| jd ur�t|j t j�r�| jd8 _| jdkr�d}n|jd ur�|j| j vr�d}| j | jkr�| j| j9 _nd}|jd ur�| j|jkr�d}|j| _n:| jd u �st| jt��rt|j | j��s"d}t|j �| _|�s.|�sFtd| j |f tjd� |S )N� z1Polling IMDS failed with unexpected exception: %r�Zlogger_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 Zreq_args� exception�logZretryr r r �exception_callback: sd ��� �� � � � ����z&ReadUrlRetryHandler.exception_callback) �__name__� __module__�__qualname__�__doc__�floatr �intr �boolr. r r r r r s ��r T� )�log_response�timeout)�url� retry_handlerr7 r8 r c C sZ zt | |jtd||d�}W n8 tyR } z td| tjd� � W Y d}~n d}~0 0 |jS )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�Zexception_cbr ZinfiniteZlog_req_respr8 z&Failed to fetch metadata from IMDS: %sr# N)r r. r r r r% r&