관리-도구
편집 파일: imds.cpython-39.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&����contents)r9���r:���r7���r8����response�errorr���r���r���� _fetch_url{���s ����� �r?���)r9���r:���r���c������������� ���C���s\���t�|�|d�}zt�|�d��W�S��tyV�}�z td|�tjd����W�Y�d}~n d}~0�0�dS�)z�Fetch 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. �r:���zutf-8z&Failed to parse metadata from IMDS: %sr#���N)r?���r���Z load_json�decode� ValueErrorr���r%���r&���)r9���r:����metadatar>���r���r���r����_fetch_metadata����s���� �rD���)r���r���r���c�������������� ���C���s����t�||�d�}ztd�}t||d�W�S��ty��}�zR|jdkrvtdtjd��t�||�d�}td�}t||d�W��Y�d}~S���W�Y�d}~n d}~0�0�dS�) z�Fetch 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=truer@���i���z,Falling back to IMDS api-version: 2019-06-01r#���z /instance?api-version=2019-06-01N)r����IMDS_URLrD���r ���r*���r���r%���r&���)r���r���r:���r9���r>���r���r���r���� fetch_metadata_with_api_fallback����s(���� � ��rF���r!���c������������������C���sP���t�d�}�tddddd�}t|�|jtddd d �}td|jd���d�tjd ��|j S�)zhFetch extended metadata, falling back to non-extended as required. :raises UrlError: on error. z'/reprovisiondata?api-version=2019-06-01g�������@r"���)r���r���r���Nr���TFr6���r;���zPolled IMDS z time(s)r#���) rE���r���r ���r.���r���r���r���r%����debugr<���)r9���Zhandlerr=���r���r���r����fetch_reprovision_data����s(����� � �rH���)N) Zloggingr ����timer����typingr���r���r���r���r(���Z cloudinitr���Zcloudinit.sources.helpers.azurer���Zcloudinit.url_helperr ���r ���Z getLoggerr/���r%���rE���r���r���r���r5���r4����bytesr?���rD���r3���rF���rH���r���r���r���r����<module>���s<��� c��$����