HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceVMware.cpython-312.pyc
�

쑛h���>�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
ddlmZmZmZmZmZmZddlmZmZmZddlmZddlmZddlmZmZm Z d	Z!ejDe#�Z$d
Z%dZ&dZ'd
Z(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3ejhejjejlejnhiZ8ejhejlejnhiZ9gd�Z:dZ;d�Z<d�Z=Gd�dej|�Z?d�Z@d �ZAd!�ZBd"�ZCd#�ZDd$�ZEd%�ZFd&�ZGd'�ZHd(�ZId)�ZJd*�ZKd+�ZLd,�ZMd-�ZNd.�ZOd/�ZPd0�ZQd1�ZRe?ej�ffe?ej�ej�ffgZUd2�ZVd3�ZWd>d4�ZXd5�ZYd6eZd7eZfd8�Z[d6eZd7eZfd9�Z\d:�Z]d;�Z^d<�Z_e#d=k(re_�yy)?z�Cloud-Init DataSource for VMware

This module provides a cloud-init datasource for VMware systems and supports
multiple transports types, including:

    * EnvVars
    * GuestInfo
    * IMC (Guest Customization)
�N)�Dict�Set)�
atomic_helper�dmi�net�netinfo�sources�util)�
EventScope�	EventType�userdata_to_events)�loggers)�guestcust_util)�ProcessExecutionError�subp�whichz/sys/class/dmi/id/product_uuidzNo value found�envvar�	guestinfo�imc�redactzcleanup-guestinfo�
VMX_GUESTINFOz---z
local-ipv4z
local-ipv6zwait-on-network�ipv4�ipv6zcloudinit.updates.supportedzcloudinit.updates.enabled)�e1000�e1000e�vlance�vmxnet2�vmxnet3�vrdmaz9
ENV{}=="{}", GOTO="cloudinit_hook"
GOTO="cloudinit_end"
c�\�tjdddkr|Stj|�S)z�
    cache is a wrapper around functools.cache that no-ops when Python
    is <3.9, the version in which functools.cache was introduced.
    N�)��	)�sys�version_info�	functools�cache)�functions �D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMware.pyr'r'ms-��
������f�$������x�(�(�c�R�|r%tjddj|��Sy)Nz{ID_NET_DRIVER}�|)� _EXTRA_HOTPLUG_UDEV_RULES_FORMAT�format�join)�
driver_idss r)�get_extra_hotplug_udev_rulesr1xs+���/�6�6��s�x�x�
�3�
�	
�r*c�
��eZdZdZdZeje�Zeje	�Z
ee�Z
dd�Zdeddf�fd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zed��Zd�Zd�Zed��Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#�xZ$S)�DataSourceVMwareav
    Setting the hostname:
        The hostname is set by way of the metadata key "local-hostname".

    Setting the instance ID:
        The instance ID may be set by way of the metadata key "instance-id".
        However, if this value is absent then the instance ID is read
        from the file /sys/class/dmi/id/product_uuid.

    Configuring the network:
        The network is configured by setting the metadata key "network"
        with a value consistent with Network Config Versions 1 or 2,
        depending on the Linux distro's version of cloud-init:

            Network Config Version 1 - http://bit.ly/cloudinit-net-conf-v1
            Network Config Version 2 - http://bit.ly/cloudinit-net-conf-v2

        For example, CentOS 7's official cloud-init package is version
        0.7.9 and does not support Network Config Version 2.

        imc transport:
            Either Network Config Version 1 or Network Config Version 2 is
            supported which depends on the customization type.
            For LinuxPrep customization, Network config Version 1 data is
            parsed from the customization specification.
            For CloudinitPrep customization, Network config Version 2 data
            is parsed from the customization specification.

        envvar and guestinfo transports:
            Network Config Version 2 data is supported as long as the Linux
            distro's cloud-init package is new enough to parse the data.
            The metadata key "network.encoding" may be used to indicate the
            format of the metadata key "network". Valid encodings are base64
            and gzip+base64.
    �VMwareNc��tjj|||||�i|_d|_d|_d|_t|jdft|jdft|jdfg|_
y)NFT)r	�
DataSource�__init__�cfg�data_access_method�rpctool�
rpctool_fn�DATA_ACCESS_METHOD_ENVVAR�get_envvar_data_fn�DATA_ACCESS_METHOD_GUESTINFO�get_guestinfo_data_fn�DATA_ACCESS_METHOD_IMC�get_imc_data_fn� possible_data_access_method_list)�self�sys_cfg�distro�paths�ud_procs     r)r7zDataSourceVMware.__init__�sw�����#�#�D�'�6�5�'�J����"&���������'��(?�(?��G�
)�4�+E�+E�t�L�
#�T�%9�%9�4�@�1
��-r*�ci_pkl_version�returnc	�x��t�|�|�dD]}t||�r�t||d��t|d�s
t|di�t|d�sCt|dt|j
dft|jdft|jdfg�t|d�stt�|_yy)N)r:r;r8rBFT�extra_hotplug_udev_rules)
�super�	_unpickle�hasattr�setattrr<r=r>r?r@rAr1�DEFAULT_NETWORK_DRIVERSrK)rCrH�attr�	__class__s   �r)rMzDataSourceVMware._unpickle�s����
���.�)�-�	*�D��4��&���d�D�)�	*��t�U�#��D�%��$��t�?�@���2�2��/�/���5��2�2���
,�T�-A�-A�4�H��
�"�t�7�8�,H�'�-�D�)�9r*c�d�tjj|�}|�d|j�d�S)Nz [seed=�])r	r6�__str__r9)rC�roots  r)rUzDataSourceVMware.__str__�s)���!�!�)�)�$�/��!%�t�'>�'>�?�?r*c���d\}}}|jD]-\}}}|rt�s�|�\}}}|s|s|s�&||_n|jstj	d�ytjd|j
��tt|��|_	||_
||_|j�|js|js|jryy)a�
        _get_data loads the metadata, userdata, and vendordata from one of
        the following locations in the given order:

            * envvars
            * guestinfo
            * imc

        Please note when updating this function with support for new data
        transports, the order should match the order in the dscheck_VMware
        function from the file ds-identify.
        �NNNz)failed to find a valid data access methodFzusing data access method %sT)
rB�is_vmware_platformr9�LOG�debug�info�_get_subplatform�process_metadata�load_json_or_yaml�metadata�userdata_raw�vendordata_raw�redact_keys)rC�md�ud�vdr9�get_data_fn�require_vmware_platforms       r)�	_get_datazDataSourceVMware._get_data�s���"&�
��B���
2�
2�	
	�
���#�&�/A�/C��&�=�L�R��R��R�2�*<��'��
	��&�&��I�I�A�B�����.��0E�0E�0G�H�)�):�2�)>�?��
����!���	
�����=�=�D�-�-��1D�1D��r*c�(�t|j�}tjd|�t	||j
|j�tj|j|g�|_|j�|j�y)a(setup(is_new_instance)

        This is called before user-data and vendor-data have been processed.

        Unless the datasource has set mode to 'local', then networking
        per 'fallback' or per 'network_config' will have been written and
        brought up the OS at this point.
        zgot host-info: %sN)�wait_on_networkr`rZr\�advertise_local_ip_addrsr:r;r
�
mergemanydict�init_extra_hotplug_udev_rules�persist_instance_data)rC�is_new_instance�	host_infos   r)�setupzDataSourceVMware.setupsp��$�D�M�M�2�	����$�i�0�	!��D�L�L�$�/�/�J�
�*�*�D�M�M�9�+E�F��
�	
�*�*�,�	
�"�"�$r*c�&�|j|�y)a�activate(cfg, is_new_instance)

        This is called before the init_modules will be called but after
        the user-data and vendor-data have been fully processed.

        The cfg is fully up to date config, it contains a merged view of
           system config, datasource config, user config, vendor config.
        It should be used rather than the sys_cfg passed to __init__.

        is_new_instance is a boolean indicating if this is a new instance.
        N)�advertise_update_events)rCr8rps   r)�activatezDataSourceVMware.activate?s��	
�$�$�S�)r*c���d}|jtk(rt}nD|jtk(rt}n*|jt
k(rt}ntjS|j�d|d��d�S)Nz (r`�))	r9r<�get_guestinfo_envvar_key_namer>�get_guestinfo_key_namer@�get_imc_key_namer	�METADATA_UNKNOWN)rC�get_key_name_fns  r)r]z!DataSourceVMware._get_subplatformOsl�����"�"�&?�?�;�O�
�
$�
$�(D�
D�4�O�
�
$�
$�(>�
>�.�O��+�+�+�
�#�#��J�'�
�	
r*c��|jS�N)r8�rCs r)�get_config_objzDataSourceVMware.get_config_objbs���x�x�r*c���d|jvrtjd�n>tjd�d|jj	�i|jd<|jddS)N�networkzusing metadata network configzusing fallback network config�config)r`rZr[rE�generate_fallback_configrs r)�network_configzDataSourceVMware.network_configes`����
�
�%��I�I�5�6��I�I�5�6��$�+�+�>�>�@�(�D�M�M�)�$��}�}�Y�'��1�1r*c�H�tj|j�}t|j	di��}tjtj|�tj|�g�}t|j||j|j�S)N�updates)�copy�deepcopy�default_update_eventsr
�getr
rmrt�supported_update_eventsr:r;)rCr8�default_events�user_events�enabled_eventss     r)rtz(DataSourceVMware.advertise_update_eventsps���;?�=�=��&�&�<
��9K��G�G�I�r�"�9
���+�+��
�
�k�*��
�
�n�-�
�
��'��(�(���L�L��O�O�	
�	
r*c�J�t|j��}|r||_yyr~)r1�get_network_driversrK)rC�ruless  r)rnz.DataSourceVMware.init_extra_hotplug_udev_rules�s%��,�T�-E�-E�-G�H���,1�D�)�r*c���t}|jr;d|jvr-|jd}|D�cgc]}|jd���}}tj	d|�|Scc}w)Nznetwork-drivers� zgot network drivers %s)rPr`�striprZr\)rC�network_drivers�ss   r)r�z$DataSourceVMware.get_network_drivers�sb��1���=�=�.�$�-�-�?�"�m�m�,=�>�O�6E�E��q�w�w�s�|�E�O�E����)�?�;����Fs�A&c��|jrd|jvr|jdStjt�j	�j�|jd<|jdS)Nzinstance-id)r`r
�load_text_file�PRODUCT_UUID_FILE_PATH�rstrip�lowerrs r)�get_instance_idz DataSourceVMware.get_instance_id�se���=�=�]�d�m�m�;��=�=��/�/���� 6�7�>�>�@�F�F�H�	
�
�
�m�$��}�}�]�+�+r*c��|jrB|jtk(r/t�r%tj	d|j��yy)Nz"Cache fallback is allowed for : %sTF)r9r@rYrZr[r]rs r)�check_if_fallback_is_allowedz-DataSourceVMware.check_if_fallback_is_allowed�sB���#�#��'�'�+A�A�"�$��I�I�4�d�6K�6K�6M�
��r*c�x�dD]4}||jvs�tj|j|�cSgS)N)zpublic-keys-data�public_keys_datazpublic-keys�public_keys)r`r	�normalize_pubkey_data)rC�key_names  r)�get_public_ssh_keysz$DataSourceVMware.get_public_ssh_keys�sD��
�	N�H��4�=�=�(��4�4�T�]�]�8�5L�M�M�	N��	r*c��d}t|jvr|jt}n%t|jvr|jt}|jtk(r"t||j|j�yyr~)�REDACTr`�CLEANUP_GUESTINFOr9r>�guestinfo_redact_keysr:r;)rC�keys_to_redacts  r)rczDataSourceVMware.redact_keys�sh�����T�]�]�"�!�]�]�6�2�N�
�$�-�-�
/�!�]�]�+<�=�N��"�"�&B�B�!�����d�o�o�
�Cr*c��d\}}}tjjtd�r!t	d�}t	d�}t	d�}|||fS)z<
        check to see if there is data via env vars
        rX�r`�userdata�
vendordata)�os�environr�r�guestinfo_envvar)rCrdrerfs    r)r=z#DataSourceVMware.get_envvar_data_fn�sK��&�
��B��
�:�:�>�>�-��,�!�*�-�B�!�*�-�B�!�,�/�B��B��|�r*c�8�td�}td�}|r(||_t|_tjd|�|r*|s||_t|_tjd|�|jstjd�yd�}	||j|j�S#t$r�}tjtd|j|�|r|j|k(rYd	}~y|stjd
�Yd	}~ytjd�||_t|_	||j|j�cYd	}~S#t$r-tjtd|j|�YYd	}~ywxYwd	}~wwxYw)zK
        check to see if there is data via the guestinfo transport
        �vmtoolsdzvmware-rpctoolzdiscovered vmware-rpctool: %szdiscovered vmtoolsd: %szno rpctool discoveredrXc��d\}}}tjd|�td||�}td||�}td||�}|||fS)NrXzquery guestinfo with %sr`r�r�)rZr\r)r:r;rdrerfs     r)�query_guestinfoz?DataSourceVMware.get_guestinfo_data_fn.<locals>.query_guestinfo�sR��)�J�B��B��H�H�.��8��:�w�
�;�B��:�w�
�;�B��<��*�=�B��r�2�:�r*z%Failed to query guestinfo with %s: %sNz$vmtoolsd fallback option not presentzfallback to vmtoolsd)rr:�exec_vmware_rpctoolr;rZr[�
exec_vmtoolsd�	Exceptionr
�logexcr\)rCr��vmware_rpctoolr��errors     r)r?z&DataSourceVMware.get_guestinfo_data_fn�sP��
��$���/�0���)�D�L�1�D�O��I�I�5�~�F��"�'���"/����I�I�/��:��|�|��I�I�-�.�%�	�&	*�#�4�<�<����A�A���"	*��K�K��7�����	
��D�L�L�H�4�)�����?�@�)��H�H�+�,�#�D�L�+�D�O�

*�&�t�|�|�T�_�_�E�E���
*�����;��L�L��	�*�
*��5"	*�sH�B0�0	F�97F�5F�'F�9E�F�/F�
F�F�F�Fc��d\}}}tj|j�}tj|j�}|s|st
j
d�|||fStj�s|||fStj|j�}|�|||fStjj|�}tj|�}tj|�\}	}
|	rr|rpt
j
d�tj|jj |jj#d�|||j$�\}}}|_nH|
r1|r/t
j
d�tj(|�\}}}nt
j
d�t+j,|�|||fS)zN
        check to see if there is data via vmware guest customization
        rXz-Customization for VMware platform is disabledz3Getting data via VMware customization configuration�scriptszFGetting data via VMware raw cloudinit data customization configurationz1No allowed customization configuration data found)r�is_vmware_cust_enabledrD�is_raw_data_cust_enabled�ds_cfgrZr[�is_cust_plugin_available�get_cust_cfg_filer��path�dirname�parse_cust_cfg�get_cust_cfg_type�get_data_from_imc_cust_cfgrF�	cloud_dir�	get_cpathrEr8�#get_data_from_imc_raw_data_cust_cfgr
�del_dir)rCrdrerf�allow_vmware_cust�allow_raw_data_cust�
cust_cfg_file�cust_cfg_dir�cust_cfg�is_vmware_cust_cfg�is_raw_data_cust_cfgs           r)rAz DataSourceVMware.get_imc_data_fns���&�
��B��+�A�A�$�,�,�O��,�E�E��K�K�
��!�)<��I�I�E�F���B�<���6�6�8���B�<��'�8�8����E�
�� ���B�<���w�w���}�5��!�0�0��?��
�,�,�X�6�	
�� ��"3��I�I�K�L�%3�%N�%N��
�
�$�$��
�
�$�$�Y�/������&�"�R��R���"�&9��I�I�.�
�*�M�M���L�R��R�
�I�I�I�J�	
���\�"��B��|�r*r~)%�__name__�
__module__�__qualname__�__doc__�dsnamer�r��SUPPORTED_UPDATE_EVENTSr��DEFAULT_UPDATE_EVENTSr�r1rPrKr7�intrMrUrirrrur]r��propertyr�rtrnr'r�r�r�r�rcr=r?rA�
__classcell__)rRs@r)r3r3�s����"�H�F�+�d�m�m�,C�D��)�D�M�M�*?�@��;�� ��
�*�����<@�7�r%�@*� 
�&��2��2�
�(2�
�
��
�,�
�	��
�J*�X7r*r3c��tjd�}|�tjd�yd|j	�vrtjd�yy)Nzsystem-product-namezNo system-product-name foundF�vmwarezNot a VMware platformT)r�
read_dmi_datarZr[r�)�system_types r)rYrYWsM���#�#�$9�:�K����	�	�0�1��	��*�*�,�	,��	�	�)�*��r*c�x�tjd||�d}|dvr@tjd||�tjt	j
|��}nI|dvr-tjd||�t	j
|�}ntjd|�|}tj|�S)z�
    decode returns the decoded string value of data
    key is a string used to identify the data being decoded in log messages
    z'Getting encoded data for key=%s, enc=%sN)zgzip+base64zgz+b64zDecoding %s format %s)�base64�b64zPlain-text data %s)rZr[r
�decomp_gzipr�b64d�
decode_binary)�key�enc_type�data�raw_datas    r)�decoder�bs���
�I�I�7��h�G��H��,�,��	�	�)�8�S�9��#�#�M�$6�$6�t�$<�=��	�&�	&��	�	�)�8�S�9� �%�%�d�+���	�	�&��,������h�'�'r*c�h�tj|�}|j�}|r	|tk(ry|S)a
    get_none_if_empty_val returns None if the provided value, once stripped
    of its trailing whitespace, is empty or equal to GUESTINFO_EMPTY_YAML_VAL.

    The return value is always a string, regardless of whether the input is
    a bytes class or a string.
    N)r
r�r��GUESTINFO_EMPTY_YAML_VAL)�vals r)�get_none_if_empty_valr�ws2���
�
�S�
!�C�

�*�*�,�C��S�4�4���Jr*c��|r|r|sy|jt�}|r(tt|||�tj	d|�|jt
�}|r)tt
|||�tj	d|�yy)z�
    advertise_local_ip_addrs gets the local IP address information from
    the provided host_info map and sets the addresses in the guestinfo
    namespace
    Nz-advertised local ipv4 address %s in guestinfoz-advertised local ipv6 address %s in guestinfo)r��
LOCAL_IPV4�guestinfo_set_valuerZr\�
LOCAL_IPV6)rqr:r;�
local_ipv4�
local_ipv6s     r)rlrl�sq���G�:�����z�*�J���J�
�G�Z�H����@�*�M����z�*�J���J�
�G�Z�H����@�*�M�r*c���|r|syd�}||�}|r(tt|||�tjd|�||�}|r(tt|||�tjd|�||fS)a�
    advertise_update_events publishes the types of supported and
    enabled events to guestinfo.

    The string returned from this method adheres to the following
    format:

        SCOPE=TYPE[;TYPE][,SCOPE=TYPE[;TYPE]]

    For example:

        * network=boot;hotplug
        * network=boot-new-instance

    The only supported event scope at the moment is network, but there
    may be more scopes in the future, and this format will support them.
    )NNc	���g}|j�D]G\}}td�|D��}|jdj|dj	|����Idj	|�S)Nc3�2K�|]}t|����y�wr~)�str)�.0�
event_types  r)�	<genexpr>zEadvertise_update_events.<locals>.get_events_string.<locals>.<genexpr>�s����&�$.��J��&�s�z{}={}�;�,)�items�sorted�appendr.r/)�events�event_scopes_and_types_list�event_scope�event_types�event_types_lists     r)�get_events_stringz2advertise_update_events.<locals>.get_events_string�st��&(�#�(.����	�$�K��%�&�2=�&� ��
(�.�.����{�C�H�H�5E�,F�G�
�		��x�x�3�4�4r*z3advertised supported update events in guestinfo: %sz1advertised enabled update events in guestinfo: %s)r��&SUPPORTED_UPDATE_EVENTS_GUEST_INFO_KEYrZr\�$ENABLED_UPDATE_EVENTS_GUEST_INFO_KEY)r��enabled_update_eventsr:r;r�supported_events_string�enabled_events_strings       r)rtrt�s���(�*��	5�0�0G�H����2�#���		
�	���A�#�	
�
.�.C�D����0�!���		
�	���?�!�	
�
#�$9�9�9r*c�N�t|�}|r|Stjd|�y)z�
    handle_returned_guestinfo_val returns the provided value if it is
    not empty or set to GUESTINFO_EMPTY_YAML_VAL, otherwise None is
    returned
    �No value found for key %sN)r�rZr[)r�r�s  r)�handle_returned_guestinfo_valr�s(�� ��
$�C�
��
��I�I�)�3�/�r*c��y)Nzvmware-tools��r�s r)rzrz�s��r*c��d|zS)Nz
guestinfo.rrs r)ryry�s
���#��r*c�\�dt|�zj�jddd�S)Nzvmx.�.�_���)ry�upper�replacers r)rxrx�s+���+�C�0�0�7�7�9�A�A�#�s�B�O�Or*c�f�t|�}|syt|dz�}tt|�||�S)N�	.encoding)�guestinfo_envvar_get_valuer�rx)r�r�r�s   r)r�r��s6��
$�S�
)�C���)�#��*;�<�H��/��4�h��D�Dr*c�l�t|�}t|tjj	|d��S)Nr�)rxrr�r�r�)r��env_keys  r)rr�s(��+�C�0�G�(��b�j�j�n�n�W�b�.I�J�Jr*c�*�t||g�\}}||fSr~�r�r:�arg�stdout�stderrs    r)r�r�s ���W�c�N�+��V�V��F��r*c�,�t|d|g�\}}||fS)Nz--cmdr r!s    r)r�r�	s#���W�g�s�3�4��V�V��F��r*c�n�t|||�}|syt|dz||�}tt|�||�S)zj
    guestinfo returns the guestinfo value for the provided key, decoding
    the value when required
    Nr)�guestinfo_get_valuer�ry)r�r:r;r�r�s     r)rrs@��
�c�7�J�
7�C���"�3��#4�g�z�J�H��(��-�x��=�=r*c��tjd|�	||dt|�z�\}}|tk(rtjd|�n|stj	d|�t||�S#t$rR}|jtk(rtjd|�ntjtd||�|�Yd}~yd}~wt$r#}tjtd||�|�d}~wwxYw)z:
    Returns a guestinfo value for the specified key.
    z"Getting guestinfo value for key %sz	info-get rz(Failed to get guestinfo value for key %sz,Failed to get guestinfo value for key %s: %sNzCUnexpected error while trying to get guestinfo value for key %s: %s)rZr[ry�NOVALr�rrr$r
r�r�)r�r:r;r#r$r�s      r)r'r's����I�I�2�C�8�!�%��[�#9�#�#>�>�
�����U�?��I�I�1�3�7���I�I�@�#�F�,�S�&�9�9�� ���<�<�5� ��I�I�1�3�7�

�K�K��>���	
��K�
8�,��������
-���	
�����s%�AA4�4	C9�=AC
�
C9�C4�4C9c�$�|dk(rd}tjd||�	||dt|��d|���y#t$r'}t	j
td|||�Yd}~yd}~wt$rt	j
td||�YywxYw)	z|
    Sets a guestinfo value for the specified key. Set value to an empty string
    to clear an existing guestinfo key.
    r�r�z$Setting guestinfo key=%s to value=%sz	info-set Tz.Failed to set guestinfo key=%s to value=%s: %sNzAUnexpected error while trying to set guestinfo key=%s to value=%s)rZr[ryrr
r�r�)r��valuer:r;r�s     r)r�r�Fs���
��{����I�I�4�c�5�A�
���)?��)D�e�L�	
��� �

�	
����<����	
�	
� ���
�����
+���	
��
�s�9�	B�A$�$(B�Bc�Z�|syt|�ttfvr|g}|D]�}t|�}tjd|�t
|t||�stjd|�tjd|�t
|dzd||�r�ttjd|���y)z�
    guestinfo_redact_keys redacts guestinfo of all of the keys in the given
    list. each key will have its value set to "---". Since the value is valid
    YAML, cloud-init can still read it if it tries.
    Nzclearing %szfailed to clear %szclearing %s.encodingrr�zfailed to clear %s.encoding)	�type�list�tupleryrZr\r�r�r�)�keysr:r;r�r�s     r)r�r�qs������D�z�$���&��v���	?��)�#�.�������)�"��)�7�J�
�
�I�I�*�H�5����'��2�"�3��#4�b�'�:�N��I�I�3�X�>�	?r*c���|siSt|t�r|S	tj|�S#tj
tf$rtj|�cYSwxYw)z�
    load first attempts to unmarshal the provided data as JSON, and if
    that fails then attempts to unmarshal the data as YAML. If data is
    None then a new dictionary is returned.
    )�
isinstance�dictr
�	load_json�json�JSONDecodeError�	TypeError�	load_yaml)r�s r)r_r_�sX����	��$�����$��~�~�d�#�#��� � �)�,�$��~�~�d�#�#�$�s�-�.A�Ac��|siSd}d|vr|d}|d=d}d|vr|d}|d=|r�t|tjj�r-tjd�dt
j|�i}n0tjd|�td||�}dt|�i}tjd|�||d<|S)	z_
    process_metadata processes metadata and loads the optional network
    configuration.
    Nr�znetwork.encodingz#network data copied to 'config' keyr�znetwork data to be decoded %szmetadata.networkznetwork data %s)
r2�collections�abc�MappingrZr[r�r�r�r_)r�r��network_enc�dec_nets    r)r^r^�s���
��	��G��D���y�/����O��K��T�!��-�.���#�$���g�{���6�6�7��I�I�;�<�����w�!7�8�G��I�I�5�w�?��/��g�F�G��+�G�4��G�	�	�	�#�W�-�!��Y���Kr*c�6�tj|t�S)zK
    Return a list of data sources that match this set of dependencies
    )r	�list_from_depends�datasources)�dependss r)�get_datasource_listrC�s���$�$�W�k�:�:r*c��d}d}tj�}|dD]}|ddk(s�|d}n|dD]}|ddk(s�|d}nd}d}tj�}||vrK||d}t|�dkDrtjd	||�nt|�dk(rd
|dvr|dd
}||vrK||d}t|�dkDrtjd||�nt|�dk(rd
|dvr|dd
}|�C|�A|D]<}||dD]/}	|	d
|k(s�t||d�dk(s�!||ddd
}�<�>|�C|�A|D]<}||dD]/}	|	d
|k(s�t||d�dk(s�!||ddd
}�<�>||fS)
aI
    Returns the default IPv4 and IPv6 addresses based on the device(s) used for
    the default route. Please note that None may be returned for either address
    family if that family has no default route or if there are multiple
    addresses associated with the device used by the default route for a given
    address.
    Nr�destination�0.0.0.0�ifacerz::/0�z,device %s has more than one ipv4 address: %s�iprz,device %s has more than one ipv6 address: %s)r�
route_info�netdev_info�lenrZr[)
�ipv4_if�ipv6_if�routes�routerr�netdev�addrs�dev_name�addrs
          r)�get_default_ip_addrsrU�s2���G��G�
�
�
�
!�F���������9�,��G�n�G�����������6�)��G�n�G����D��D�
�
 �
 �
"�F��&���w���'���u�:��>��I�I�>���
���Z�1�_���q��!1���8�D�>�D��&���w���'���u�:��>��I�I�>���
���Z�1�_���q��!1���8�D�>�D�
��D�L��	�H��x�(��0�
����:��%�#�f�X�.>�v�.F�*G�1�*L�!�(�+�F�3�A�6�t�<�D��
�	��|��(��	�H��x�(��0�
����:��%�#�f�X�.>�v�.F�*G�1�*L�!�(�+�F�3�A�6�t�<�D��
�	���:�r*c�&�|j�}|r|dk(rtj�}	tj|ddtj
dtj�}|D]}|ds�	|d}|S|S#tj$rY|SwxYw)zoGet fully qualified domain name from name.
    An empty argument is interpreted as meaning the local host.
    rFNrr")r�r
�get_hostname�socket�getaddrinfo�
SOCK_DGRAM�AI_CANONNAMEr�)�namerRrTs   r)�getfqdnr]
s����:�:�<�D��4�9�$�� � �"��
��"�"��$��6�,�,�a��1D�1D�
���	�D��A�w��A�w����K�		��K���<�<�
���K�
�s�6A9�9B�Bc��tjtj|�}|xr)|jxs|j
xs|jS)zn
    Returns false if the address is loopback, link local or unspecified;
    otherwise true is returned.
    )r�maybe_get_address�	ipaddress�
ip_address�
is_link_local�is_loopback�is_unspecified)r�rTs  r)�is_valid_ip_addrre!sM��
� � ��!5�!5�s�;�D������E�d�.�.�E�$�2E�2E��r*rTrIc��|jd�siS|jd�|jd�|jd�d�S)a�
    Takes a cloudinit.netinfo formatted address and converts to netifaces
    format, since this module was originally written with netifaces as the
    network introspection module.
    netifaces ipv4 format:
    {
      "broadcast": "10.15.255.255",
      "netmask": "255.240.0.0",
      "addr": "10.0.1.4"
    }
    cloudinit.netinfo ipv4 format:
    {
      "ip": "10.0.1.4",
      "mask": "255.240.0.0",
      "bcast": "10.15.255.255",
      "scope": "global",
    }
    rI�bcast�mask)�	broadcast�netmaskrT)r�)rTs r)� convert_to_netifaces_ipv4_formatrk,sA��&�8�8�D�>��	��X�X�g�&��8�8�F�#�������r*c���|jd�siStj|jd��}|j�d|jj
��t
|j�d�S)a�
    Takes a cloudinit.netinfo formatted address and converts to netifaces
    format, since this module was originally written with netifaces as the
    network introspection module.
    netifaces ipv6 format:
    {
      "netmask": "ffff:ffff:ffff:ffff::/64",
      "addr": "2001:db8:abcd:1234::1"
    }
    cloudinit.netinfo ipv6 format:
    {
      "ip": "2001:db8:abcd:1234::1/64",
      "scope6": "global",
    }
    rI�/)rjrT)r�r`�
IPv6Interfacerjr��	prefixlenr�rI)rTrs  r)� convert_to_netifaces_ipv6_formatrpHs^�� �8�8�D�>��	��"�"�4�8�8�D�>�2�D��l�l�^�1�T�\�\�%;�%;�$<�=��D�G�G���r*c�V�ddtj�tj�tj�d�ii}ttj��}|r||d<||d<||d<t�\}}|r	||t<|r	||t<|ddd}|ddd}|ddd	}tj�}|D�]\}g}	g}
||d
D]}|	jt|���||dD]}|
jt|���||jd�}|d
k(r�p|rm|	s|
ri|}
i}|	r.g}|	D]"}t|d�s�|j|��$||d
<|
r.g}|
D]"}t|d�s�|j|��$||d<|||
<|	r<|	D]7}|d}
t|
�s�tj |�}|d=|r||d<|||
<�9|
s��!|
D]7}|d}
t|
�s�tj |�}|d=|r||d<|||
<�9��_|S)zP
    Returns host information such as the host name and network interfaces.
    r��
interfaces)�by-mac�by-ipv4�by-ipv6�hostnamezlocal-hostname�local_hostnamersrtrurr�hwaddrz00:00:00:00:00:00rT�mac)r:�OrderedDictr]r
rWrUr�r�rrKrrkrpr�rer�r�)rqrv�default_ipv4�default_ipv6�by_mac�by_ipv4�by_ipv6�ifacesrS�af_inet4�af_inet6rTryr�r��
af_inet4_vals�ip_info�
af_inet6_valss                  r)�
get_host_infor�as���
	��%�1�1�3�&�2�2�4�&�2�2�4��
��I��t�(�(�*�+�H�� (�	�*��&.�	�"�#�&.�	�"�#�!5�!7��L�,�� ,�	�*��� ,�	�*��
�y�
!�,�
/��
9�F��	�"�<�0��;�G��	�"�<�0��;�G�
�
 �
 �
"�F��5#�������8�$�V�,�	D�D��O�O�<�T�B�C�	D��8�$�V�,�	D�D��O�O�<�T�B�C�	D��X��"�"�8�,���%�%���H���C��C�� "�
�'�2�G�+�G�F�O�<� �!�(�(��1�2�,��F��� "�
�'�2�G�+�G�F�O�<� �!�(�(��1�2�,��F���F�3�K��#�
#���f�o��'��,���m�m�G�,����K��!$�C��J�"����
#��#�
#���f�o��'��,���m�m�G�,����K��!$�C��J�"����
#�[5#�n�r*c���d}d}t|vr{|t}t|vr1|t}t|t�r|}nt	j
|�}t|vr1|t}t|t�r|}nt	j
|�}d\}}}|��t�}|jd�xsi}	|	jd�xsi}
|
jd�xsi}|
jd�xsi}|r|rt|�dkDnd}|sd}|r|rt|�dkDnd}|sd}|�.tjd||||�tjd	�|���tjd
�|S)NF)NFFr�rrrtrurz<waiting on network: wait4=%s, ready4=%s, wait6=%s, ready6=%srHzwaiting on network complete)�WAIT_ON_NETWORK�WAIT_ON_NETWORK_IPV4r2�boolr
�translate_bool�WAIT_ON_NETWORK_IPV6r�r�rLrZr[�time�sleep)
r`�wait_on_ipv4�wait_on_ipv6rk�wait_on_ipv4_val�wait_on_ipv6_valrq�
ipv4_ready�
ipv6_readyr�rrr~rs
             r)rkrk�sv���L��L��(�"�"�?�3���?�2�.�/C�D���*�D�1�/��#�2�2�3C�D���?�2�.�/C�D���*�D�1�/��#�2�2�3C�D��);�%�I�z�:�
�
�"�O�	��-�-�	�*�0�b���[�[��.�4�"�
��.�.��+�1�r���.�.��+�1�r���-4��W���)�%�J�� �	��-4��W���)�%�J�� �	����I�I�N�����
�
�J�J�q�M�;�
�>�I�I�+�,��r*c��	tj�ttdt
diddddiii}t
|�}tj||g�}ttj|��y#t$rY�fwxYw)z7
    Executed when this file is used as a program.
    TFr�r��dhcpN)r�setup_basic_loggingr�r�r�r�rkr
rm�printr�
json_dumps)r`rqs  r)�mainr��s���
��#�#�%�	� �$� �%�
�	�H�v�t�n�-��H� ��)�I��!�!�8�Y�"7�8�H�	�-�
"�
"�8�
,�-���
��
�s�A1�1	A=�<A=�__main__)r�)`r�r:r�r&r`r5�loggingr�rXr$r��typingrr�	cloudinitrrrrr	r
�cloudinit.eventrrr
�
cloudinit.logr�$cloudinit.sources.helpers.vmware.imcr�cloudinit.subprrrr��	getLoggerr�rZr)r<r>r@r�r�rr�r�r�r�r�r�rr	�NETWORK�BOOT�BOOT_NEW_INSTANCE�HOTPLUGr�r�rPr-r'r1r6r3rYr�r�rlrtrrzryrxr�rr�r�rr'r�r�r_r^�DEP_FILESYSTEM�DEP_NETWORKrArCrUr]rer3rkrpr�rkr�rr*r)�<module>r�s8���������	�
�
���E�E�E�E�!�?�=�=�9���g����!����%��*����	��'���
� ��
�
�
�
�#������)F�&�'B�$��������#�#�����������#�#������� ��$� �)��T�w�)�)�T�n�(�*�$N�,<:�~
���P�E�K�
�
�
	>�)�X(�V?�,$�"�H��.�.�0�1���.�.��0C�0C�D�E���;�?�D�.��4��D��8�4��D��2U�p5�p.�(�z���F�r*