%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceAkamai.cpython-312.pyc

�

�f�2�	��ddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZmZmZddlmZmZddlmZdd	lmZmZmZej8e�Zd
dd�d
ddd�ddddddgd�ZGd�de	�Z Gd�dejB�Z"Gd�de"�Z#e#ejHffe"ejHejJffgZ&deejBfd�Z'y)�N)�	b64decode)�suppress)�Enum)�Any�List�Tuple�Union)�sources�
url_helper�util)�find_fallback_nic�get_interfaces_by_mac)�EphemeralIPNetwork)�get_dmi_config�get_local_instance_id�is_on_akamaizhttp://169.254.169.254zhttp://[fd00:a9fe:a9fe::1]��ipv4�ipv6z	/v1/tokenz/v1/instancez
/v1/user-data)�token�metadata�userdataTzf2:3)�	base_urls�paths�allow_local_stage�allow_init_stage�
allow_dhcp�
allow_ipv4�
allow_ipv6�preferred_mac_prefixesc��eZdZdZdZdZdZy)�MetadataAvailabilityResultzj
    Used to indicate how this instance should behave based on the availability
    of metadata to it
    r��N)�__name__�
__module__�__qualname__�__doc__�
NOT_AVAILABLE�	AVAILABLE�DEFER���D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAkamai.pyr"r"-s���
�M��I�
�Er-r"c��eZdZdZdZd�Zddededefd�Zde	fd�Z
de	fd	�Zde	fd
�Zde
eeeefeffd�Zddedefd�Zdefd
�Zdefd�Zy)�DataSourceAkamai�AkamaiFc��tjd�tjj	||||�t�|_tjt�tj|ddgi�tg�|_y)NzSetting up Akamai DataSource�
datasourcer1)
�LOG�debugr
�
DataSource�__init__�dictrr�
mergemanydictr�get_cfg_by_path�BUILTIN_DS_CONFIG�ds_cfg)�self�sys_cfg�distrors    r.r7zDataSourceAkamai.__init__<sr���	�	�0�1����#�#�D�'�6�5�A����
��(�(�� ��$�$��!�8�,���
"�
�

��r-�	path_name�use_v6�returnc���||jdvrtdj|���d}|s|jdsd}|jd|}|jd|}dj||�S)z�
        Looks up the path for a given name and returns a full url for it.  If
        use_v6 is passed in, the IPv6 base url is used; otherwise the IPv4 url
        is used unless IPv4 is not allowed in ds_cfg
        rzUnknown path name {}rrrrz{}{})r<�
ValueError�format)r=r@rA�version_key�base_url�paths      r.�
_build_urlzDataSourceAkamai._build_urlNs{���D�K�K��0�0��3�:�:�9�E�F�F�������\�2� �K��;�;�{�+�K�8���{�{�7�#�I�.���}�}�X�t�,�,r-c��|jds|jdr|jds4|jds%tjd�tjS|j
r|j
�S|j�S)z�
        Returns whether metadata should be retrieved at this stage, at the next
        stage, or never, in the form of a MetadataAvailabilityResult.
        rrrrz*Configuration prohibits fetching metadata.)r<r4�infor"r)�local_stage�_should_fetch_data_local�_should_fetch_data_network�r=s r.�_should_fetch_dataz#DataSourceAkamai._should_fetch_data`sw�����L�)�$�+�+�l�2K����/�0��K�K� 2�3�
�H�H�A�B�-�;�;�;�����0�0�2�2��2�2�4�4r-c��|jds%tjd�tjS|jds4|jds%tjd�tjStj
S)z�
        Returns whether metadata should be retrieved during the local stage, or
        if it should wait for the init stage.
        rz)Configuration prohibits local stage setuprrz9Configuration does not allow for ephemeral network setup.�r<r4rKr"r+r*rOs r.rMz)DataSourceAkamai._should_fetch_data_localtsl��
�{�{�.�/��H�H�@�A�-�3�3�3��{�{�<�(����\�1J�
�H�H�K�
�.�3�3�3�)�3�3�3r-c��|jds%tjd�tjStj
S)zS
        Returns whether metadata should be fetched during the init stage.
        rz1Configuration does not allow for init stage setuprRrOs r.rNz+DataSourceAkamai._should_fetch_data_network�s6���{�{�-�.��H�H�H�I�-�3�3�3�)�3�3�3r-c	���g}|j�rt�}d}|jd}|j�D]1\}}t	|D�cgc]}|j|���c}�s�/|}n|�tjd�t�}g}|jdr*|jt|j|dd��df�|jdr8|jd	r)|jt|j|d�
�df�|S|jdr|jt�df�|jdr|jt�df�|Scc}w)z�
        Returns a list of context managers which should be tried when setting
        up a network context.  If we're running in init mode, this return a
        noop since networking should already be configured.
        Nr zGFailed to find default interface, attempting DHCP on fallback interfacerFTrrr)r)
rLrr<�items�any�
startswithr4�warningr
�appendrr?�noop)r=�network_context_managers�
interfaces�	interface�preferred_prefixes�mac�inf�prefixs        r.�_get_network_context_managersz.DataSourceAkamai._get_network_context_managers�s���
�	!����
/�0�J��I�!%���-E�!F��&�,�,�.�
���S��:L�M��S�^�^�F�+�M��!$�I��

�� ����)��.�/�	�')�$��{�{�<�(�(�/�/�*� �K�K�%�!&�!%�	���
��{�{�<�(�T�[�[��-F�(�/�/�*� �K�K�%�!%��
�
�	�6(�'�!�{�{�<�(�(�/�/�������{�{�<�(�(�/�/������(�'��oNs�
E*
c	�(�	tj|jd|��ddddddi�	�}|jd
k7r!tjd|j�yt
|�}tj|jd
|��dddd|d���}tjt
|��|_	tj|jd|��dddd|i��}t
|�|_
	t|j�j�|_
y#tj$r }tjd|�Yd}~yd}~wwxYw#tj $r%}tjd|rdnd|�Yd}~yd}~wwxYw)z�
        Runs through the sequence of requests necessary to retrieve our
        metadata and user data, creating a token for use in doing so, capturing
        the results.
        r�rA�PUT�r$�zMetadata-Token-Expiry-Seconds�300)�request_method�timeout�sec_between�retries�headers��z-Fetching token returned %s; not fetching dataTrzapplication/json)�Accept�Metadata-Token)rjrkrlrmrrpz*Failed to base64 decode userdata due to %sNz1Failed to retrieve metadata using IPv%s due to %s�6�4F)r�readurlrI�coder4rK�str�json�loadsr�userdata_rawr�decode�binascii�ErrorrX�UrlError)r=rA�token_responserrr�es       r.�_fetch_metadataz DataSourceAkamai._fetch_metadata�s���:	�'�/�/�������7�$����3�U��
	�N��"�"�c�)����C�"�'�'�����'�E�"�)�)����
�6��:����0�&+��	�H�!�J�J�s�8�}�5�D�M�"�)�)����
�6��:����$�e���H�!$�H�
�D��
M�$-�d�.?�.?�$@�$G�$G�$I��!����>�>�
M����H�!�L�L���
M���"�"�		�
�K�K�C���3��
�
��		�sC�AE� BE�:(D#�#E�6E�E�E�E�F�,F�Fc�v�tjd�t�stjd�yt	�}d|i|_|j
�}|tjk7r?|tjk(rtjd�ytjd�y|j�}|D]Y\}}|5|j|��}|r4|j
jd	|�|j
d<	d
d
d
�y	d
d
d
��[tjd�y#1swY�{xYw)zW
        Overrides _get_data in the DataSource class to actually retrieve data
        z#Getting data from Akamai DataSourcez#Not running on Akamai, not running.Fzinstance-idz5Metadata is not available, returning local data only.TzFConfigured not to fetch data at this stage; waiting for a later stage.rd�idNzHFailed to contact metadata service, falling back to local metadata only.)r4r5rrKrrrPr"r*r)rbr�getrX)r=�local_instance_id�availabilityr[�managerrA�dones       r.�	_get_datazDataSourceAkamai._get_data's?��	�	�	�7�8��~��H�H�:�;��1�3���,�
��
��.�.�0���5�?�?�?��9�G�G�G����K����H�H�!�
��#'�#E�#E�#G� �7�	�O�G�V��
��+�+�6�+�:���37�=�=�3D�3D��)�4�D�M�M�-�0��
�
�&�#�
�
�	�
�K�K�!�
�
�'
�
�s�?D/�/D8	c�J�tj|j�d�S)zj
        A local-only check to see if the instance id matches the id we see on
        the system
        zsystem-serial-number)r
�instance_id_matches_system_uuid�get_instance_id)r=r>s  r.�check_instance_idz"DataSourceAkamai.check_instance_id[s&��
�6�6�� � �"�$:�
�	
r-N)F)r%r&r'�dsnamerLr7ru�boolrIr"rPrMrNrrr	rrrbrr�r�r,r-r.r0r08s���
�F��K�
�$-�C�-��-�#�-�$5�$>�5�(4�*D�4�*	4�,F�	4�M(�	
�e�E�#�1�1�2�D�8�9�	:�M(�^B�d�B�t�B�H2�4�2�h
�D�
r-r0c��eZdZdZdZy)�DataSourceAkamaiLocalz�
    A subclass of DataSourceAkamai that runs the same functions, but during the
    init-local stage.  This allows configuring networking via cloud-init, as
    networking hasn't been configured yet.
    TN)r%r&r'r(rLr,r-r.r�r�es����Kr-r�rBc�6�tj|t�S)N)r
�list_from_depends�datasources)�dependss r.�get_datasource_listr�s���$�$�W�k�:�:r-)(rzrv�logging�base64r�
contextlibrrZ�enumr�typingrrrr	�	cloudinitr
rr�
cloudinit.netr
r�cloudinit.net.ephemeralr� cloudinit.sources.helpers.akamairrr�	getLoggerr%r4r;r"r6r0r��DEP_FILESYSTEM�DEP_NETWORKr�r�r,r-r.�<module>r�s������'��*�*�/�/�B�6����g����!��
)�,��
�"�#�������	��%��0���j
�w�)�)�j
�Z	�,���W�3�3�5�6�	��"�"����	
��	�� ;�D��);�);�$<�;r-

Zerion Mini Shell 1.0