File manager - Edit - /usr/lib/python3/dist-packages/cloudinit/sources/azure/__pycache__/imds.cpython-310.pyc
Back
o o@�d� � @ s� d dl m Z d dlmZmZ d dlZd dlmZ d dlmZ d dl m Z d dlmZm Z e�e�ZdZG d d � d �Zddd �dededededef dd�Zdededefdd�Zdedefdd�Zdefdd�ZdS )� )�time)�Dict�OptionalN)�log)�util)�report_diagnostic_event)�UrlError�readurlzhttp://169.254.169.254/metadatac @ sH e Zd ZdZddddd�deded ee d dfdd�Zd efd d�Z dS )�ReadUrlRetryHandleraF 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 time()-based deadline to retry until. � �?� )� � i� i� N��logging_backoff�max_connection_errors�retry_codes�retry_deadliner r r �returnc C s( || _ || _|| _|| _d| _d| _d S )Nr r )r r r r �_logging_threshold�_request_count)�selfr r r r � r �>/usr/lib/python3/dist-packages/cloudinit/sources/azure/imds.py�__init__ s zReadUrlRetryHandler.__init__c C s� | j d7 _ t|t�std| tjd� dS d}| jd ur't� | jkr'd}nd}t|jt j �r?| jd8 _| jdk r>d}n |jd urL|j| j vrLd}| j | jkr[| j| j9 _nd}|sa|smtd| 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 �cause�requests�ConnectionErrorr �coder r r �info)r �req_args� exceptionr �retryr r r �exception_callback1 s@ �� � ��z&ReadUrlRetryHandler.exception_callback) �__name__� __module__�__qualname__�__doc__�float�intr r �boolr) r r r r r s ���� �r T� )�log_response�timeout�urlr r2 r3 r c C sZ t |d�}zt| |jddid||d�}W |jS ty, } z td| tjd� � d}~ww ) 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. �r �Metadata�trueT��exception_cb�headers�infinite�log_req_respr3 z&Failed to fetch metadata from IMDS: %sr N)r r r) r r r r �contents)r4 r r2 r3 �handler�response�errorr r r � _fetch_url\ s&