HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceOracle.cpython-311.pyc
�

܍~c�:�	�~�dZddlZddlZddlmZddlmZmZddlm	Z	ddlm
ZddlmZm
Z
mZddlmZdd	lmZmZmZmZdd
lmZmZeje��ZddiZd
ZdZedzZdZ ddiZ!edd��Z"Gd�dej#��Z$deddfd�Z%Gd�de
j&��Z'dee(fd�Z)de*fd�Z+d+de,d e(d!e,de-fd"�Z.dd#�d$e*de"fd%�Z/e'e
j0ffgZ1d&�Z2ed'krYddl3Z3d(Z4e3j5e4�)��Z6e6�7��e8ej9e/��e+��d*�����dSdS),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)�Optional�Tuple)�dmi)�log)�net�sources�util)�
NetworkConfig)�cmdline�	ephemeral�get_interfaces_by_mac�is_netfail_master)�UrlError�readurl�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�ZdS)�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_applicable9s���D�K� � � �N)�__name__�
__module__�__qualname__�__doc__rr�rrrr2s9��������!�t�!�!�!�!�!�!rr�network_configrc��d|vrdS|ddvr#t�d|d��dSt��}|ddkrYd�|dD��D]D}|dd	kr6d
|vr2|d
}|�|��}|s�2t	|��r|d
=�EdS|ddkr�|�di�����D]t\}}d
|vri|�d
i���d��}|r>|�|��}|s�Lt	|��r|d
d=|d=||d
d<�sdSdS)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(c��g|]}d|v�|��	S)�typer$)�.0�cs  r�
<listcomp>z,_ensure_netfailover_safe.<locals>.<listcomp>Zs��G�G�G�!�6�Q�;�;�A�;�;�;r�configr+�physical�mac_addressr)�	ethernets�match�
macaddresszset-name�name)�LOG�debugr�getr�items)r%�mac_to_name�cfg�mac�cur_name�_�macaddrs       r�_ensure_netfailover_safer@>s��� ��&�&����i� ��.�.��	�	�9��9�%�	
�	
�	
�	��'�)�)�K��i� �A�%�%�G�G�~�h�7�G�G�G�	/�	/�C��6�{�j�(�(� �C�'�'��m�,�C�*���s�3�3�H�#�/� �*�8�4�4�/��
�.��	/�	/�
�	�	"�a�	'�	'�$�(�(��b�9�9�?�?�A�A�
	8�
	8�F�A�s��#�~�~��'�'�'�2�.�.�2�2�<�@�@���8�*���w�7�7�H�#�8� �*�8�4�4�8���L��6��
�O�/7��G��V�,��
(�	'�
	8�
	8rc�,��eZdZUdZdZdZejjejj	ejj
ejjfZe
ejdfed<gdd�Zeed<�fd�Zd	efd
�Zd	efd�Zd�Zd	efd
�Zd�Zd	efd�Zd	efd�Zed���Zddefd�Z�xZS)�DataSourceOracle�OracleN.�network_config_sourcesr()r/r'�_network_configc���tt|��j|g|�Ri|��d|_t	jt	j|d|jgi��tg��|_	t��|_dS)N�
datasource)�superrB�__init__�_vnics_datar
�
mergemanydict�get_cfg_by_path�dsname�BUILTIN_DS_CONFIG�ds_cfgr�_network_config_source)r�sys_cfg�args�kwargs�	__class__s    �rrIzDataSourceOracle.__init__�s����.����%�%�.�w�H��H�H�H��H�H�H�����(��$�W�|�T�[�.I�2�N�N�!�
�
�
���'E�&F�&F��#�#�#rrc�R�t|j�dg����S)Nr/)rrEr8rs 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_viablers rrXz$DataSourceOracle._is_platform_viable�s��"�$�$�$rc�j�|���sdSt��|_tjtj��t�dd���td�|j
������}|���}|j
�dtd��}|5t!|p|���}ddd��n#1swxYwY|jx}|_t&�|j�	��|_|j|_|d
|dd|d
|dd�|_d|vrY|d�d��}|rt3j|��|_|d�d��|jd<dS)NFr)�instance�r'�path)�url�headers)�iface�connectivity_url_data�tmp_dirr��fetch_vnics_data)r'�	ociAdName�idr�hostname�displayName)zavailability-zonezinstance-idzlaunch-indexzlocal-hostnamer5�metadata�	user_data�ssh_authorized_keys�public_keysT)rX�_read_system_uuid�system_uuidr
�EphemeralDHCPv4r�find_fallback_nic�METADATA_PATTERN�format�
V2_HEADERS�distro�get_tmp_exec_path�_is_iscsi_rootrOr8rN�read_opc_metadata�
instance_data�_crawled_metadata�
METADATA_ROOTr'�metadata_address�
vnics_datarJrh�base64�	b64decode�userdata_raw)r�network_context�fetch_primary_nic�fetch_secondary_nics�fetched_metadata�dataris       r�	_get_datazDataSourceOracle._get_data�s���'�'�)�)�	��5�,�.�.���#�3��'�)�)�'�.�.�q�z�.�J�J�%�#�#��K�1�1�3�3�

�
�
��!%� 3� 3� 5� 5�5��#�{���&��8�9� 
� 
���	�	�0�!2�!J�6J� � � ��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
)9�(F�F��t�%� -� 4� 4�$�,�!5�!
�!
���,�6���"&�k�!2���:��"�:�.���'�
�
��
������Z�(�,�,�[�9�9�I��
@�$*�$4�Y�$?�$?��!�+/�
�+;�+?�+?�%�,�,�D�M�-�(��ts�C'�'C+�.C+c�4�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_uuidrm)rrQs  r�check_instance_idz"DataSourceOracle.check_instance_id�s��
�6�t�7G�H�H�Hrc�Z�tj|j�d����S)Nrk)r	�normalize_pubkey_datarhr8rs r�get_public_ssh_keysz$DataSourceOracle.get_public_ssh_keys�s#���,�T�]�->�->�}�-M�-M�N�N�Nrc�4�|j���S)z)Return whether we are on a iscsi machine.)rPrrs rruzDataSourceOracle._is_iscsi_root�s���*�8�8�:�:�:rc�4�|j���S�N)rP�
render_configrs r�_get_iscsi_configz"DataSourceOracle._get_iscsi_config�s���*�8�8�:�:�:rc��|���r|jSd}|���r|���|_|���st�d��d}|j�dtd��}|s|rA	|�	|��n*#t$rtjtd��YnwxYwt|j��|jS)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!)rVrErur�r6�warningrOr8rN�!_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�C�C�C���
�
�
����A������
����	!��!5�6�6�6��#�#s�&B<�<$C#�"C#Fr�c�.�|j�t�d��dS|s+d|jdvrt�d��dSt��}|r|jn|jdd�}t	|��D�]
\}}|o|dk}|d���}||vrt�d|���H||}t
j|d	��}	|jd
dkrK|rddi}
nd
|d�d|	j	��d�}
|d|t|
gd�}|jd�|����|jd
dkr6td|id|d�}|s|d�d|	j	��g|d<||jd|<��dS)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+�addressr0)r5r+r1�mtu�subnetsr/r)r4F)r�r3�dhcp6�dhcp4�	addressesr2)rJr6r�r�	enumerate�lower�	ipaddress�
ip_networkrE�	prefixlen�MTU�append)rr��interfaces_by_macr{�index�	vnic_dict�
is_primaryr1r5�network�subnet�interface_configs            rr�z2DataSourceOracle._add_network_config_from_opc_imdss5����#��K�K�=�>�>�>��F��	�
�d�.>�q�.A� A� A�
�K�K�9�
�
�
�
�F�1�3�3��)4�N�T�%�%�$�:J�1�2�2�:N�
� )�*� 5� 5�+	K�+	K��E�9�$�3��!��J�#�I�.�4�4�6�6�K��"3�3�3����?������$�[�1�D��*�9�5F�+G�H�H�G��#�I�.�!�3�3���$�f�-�F�F�!)�(��5�K�K��8I�K�K���F�!�&�#.�� &�x�$�$� ��$�X�.�5�5�6F�G�G�G�G��%�i�0�A�5�5��*�K�8�"�'�	$�$� �"��$�[�1�G�G�G�4E�G�G�5�$�[�1�;K��$�[�1�$�7��W+	K�+	Kr)F)r r!r"rMrm�vendordata_purer	�NetworkConfigSource�CMD_LINE�DS�	INITRAMFS�
SYSTEM_CFGrDr�__annotations__rE�dictrIrrVrXr�r�r�rur��propertyr%r��
__classcell__)rTs@rrBrBrs���������
�F��K��O��#�,��#�&��#�-��#�.�	G��E�'�"=�s�"B�C����(*�a�8�8�O�T�8�8�8�
G�
G�
G�
G�
G�<�T�<�<�<�<�%�T�%�%�%�%�.�.�.�`I�D�I�I�I�I�O�O�O�;��;�;�;�;�;�4�;�;�;�;��+$�+$��X�+$�ZLK�LK�T�LK�LK�LK�LK�LK�LK�LK�LKrrBc�Z�tjd��}|�dn|���S)Nzsystem-uuid)r�
read_dmi_datar�)�sys_uuids rrlrlQs+��� ��/�/�H��#�4�4����)9�)9�9rc�@�tjd��}|tkS)Nzchassis-asset-tag)rr��CHASSIS_ASSET_TAG)�	asset_tags rrXrXVs���!�"5�6�6�I��)�)�)rr)�metadata_versionr\�retriesc��tt�||���|dkrtnd|���j���S)Nr[r()r]r^r�)rrprqrr�	_response�json)r�r\r�s   r�_fetchr�[sQ����#�#�,<�4�#�H�H�.��2�2�
�
�����������	rrbrcc��d}	t|d���}n##t$rd}t|d���}YnwxYwd}|r=	t|d���}n*#t$rtjtd��YnwxYwt|||��S)aCFetch 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

    r)rZ)r\r(N�vnicsz+Failed to fetch IMDS network configuration!)r�rr
r�r6r)rcr�rwr{s    rrvrvcs�����B��/�j�A�A�A�
�
���B�B�B����/�j�A�A�A�
�
�
�B�����J��L�	L�� 0�w�?�?�?�J�J���	L�	L�	L��K��J�K�K�K�K�K�	L�����'��
�C�C�Cs��6�6�A�$A7�6A7c�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)rvrX)r)):r#r|r��collectionsr�typingrr�	cloudinitrr�loggingrr	r
�cloudinit.distros.networkingr�
cloudinit.netrr
rr�cloudinit.url_helperrr�	getLoggerr r6rNr�ryrpr�rrr�KlibcNetworkConfigSourcerr@�
DataSourcerB�strrlrrX�intr�r�rv�DEP_FILESYSTEMr�r��argparser��ArgumentParser�parser�
parse_args�print�
json_dumpsr$rr�<module>r�sR�����
�
�
�����"�"�"�"�"�"�"�"�"�"�"�"�"�"�������$�$�$�$�$�$�(�(�(�(�(�(�(�(�(�(�6�6�6�6�6�6�������������3�2�2�2�2�2�2�2��g���!�!������&��8�
� �9�,������
/�
��j��(J�K�K��	!�	!�	!�	!�	!�W�%E�	!�	!�	!�18�]�18�t�18�18�18�18�h\K�\K�\K�\K�\K�w�)�\K�\K�\K�~:�8�C�=�:�:�:�:�
*�T�*�*�*�*�
��S����c��$�����38�D�D�D�4�D�K�D�D�D�D�@��.�0�1���;�;�;��z����O�O�O� �K�
%�X�
$��
=�
=�
=�F�
������	�E����%6�%6�%8�%8�':�':�'<�'<�
�
�	
�	
�������r