관리-도구
편집 파일: DataSourceAkamai.cpython-39.opt-1.pyc
a ����'�Dg�2������������������� ���@���s.��d�dl�Z�d�dlZd�dlZd�dlmZ�d�dlmZ�d�dlm Z �d�dl mZmZm Z mZ�d�dlmZmZmZ�d�dlmZmZ�d�dlmZ�d�d lmZmZmZ�e�e�Zd dd�d ddd�ddddddgd�ZG�dd��de �Z G�dd��dej!�Z"G�dd��de"�Z#e#ej$ffe"ej$ej%ffgZ&eej!�d�dd�Z'dS�)�����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�������������������@���s���e�Zd�ZdZdZdZdZdS�)�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��r*���r*����F/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceAkamai.pyr ���-���s���r ���c�������������������@���s����e�Zd�ZdZdZdd��Zdeeed�dd�Ze d�d d �Z e d�dd�Ze d�d d�Ze eeeef�ef��d�dd�Zdeed�dd�Zed�dd�Zed�dd�ZdS�)�DataSourceAkamai�AkamaiFc�����������������C���sJ���t��d��tj�|�|||��t��|�_t�t ��t� |ddgi��tg�|�_d�S�)NzSetting up Akamai DataSourceZ datasourcer-���) �LOG�debugr ���� DataSource�__init__�dictr���r���Z mergemanydictr���Zget_cfg_by_path�BUILTIN_DS_CONFIG�ds_cfg)�self�sys_cfg�distror���r*���r*���r+���r1���<���s���� ���zDataSourceAkamai.__init__)� path_name�use_v6�returnc�����������������C���sZ���||�j�d�vrtd�|���d}|s.|�j�d�s2d}|�j�d�|�}|�j�d�|�}d�||�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 r���zUnknown path name {}r���r���r���r���z{}{})r4���� ValueError�format)r5���r8���r9���Zversion_keyZbase_url�pathr*���r*���r+���� _build_urlN���s����zDataSourceAkamai._build_url�r:���c�����������������C���sR���|�j�d�s|�j�d�r(|�j�d�s8|�j�d�s8t�d��tjS�|�jrF|����S�|����S�dS�)z� Returns whether metadata should be retrieved at this stage, at the next stage, or never, in the form of a MetadataAvailabilityResult. r���r���r���r���z*Configuration prohibits fetching metadata.N)r4���r.����infor ���r'����local_stage�_should_fetch_data_local�_should_fetch_data_network�r5���r*���r*���r+����_should_fetch_data`���s�������� z#DataSourceAkamai._should_fetch_datac�����������������C���sD���|�j�d�st�d��tjS�|�j�d�s>|�j�d�s>t�d��tjS�tjS�)z� Returns whether metadata should be retrieved during the local stage, or if it should wait for the init stage. r���z)Configuration prohibits local stage setupr���r���z9Configuration does not allow for ephemeral network setup.�r4���r.���r@���r ���r)���r(���rD���r*���r*���r+���rB���t���s���� �z)DataSourceAkamai._should_fetch_data_localc�����������������C���s ���|�j�d�st�d��tjS�tjS�)zS Returns whether metadata should be fetched during the init stage. r���z1Configuration does not allow for init stage setuprF���rD���r*���r*���r+���rC�������s���� z+DataSourceAkamai._should_fetch_data_networkc��������������������s����g�}|�j�r�t��}d}|�jd�}|���D�]&\��}t��fdd�|D���r&|}�qNq&|du�rft�d��t��}g�}|�jd�r�|�t |�j |ddd �df��|�jd �r�|�jd�r�|�t |�j |dd�df��n4|�jd�r�|�t��df��|�jd �r�|�t��df��|S�) 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���c��������������������s���g�|�]}����|��qS�r*���)� startswith)�.0�prefix�Zmacr*���r+���� <listcomp>���������zBDataSourceAkamai._get_network_context_managers.<locals>.<listcomp>zGFailed to find default interface, attempting DHCP on fallback interfacer���FTr���r���r���)r���)rA���r ���r4����items�anyr.����warningr����appendr���r7����noop)r5����network_context_managersZ interfacesZ interfaceZpreferred_prefixes�infr*���rJ���r+����_get_network_context_managers����sh���� � �� ������ �� ��z.DataSourceAkamai._get_network_context_managers)r9���r:���c�������������� ���C���s:��z�t�j|�jd|d�ddddddid �}|jd krDt�d|j��W�dS�t|�}t�j|�jd |d�dddd|d�d�}t�t|��|�_ t�j|�jd|d�dddd|id�}t|�|�_ zt|�j �|�_ W�n2�tj y��}�zt�d|��W�Y�d}~n d}~0�0�W�nB�t�j�y4�}�z&t�d|�rdnd|��W�Y�d}~dS�d}~0�0�dS�)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����r9���ZPUT����r"�������zMetadata-Token-Expiry-SecondsZ300)Zrequest_method�timeout�sec_between�retries�headers�����z-Fetching token returned %s; not fetching dataTr���zapplication/json)ZAccept�Metadata-Token)rX���rY���rZ���r[���r���r]���z*Failed to base64 decode userdata due to %sNz1Failed to retrieve metadata using IPv%s due to %s�6�4F)r ���Zreadurlr>����coder.���r@����str�json�loadsr���Zuserdata_rawr����binascii�ErrorrO���ZUrlError)r5���r9���Ztoken_responser���r���r����er*���r*���r+����_fetch_metadata����s`������ ��� �� &�z DataSourceAkamai._fetch_metadatac�������������� ���C���s����t��d��t��st��d��dS�t��}d|i|�_|����}|tjkrf|tj krXt��d��dS�t��d��dS�|�� ��}|D�]`\}}|�D�|�j|d�}|r�|�j�d |�|�jd<�W�d �����q�W�d ����qr1�s�0����Y��qrt�� d��dS�)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.rU����idNzHFailed to contact metadata service, falling back to local metadata only.)r.���r/���r���r@���r���r���rE���r ���r(���r'���rT���rg����getrO���)r5���Zlocal_instance_idZavailabilityrR���Zmanagerr9���Zdoner*���r*���r+���� _get_data'��s@���� � ��� 0�zDataSourceAkamai._get_datac�����������������C���s���t��|����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 ���Zinstance_id_matches_system_uuidZget_instance_id)r5���r6���r*���r*���r+����check_instance_id[��s�����z"DataSourceAkamai.check_instance_idN)F)F)r#���r$���r%���ZdsnamerA���r1���ra����boolr>���r ���rE���rB���rC���r���r���r���r���r���rT���rg���rj���rk���r*���r*���r*���r+���r,���8���s��� �OD4r,���c�������������������@���s���e�Zd�ZdZdZdS�)�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&���rA���r*���r*���r*���r+���rm���e��s���rm���r?���c�����������������C���s���t��|�t�S�)N)r ���Zlist_from_depends�datasources)Zdependsr*���r*���r+����get_datasource_list��s����ro���)(rd���rb���Zlogging�base64r���� contextlibr���rQ����enumr����typingr���r���r���r���Z cloudinitr ���r ���r���Z cloudinit.netr���r ���Zcloudinit.net.ephemeralr���Z cloudinit.sources.helpers.akamair���r���r���Z getLoggerr#���r.���r3���r ���r0���r,���rm���ZDEP_FILESYSTEMZDEP_NETWORKrn���ro���r*���r*���r*���r+����<module>���sN��� ������/ ���