HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceOracle.cpython-312.pyc
�

�f{B���dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlm
Z
mZmZmZmZddlmZddlmZmZmZmZddlmZej6e�Zd	d
iZdZdZ e d
zZ!dZ"ddiZ#edd�Z$Gd�dejJ�Z&deddfd�Z'Gd�dejP�Z)Gd�de)�Z*de
e+fd�Z,de-fd�Z.de+de/fd�Z0de+de
e	e+e+ffd �Z1d
e)jde)jfd!�d"e-de
e$fd#�Z4e)ejjffe*ejjejlffgZ7d$�Z8ed%k(rOddl9Z9d&Z:e9jve:�'�Z<e<j{�e>e
j~e4�e.�d(���yy))a3Datasource for Oracle (OCI/Oracle Cloud Infrastructure)

Notes:
 * This datasource does not support OCI Classic. OCI Classic provides an EC2
   lookalike metadata service.
 * The UUID provided in DMI data is not the same as the meta-data provided
   instance-id, but has an equivalent lifespan.
 * We do need to support upgrade from an instance that cloud-init
   identified as OpenStack.
 * Bare metal instances use iSCSI root, virtual machine instances do not.
 * Both bare metal and virtual machine instances provide a chassis-asset-tag of
   OracleCloud.com.
�N)�
namedtuple)�Dict�Optional�Tuple)�
atomic_helper�dmi�net�sources�util)�
NetworkConfig)�cmdline�	ephemeral�get_interfaces_by_mac�is_netfail_master)�wait_for_url�configure_secondary_nicsFzOracleCloud.comz&http://169.254.169.254/opc/v{version}/z{path}/i(#�
Authorizationz
Bearer Oracle�OpcMetadataz version instance_data vnics_datac��eZdZdZdefd�Zy)�KlibcOracleNetworkConfigSourcez�Override super class to lower the applicability conditions.

    If any `/run/net-*.cfg` files exist, then it is applicable. Even if
    `/run/initramfs/open-iscsi.interface` does not exist.
    �returnc�,�t|j�S)zOverride is_applicable)�bool�_files��selfs �D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceOracle.py�
is_applicablez,KlibcOracleNetworkConfigSource.is_applicable:s���D�K�K� � �N)�__name__�
__module__�__qualname__�__doc__rr�rrrr3s���!�t�!rr�network_configrc�<�d|vry|ddvrtjd|d�yt�}|ddk(rT|dD�cgc]	}d|vs�|��c}D]8}|ddk(s�d	|vs�|d	}|j|�}|s�*t	|�s�6|d	=�:y|dd
k(r�|jdi�j�D]_\}}d|vs�|jdi�jd
�}|s�/|j|�}|s�Ct	|�s�O|dd
=|d=||dd<�ayycc}w)aP
    Search network config physical interfaces to see if any of them are
    a netfailover master.  If found, we prevent matching by MAC as the other
    failover devices have the same MAC but need to be ignored.

    Note: we rely on cloudinit.net changes which prevent netfailover devices
    from being present in the provided network config.  For more details about
    netfailover devices, refer to cloudinit.net module.

    :param network_config
       A v1 or v2 network config dict with the primary NIC, and possibly
       secondary nic configured.  This dict will be mutated.

    �versionN)��z+Ignoring unknown network config version: %sr(�config�type�physical�mac_addressr)�	ethernets�match�
macaddresszset-name�name)�LOG�debugr�getr�items)r%�mac_to_name�c�cfg�mac�cur_name�_�macaddrs        r�_ensure_netfailover_safer=?sY�� ��&���i� ��.��	�	�9��9�%�	
�	�'�)�K��i� �A�%�-�h�7�G�!�6�Q�;�A�G�	/�C��6�{�j�(� �C�'��m�,�C�*���s�3�H�#� �*�8�4��
�.�	/�
�	�	"�a�	'�$�(�(��b�9�?�?�A�
	8�F�A�s��#�~��'�'�'�2�.�2�2�<�@���*���w�7�H�#� �*�8�4���L��6��
�O�/7��G��V�,�
	8�
(��Hs�	D�
Dc���eZdZUdZdZdZejjejjejjejjfZe
ejdfed<gdd�Zeed<dZd	Zd
Z�fd�Zded
df�fd�Zd
efd�Zed
efd��Zd�Zd
efd�Zd�Zd
efd�Zd
efd�Ze d��Z!ddefd�Z"�xZ#S)�DataSourceOracle�OracleN.�network_config_sourcesr()r*r'�_network_configT��c�F��tt|�
|g|��i|��d|_t	j
t	j|d|jgi�tg�|_	t�|_|j�}|j|_|j|_y)N�
datasource)�superr?�__init__�_vnics_datar�
mergemanydict�get_cfg_by_path�dsname�BUILTIN_DS_CONFIG�ds_cfgr�_network_config_source�get_url_params�max_wait_seconds�url_max_wait�timeout_seconds�url_timeout)r�sys_cfg�args�kwargs�
url_params�	__class__s     �rrHzDataSourceOracle.__init__�s����
���.�w�H��H��H�����(�(��$�$�W�|�T�[�[�.I�2�N�!�
�
���'E�&F��#��(�(�*�
�&�7�7���%�5�5��r�ci_pkl_versionrc���t�|�|�t|d�s
t|dd�t|d�st|dt	��yy)NrIrO)rG�	_unpickle�hasattr�setattrr)rrZrYs  �rr\zDataSourceOracle._unpickle�sJ���
���.�)��t�]�+��D�-��.��t�5�6���(�.�0�
�7rc�L�t|jjdg��S)Nr*)rrBr4rs r�_has_network_configz$DataSourceOracle._has_network_config�s ���D�(�(�,�,�X�r�:�;�;rc��t�S)z@Check platform environment to report if this datasource may run.)�_is_platform_viabler$rr�	ds_detectzDataSourceOracle.ds_detect�s
��#�$�$rc�Z�t�|_|jrQtj|j
t
j�tjdd��td���}ntj�}|j�}|jjdt d�}|5t#|xs||j$|j&��}ddd�sy|j(x}|_t,j|j.�	�|_|j2|_|d
|dd|d
|dd�|_d|vrQ|djd�}|rt9j:|�|_|djd�|j6d<y#1swY��xYw)Nr)�instance�r'�path)�url�headers)�iface�connectivity_url_datar��fetch_vnics_data�max_wait�timeoutF)r'�	ociAdName�idr�hostname�displayName)zavailability-zonezinstance-idzlaunch-indexzlocal-hostnamer1�metadata�	user_data�ssh_authorized_keys�public_keysT)�_read_system_uuid�system_uuid�perform_dhcp_setupr�EphemeralDHCPv4�distror	�find_fallback_nic�METADATA_PATTERN�format�
V2_HEADERSr�nullcontext�_is_iscsi_rootrNr4rM�read_opc_metadatarRrT�
instance_data�_crawled_metadata�
METADATA_ROOTr'�metadata_address�
vnics_datarIrt�base64�	b64decode�userdata_raw)r�network_context�fetch_primary_nic�fetch_secondary_nics�fetched_metadata�datarus       r�	_get_datazDataSourceOracle._get_data�s���,�.����"�"�'�7�7�����+�+�-�+�2�2�1�:�2�N�)�'��O�#�.�.�0�O� $� 3� 3� 5�5��#�{�{���&��8�9� 
��
�	�0�!2�!J�6J��*�*��(�(� ��	� ��(8�(F�(F�F��t�%� -� 4� 4�$�,�,�!5�!
���,�6�6���"&�k�!2���:��"�:�.���'�
��
�����Z�(�,�,�[�9�I��$*�$4�$4�Y�$?��!�+/�
�+;�+?�+?�%�,�D�M�M�-�(��?	�	�s�7'F!�!F*c�@�tj|j�S)z�quickly check (local only) if self.instance_id is still valid

        On Oracle, the dmi-provided system uuid differs from the instance-id
        but has the same life-span.)r
�instance_id_matches_system_uuidry)rrUs  r�check_instance_idz"DataSourceOracle.check_instance_id�s��
�6�6�t�7G�7G�H�Hrc�^�tj|jjd��S)Nrw)r
�normalize_pubkey_datartr4rs r�get_public_ssh_keysz$DataSourceOracle.get_public_ssh_keys�s"���,�,�T�]�]�->�->�}�-M�N�Nrc�6�|jj�S)z)Return whether we are on a iscsi machine.)rOrrs rr�zDataSourceOracle._is_iscsi_root�s���*�*�8�8�:�:rc�6�|jj�S�N)rO�
render_configrs r�_get_iscsi_configz"DataSourceOracle._get_iscsi_config�s���*�*�8�8�:�:rc���|j�r|jSd}|j�r|j�|_|j�stjd�d}|jjdtd�}|s|r	|j|�t|j�|jS#t$rtjtd�Y�FwxYw)z�Network config is read from initramfs provided files

        Priority for primary network_config selection:
        - iscsi
        - imds

        If none is present, then we fall back to fallback configuration.
        FzLCould not obtain network configuration from initramfs. Falling back to IMDS.Trz+Failed to parse IMDS network configuration!)r`rBr�r�r2�warningrNr4rM�!_add_network_config_from_opc_imds�	Exceptionr�logexcr=)r�set_primary�
set_secondarys   rr%zDataSourceOracle.network_config�s����#�#�%��'�'�'������ �#'�#9�#9�#;�D� ��'�'�)��K�K�(�
��K������&��8�9�
�
��-�
��6�6�{�C�	!��!5�!5�6��#�#�#���
�����A��
�s�C�#C+�*C+r�c�
�|j�tjd�y|s'd|jdvrtjd�yt�}|r|jn|jdd}t	|�D�]\}}|xr|dk(}|dj�}||vrtjd|��>||}t
j|d	�}	|jd
dk(rJ|rddi}
nd
|d�d|	j��d�}
|d|t|
gd�}|jdj|���|jd
dk(s��td|id|d�}|s|d�d|	j��g|d<||jd|<��y)a�Generate primary and/or secondary NIC config from IMDS and merge it.

        It will mutate the network config to include the secondary VNICs.

        :param set_primary: If True set primary interface.
        :raises:
            Exceptions are not handled within this function.  Likely
            exceptions are KeyError/IndexError
            (if the IMDS returns valid JSON with unexpected contents).
        Nz#NIC data is UNSET but should not be�nicIndexrz\VNIC metadata indicates this is a bare metal machine; skipping secondary VNIC configuration.r(�macAddrz)Interface with MAC %s not found; skipping�subnetCidrBlockr'r+�dhcp�static�	privateIp�/)r+�addressr,)r1r+r-�mtu�subnetsr*r)r0F)r�r/�dhcp6�dhcp4�	addressesr.)rIr2r�r�	enumerate�lower�	ipaddress�
ip_networkrB�	prefixlen�MTU�append)rr��interfaces_by_macr��index�	vnic_dict�
is_primaryr-r1�network�subnet�interface_configs            rr�z2DataSourceOracle._add_network_config_from_opc_imdss������#��K�K�=�>���
�d�.>�.>�q�.A� A�
�K�K�9�
�
�1�3��)4�T�%�%�$�:J�:J�1�2�:N�
� )�*� 5�+	K��E�9�$�3��!��J�#�I�.�4�4�6�K��"3�3����?����$�[�1�D��*�*�9�5F�+G�H�G��#�#�I�.�!�3��$�f�-�F�!)�(��5�6�a��8I�8I�7J�K��F�!�&�#.�� &�x�$� ��$�$�X�.�5�5�6F�G��%�%�i�0�A�5��*�K�8�"�'�	$� �"�$�[�1�2�!�G�4E�4E�3F�G�5�$�[�1�;K��$�$�[�1�$�7�W+	Kr)F)$r r!r"rLry�vendordata_purer
�NetworkConfigSource�CMD_LINE�
SYSTEM_CFG�DS�	INITRAMFSrAr�__annotations__rB�dictrzrRrTrH�intr\rr`�staticmethodrcr�r�r�r�r��propertyr%r��
__classcell__)rYs@rr?r?ss'���
�F��K��O��#�#�,�,��#�#�.�.��#�#�&�&��#�#�-�-�	G��E�'�"=�"=�s�"B�C��(*�a�8�O�T�8����L��K�6� 	��	��	�<�T�<��%�t�%��%�4�lI�D�I�O�;��;�;�4�;��+$��+$�ZLK�T�LKrr?c��eZdZdZy)�DataSourceOracleNetFN)r r!r"rzr$rrr�r�ms���rr�c�T�tjd�}|�dS|j�S)Nzsystem-uuid)r�
read_dmi_datar�)�sys_uuids rrxrxqs)��� � ��/�H��#�4�9����)9�9rc�>�tjd�}|tk(S)Nzchassis-asset-tag)rr��CHASSIS_ASSET_TAG)�	asset_tags rrbrbvs���!�!�"5�6�I��)�)�)rrhc�,�|jd�rdSdS)Nzhttp://169.254.169.254/opc/v2r)r()�
startswith�rhs r�_url_versionr�{s�����>�?�1�F�Q�Frc�.�t|�dk(rtSdS)Nr))r�r�r�s r�_headers_cbr�s��%�c�*�a�/�:�9�T�9rrlrmc�f�tjdd��tjdd��g}tj�}t|||td��\}}|st
j
d�ytj|jd	��}t|�}d}	|r�ttj|d
��g|tj�|z
z
|td��\}
}|
r%tj|jd	��}	nt
j
d�t|||	�S)aoFetch metadata from the /opc/ routes.

    :return:
        A namedtuple containing:
          The metadata version as an integer
          The JSON-decoded value of the instance data endpoint on the IMDS
          The JSON-decoded value of the vnics data endpoint if
            `fetch_vnics_data` is True, else None
        or None if fetching metadata failed

    r)rerfr(r)rnro�
headers_cb�
sleep_timezFailed to fetch IMDS metadata!Nzutf-8�vnicsz+Failed to fetch IMDS network configuration!)r~r�timerr�r2r��json�loads�decoder�r)rmrnro�urls�
start_time�instance_url�instance_responser��metadata_versionr��	vnics_url�vnics_responses            rr�r��s��*	����
��;�����
��;��D�����J�&2������'�#�L�#�����4�5���J�J�0�7�7��@�A�M�#�L�1���J��%1�
�
$�
$�-=�G�
$�
L�M������z�!9�:��"��%
�!�	�>�����N�$9�$9�'�$B�C�J��K�K�E�F��'��
�C�Crc�6�tj|t�Sr�)r
�list_from_depends�datasources)�dependss r�get_datasource_listr��s���$�$�W�k�:�:r�__main__z�
        Query Oracle Cloud metadata and emit a JSON object with two keys:
        `read_opc_metadata` and `_is_platform_viable`.  The values of each are
        the return values of the corresponding functions defined in
        DataSourceOracle.py.)�description)r�rb)@r#r�r�r��loggingr��collectionsr�typingrrr�	cloudinitrrr	r
r�cloudinit.distros.networkingr�
cloudinit.netr
rrr�cloudinit.url_helperr�	getLoggerr r2rMr�r�r~r�r�r�KlibcNetworkConfigSourcerr=�
DataSourcer?r��strrxrrbr�r�r�rRrTr��DEP_FILESYSTEM�DEP_NETWORKr�r��argparser��ArgumentParser�parser�
parse_args�print�
json_dumpsr$rr�<module>rs��������"�(�(�<�<�6���.��g����!������&��8�
� �9�,������
/�
���(J�K��	!�W�%E�%E�	!�18�]�18�t�18�hwK�w�)�)�wK�t�*��:�8�C�=�:�
*�T�*�
G�c�G�c�G�:�S�:�X�d�3��8�n�5�:�#�
�
*�
*��(�(�	7D��7D�
�k��7D�x��.�.�0�1���"�"����	
��	��;��z��� �K�
%�X�
$�
$��
=�F�
����	� �
� � �%6�%8�':�'<�
�	
��r