D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
lib
/
python3.6
/
site-packages
/
cloudinit
/
sources
/
azure
/
__pycache__
/
Filename :
imds.cpython-36.pyc
back
Copy
3 \�men � @ s� d dl Z d dlmZ d dlmZmZmZmZ d dlZd dlm Z d dl mZ d dlm Z mZ e je�ZdZG dd � d �Zd dd�eeeeed �dd�Zeeed�dd�Zdeee ed�dd�Zed�dd�ZdS )� N)�time)�Dict�Optional�Type�Union)�util)�report_diagnostic_event)�UrlError�readurlzhttp://169.254.169.254/metadatac @ sF e Zd ZdZddddd�eee ee dd �d d�Zed�d 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. g �?N� � � �� )�logging_backoff�max_connection_errors�retry_codes�retry_deadline)r r r �returnc C s. || _ || _|| _|| _d| _d| _d | _d S )Ng �?r )r r r r �_logging_threshold�_request_count�_last_error)�selfr r r r � r �/usr/lib/python3.6/imds.py�__init__ s zReadUrlRetryHandler.__init__)r c C sP | j d7 _ t|t�s.td| tjd� dS d}| jd k rNt� | jkrNd}nd}| jd k r�t|j t j�r�| jd8 _| jdkr�d}n|jd k r�|j| j kr�d}| j | jkr�| j| j9 _nd}|jd k r�| j|jkr�d}|j| _n>| jd k�st| jt� �st|j | j� �r&d}t|j �| _|�s4| �rLtd| 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�info)r Zreq_argsZ exception�logZretryr r r �exception_callback2 sJ z&ReadUrlRetryHandler.exception_callback)r r r r ) �__name__� __module__�__qualname__�__doc__�floatr �intr �boolr( r r r r r s r T� )�log_response�timeout)�url� retry_handlerr1 r2 r c C s\ yt | |jddid||d�}W n6 tk rT } ztd| tjd� � W Y dd}~X nX |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. �Metadata�trueT)�exception_cb�headers�infinite�log_req_respr2 z&Failed to fetch metadata from IMDS: %s)r N)r r( r r r r �contents)r3 r4 r1 r2 �response�errorr r r � _fetch_urlp s r>