name : DataSourceAzure.cpython-39.pyc
a

'�Dg	.�@s�UddlZddlZddlZddlZddlZddlZddlZddlmm	Z
ddlmZddl
mZddlmZmZmZddlmZmZmZmZddlZddlmZmZmZmZmZmZddlm Z m!Z!ddl"m#Z#dd	l$m%Z%m&Z&m'Z'dd
l(m)Z)m*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1dd
l2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAddlBmCZCz2ddlDZDejEeDjDdejFdd���d�ZGeeHd<WnLeIeJf�y�zddlKZLeLjMjNjMZGWneI�y�dd�ZGYn0Yn0e�OeP�ZQdZRddiZSdZTdZUdZVdZWGdd�de�ZXdZYeeZeHd <gd!�Z[d"d#�Z\d$d%�Z]eZeZeeZd&�d'd(�Z^eZeZd)�d*d+�Z_e9eeZd,�d-d.��Z`e9eZeeZd)�d/d0��ZadyeZd,�d1d2�Zbd3d4�Zcd5d6�Zdd7d8�ZeeeZd,�d9d:�Zfe�g��rd;ZUefd<�Zhehdu�reQ�id=�d>ehZTn
eQ�id?�dZYeVd@eTidAdAdB�Zjd@dCdDgdAdE�ieUdFdG�gdH�ZkdIeRgZldJZmdKZnGdLdM�dMejo�ZpdNdO�ZqdPdQ�ZrdRdS�ZsdTdU�ZtdVdW�ZudzdXdY�Zve9dZd[��Zwe9d\d]��Zxe9eTd^d^feZeZeyeyd_�d`da��Zze9d{dbdc��Z{e9ddde��Z|dfdg�Z}e9dhdi��Z~e9eYfdjdk��Ze9dldm��Z�e9dndo��Z�e9e�eye�dp�dqdr��Z�e9e�d,�dsdt��Z�e9d|dudv��Z�epZ�epej�ffgZ�dwdx�Z�dS)}�N)�Enum)�Path)�	monotonic�sleep�time)�Any�Dict�List�Optional)�net�performance�sources�ssh_util�subp�util)�
EventScope�	EventType)�
device_driver)�NoDHCPLeaseError�NoDHCPLeaseInterfaceError�NoDHCPLeaseMissingDhclientError)�EphemeralDHCPv4�EphemeralIPv4Network)�events)�errors�identity�imds�kvp)�netlink)
�DEFAULT_WIRESERVER_ENDPOINT�NonAzureDataSource�	OvfEnvXml�azure_ds_reporter�azure_ds_telemetry_reporter�build_minimal_ovf�dhcp_log_cb�get_boot_telemetry�get_metadata_from_fabric�get_system_info�report_diagnostic_event�report_dmesg_to_kvp�report_failure_to_fabric)�UrlErrorz$6$�)Zstrlen)Zsalt�
blowfish_hashcCstd��dS)z�Raise when called so that importing this module doesn't throw
            ImportError when ds_detect() returns false. In this case, crypt
            and passlib are not needed.
            z/crypt and passlib not found, missing dependencyN)�ImportError)�_�r1�E/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceAzure.pyr.@s��Azure�instance-idziid-AZURE-NODEz/dev/disk/cloud/azure_resourceZext4z/var/lib/waagentz/dev/sr0c@s eZdZdZdZdZdZdZdS)�PPSType�NoneZPreprovisionedOSDiskZRunningZSavableZUnknownN)�__name__�
__module__�__qualname__�NONE�OS_DISK�RUNNING�SAVABLE�UNKNOWNr1r1r1r2r5Ws
r5z/sys/firmware/acpi/tables/OEM0�PLATFORM_ENTROPY_SOURCE)z"/etc/netplan/90-hotplug-azure.yamlz /usr/local/sbin/ephemeral_eth.shz+/etc/udev/rules.d/10-net-device-added.rulesz#/run/network/interfaces.ephemeral.dcCs�|��D]r}t�d|�r|��}t|�dkr|d�d�}t|�dkr|ddkr|d�|�r|d�d�}|dSqd	S)
z�
    dev.storvsc.1.%pnpinfo:
        classid=32412632-86cb-44a2-9b5c-50d1417354f5
        deviceid=00000000-0001-8899-0000-000000000000
    Zpnpinfo���=r�deviceid��.N)�
splitlines�re�search�split�len�
startswith)�
sysctl_outrC�line�fields�columns�compsr1r1r2�"find_storvscid_from_sysctl_pnpinfoks
�
��rQcCs2|��D]$}t�||�r|��}|dSqdS)z�
    scbus0 on ata0 bus 0
    scbus1 on ata1 bus 0
    scbus2 on blkvsc0 bus 0
    scbus3 on blkvsc1 bus 0
    scbus4 on storvsc2 bus 0
    scbus5 on storvsc3 bus 0
    scbus-1 on xpt0 bus 0
    rN)rFrGrHrI)�camcontrol_outZdisk_drvrM�itemsr1r1r2�find_busdev_from_disk�s
rT)rR�busdev�returncCsN|��D]@}t�||�r|�d�}t|�dkr|d�d�}|dSqdS)z�
    <Msft Virtual CD/ROM 1.0>          at scbus1 target 0 lun 0 (cd0,pass0)
    <Msft Virtual Disk 1.0>            at scbus2 target 0 lun 0 (da0,pass1)
    <Msft Virtual Disk 1.0>            at scbus3 target 1 lun 0 (da1,pass2)
    �(rArD�,rN)rFrGrHrIrJ)rRrUrMrSZdev_passr1r1r2�find_dev_from_busdev�s
rY)�macrVc
CsZt|�dkrRd�|dd�|dd�|dd�|dd�|dd�|dd�g�}|��S)	z1Normalize mac address with colons and lower-case.��:rrA����
)rJ�join�lower�rZr1r1r2�normalize_mac_address�s
>�rd�rVcCsdd�t��D�S)z-Get Hyper-V NICs as normalized MAC addresses.cSs$g|]}|ddkrt|d��qS)rA�	hv_netvscrD�rd)�.0�nr1r1r2�
<listcomp>�s�z1get_hv_netvsc_macs_normalized.<locals>.<listcomp>)r�get_interfacesr1r1r1r2�get_hv_netvsc_macs_normalized�s�rlcsf�fdd�t��D�}d|vr"dSt|�dkrLtd�|ftjd�|dStd�|ftjd�d	S)
z0Determine the device driver to match on, if any.cs$g|]}�t|d�kr|d�qS)rDrArg�rh�ircr1r2rj�s�z3determine_device_driver_for_mac.<locals>.<listcomp>rfrDz4Assuming driver for interface with mac=%s drivers=%r�Zlogger_funcrz=Unable to specify driver for interface with mac=%s drivers=%rN)rrkrJr)�LOG�debug�warning)rZZdriversr1rcr2�determine_device_driver_for_mac�s(
�����rsc	Cs>zt�|�jWStjy8t�dd�|��|YS0dS)NzFailed to execute: %s� )r�stdout�ProcessExecutionErrorrprqra)�cmd�fail_retr1r1r2�execute_or_debug�s
rycCstddgdd�S)NZsysctlzdev.storvsc�)rx�ryr1r1r1r2�get_dev_storvsc_sysctl�sr|cCstgd��S)N)�
camcontrol�devlistz-br{r1r1r1r2�get_camcontrol_dev_bus�srcCstddg�S)Nr}r~r{r1r1r1r2�get_camcontrol_dev�sr�cCs�d}|dkrd}|d}dt|�}d�||�}t�}t||�}|sRt�d�dSt�}t�}d�|�}t||�}	|	r�t	||	�}
|
dur�t�d	�dS|
Sd
�|�}t||�}	|	r�t	||	�}
|
dur�t�d	�dS|
SdS)NZ00000000rDZ00000001rAZ000z{0}-{1}z#Fail to find storvsc id from sysctlz	blkvsc{0}zFail to find /dev/daXz
storvsc{0})
�str�formatr|rQrprqrr�rTrY)Zport_idZg0Zg1Zg0g1rLZ	storvscidZcamcontrol_b_outrRZblkvscZscbusxZdevnameZstorvscr1r1r2�get_resource_disk_on_freebsd�s<









r�zfreebsd-ufsrDzresource disk is not None�/dev/zresource disk is NoneZ
ephemeral0T)�data_dir�disk_aliases�apply_network_config�&apply_network_config_for_secondary_ipsZgpt�d)Z
table_typeZlayoutZ	overwritezephemeral0.1)Z
filesystemZdevice)�
disk_setupZfs_setupZ
datasourceZnever_destroy_ntfsZREDACTEDcseZdZdZejejejhiZ	dZ
ejZ
dZdd�Zedd��fdd	�Zd
d�Zdd
�Zeeed�dd��Zeddddd�eeeeeed�dd��Zedd�dd��Zed�dd�Zdd�dd�Zedd��Zeeed �d!d"��Z du�fd$d%�	Z!ed&d'��Z"ed(d)��Z#d*d+�Z$d,d-�Z%ee&ed�d.d/��Z'e(e&ed0�d1d2�Z)e&ed�d3d4�Z*d5d6�Z+d7d8�Z,dvd9d:�Z-ed;d<��Z.edweee/d?�d@dA��Z0edBdC��Z1edddD�eeddE�dFdG��Z2edHdI��Z3ee4j4d�dJdK��Z5edLdM��Z6edd�dNdO��Z7edPdQ��Z8edRdS��Z9ee:d�dTdU��Z;edxe<j=eedV�dWdX��Z>eddY�ee&eee&edZ�d[d\��Z?e(eed0�d]d^�Z@e(e(eAd_�d`da�ZBedbdc��ZCee(e(ee&edd�dedf��ZDdgdh�ZEedidj��ZFeGdkdl��ZHedmdn��ZIeGdodp��ZJeGdqdr��ZKee(ed0�dsdt��ZL�ZMS)y�DataSourceAzurer3FrDcCs�tj�||||�tj�|jd�|_i|_d|_t	�
t	�|ti�t
g�|_d|_d|_d|_d|_d|_t|_tj�|jdd�|_dS)NZazureF�data�reported_ready)r
�
DataSource�__init__�os�pathra�seed_dir�cfg�seedr�
mergemanydictZget_cfg_by_path�DS_CFG_PATH�BUILTIN_DS_CONFIG�ds_cfg�_iso_dev�_network_config�_ephemeral_dhcp_ctx�_route_configured_for_imds� _route_configured_for_wireserverr�_wireserver_endpoint�	cloud_dir�_reported_ready_marker_file)�self�sys_cfg�distro�pathsr1r1r2r�Ds ��zDataSourceAzure.__init__N)�ci_pkl_versionrVcsDt��|�d|_d|_d|_d|_t|_tj	�
|jjdd�|_
dS)NFr�r�)�super�	_unpickler�r�r�r�rr�r�r�rar�r�r�)r�r���	__class__r1r2r�Vs
�zDataSourceAzure._unpicklecCstj�|�}d||jfS)Nz%s [seed=%s])r
r��__str__r�)r��rootr1r1r2r�bszDataSourceAzure.__str__cCsH|jdurd}n*|j�d�r"d}n|j��dkr6d}nd}d||jfS)z/Return the subplatform metadata source details.N�unknownz/devzconfig-diskrzseed-dirz%s (%s))r�rKrb)r�Zsubplatform_typer1r1r2�_get_subplatformfs
z DataSourceAzure._get_subplatform)�ephipv4rVcCs<|js
dSdd�|jD�}d|v|_|j|v|_|jp:|jS)NFcSsg|]}|d�d�d�qS)r�/)rI)rh�rr1r1r2rjx�z5DataSourceAzure._check_if_primary.<locals>.<listcomp>z169.254.169.254)�
static_routesr�r�r�)r�r�Zrouted_networksr1r1r2�_check_if_primaryrs
��z!DataSourceAzure._check_if_primaryT�)�iface�report_failure_if_not_primary�retry_sleep�timeout_minutes)r�r�r�r�rVcCs~|jdurtd��td|t��ftjd�t|j|t	d�|_d}t
�}||d}tjddt
d	���|du�r�z|j��}Wn�ty�td
tjd�|jtjt
�|d�dd
�Yn�ty�tdtjd�d|_�Yn�t�y$td|tjd�|jtjt
�||d�dd
�YnJtj�yl}z.td|j|j|j|jftjd�WYd}~n
d}~00|du�r�t
�||k�r�t|�qh�q�qh|du�r�d|_t��|d}||j_d|v�r�|d|_ t!|�}	|jj"}
|
du�r�td��|�#|
�}td|||	|
j$|
j%||j&|j'ftjd�|�rV|�sV|jtj(||	|
j$|
j%|d�dd
�|Wd�S1�sp0YdS)a�Setup ephemeral networking.

        Keep retrying DHCP up to specified number of minutes.  This does
        not kill dhclient, so the timeout in practice may be up to
        timeout_minutes + the system-configured timeout for dhclient.

        :param timeout_minutes: Number of minutes to keep retrying for.

        :raises NoDHCPLeaseError: If unable to obtain DHCP lease.

        :returns: True if NIC is determined to be primary.
        Nz/Bringing up networking when already configured.z2Bringing up ephemeral networking with iface=%s: %rro)r�Z
dhcp_log_func�<zobtain-dhcp-leasezobtain dhcp lease��name�description�parentzInterface not found for DHCP)�durationT��	host_onlyzdhclient executable not foundz&Failed to obtain DHCP lease (iface=%s))r��	interfacez7Command failed: cmd=%r stderr=%r stdout=%r exit_code=%sr�zunknown-245zdhcp context missing ephipv4z{Obtained DHCP lease on interface %r (primary=%r driver=%r router=%r routes=%r lease=%r imds_routed=%r wireserver_routed=%r))r��driver�routerr��lease))r��RuntimeErrorr)rrkrprqrr�r%rr�ReportEventStackr"Zobtain_leaserrr�_report_failurerZ$ReportableErrorDhcpInterfaceNotFoundr�errorrZReportableErrorDhcpLeaserrvrw�stderrru�	exit_coderr�r�rZ_ephipv4r�r�r�r�r�Z(ReportableErrorDhcpOnNonPrimaryInterface)r�r�r�r�r�r��
start_timeZdeadliner�r�r�Zprimaryr1r1r2�_setup_ephemeral_networking�s�
�
����

���
��
��
���






��
���
z+DataSourceAzure._setup_ephemeral_networkingrecCs.d|_d|_|jdurdS|j��d|_dS)zTeardown ephemeral networking.FN)r�r�r�Z
clean_network�r�r1r1r2�_teardown_ephemeral_networkings

z.DataSourceAzure._teardown_ephemeral_networkingcCs|jdup|jjduS)z"Check if networking is configured.N)r�r�r�r1r1r2�_is_ephemeral_networking_up%s

�z+DataSourceAzure._is_ephemeral_networking_upc
Cs�z2gd�}t�|�\}}td|||ftjd�Wn�tjy�}zlt|jt�rnt�d�t	�
�}|�|�n6td|j|j
|j|jftjd�t	�|�}|�|�WYd}~n
d}~00dS)abCheck if azure-proxy-agent is ready for communication with WS/IMDS.

        If ProvisionGuestProxyAgent is true, query azure-proxy-agent status,
        waiting up to 120 seconds for the proxy to negotiate with Wireserver
        and configure an eBPF proxy.  Once azure-proxy-agent is ready,
        it will exit with code 0 and cloud-init can then expect to be able to
        communicate with these services.

        Fail deployment if azure-proxy-agent is not found or otherwise returns
        an error.

        For more information, check out:
        https://github.com/azure/guestproxyagent
        )zazure-proxy-agentz--statusz--waitZ120z1Executing %s resulted in stderr=%r with stdout=%rrozGFailed to activate Azure Guest Proxy Agent: azure-proxy-agent not foundzgFailed to activate Azure Guest Proxy Agent: status check failed cmd=%r stderr=%r stdout=%r exit_code=%sN)rr)rprqrv�
isinstance�reason�FileNotFoundErrorr�rZ!ReportableErrorProxyAgentNotFoundr�rwr�rur�Z&ReportableErrorProxyAgentStatusFailure)r�rw�out�errr�Zreport_error�reportable_errorr1r1r2�_check_azure_proxy_agent_status,s:��
���	�
�z/DataSourceAzure._check_azure_proxy_agent_statusc
Csi}|jd}d}ddi}ddddiii}d}i}t|j|�D]�}zz|�d�r�t��rptj|td	d
�\}}}}nt�|t�\}}}}||_nt|�\}}}}|}t	d|t
jd�W�q$Wq>ty�t	d
|t
jd�Yq>Yq>tj
�yt	d|t
jd�Yq>Yq>0q>d}	t	|	t
jd�t|j��p6|du}
|
�rBdnd}z|j|d�Wnt�yjYn0i}|���r�|�d��r�|��|jdd�}|�s�|du�r�d}	t	|	�t�|	��|�||�}
|
tjk�r�t���r�d}	t	|	t
jd�t�|	��|���s$d}	t	|	t
jd�t�|	��|
tjk�r:|��n4|
tjk�rP|��n|
tj k�rf|�!�n|�"�|�#�\}}}}|�d��r�|��|jdd�}|�$|�}|dtjj%fv�r�|�&t'j(d|d��|j)|d�|�p�d|_*|�+||t�,|d|ig�|d��t-|�}t.|�}t/|�}|�rBt
�d|�||ddd<|�r`t
�d |�||d!d<|�r~t
�d"|�||d!d#<|j*dk�r�|d$�s�zt0|||d%�}d&|i|d$<Wn8t1�y�}zt	d'|t
jd�WYd}~n
d}~00|�sJt2|�}|�rJt
�d(�zt3�4d�5|�6���|d)<Wn"t1�yHt	d*t
jd�Yn0||k�rft	d+|t
jd�t7�}|�r~||d!d,<|�8�|d!d-<|j9d.u�r�|���r�|j:||d/�}z|j;|d0�}Wnt1�y�Yn(0t
�d1|�|�r�||d!d2<|�<�|S)3aWalk all instance metadata sources returning a dict on success.

        @return: A dictionary of any metadata content for this instance.
        @raise: InvalidMetaDataException when the expected metadata service is
            unavailable, broken or disabled.
        r�N�local-hostnamerz�system_info�default_userr�r��udf)�mtypez!Found provisioning metadata in %sroz$Did not find Azure data source in %sz%s was not mountablez�Unable to find provisioning media, falling back to IMDS metadata. Be aware that IMDS metadata does not support admin passwords or custom-data (user-data only).�r��r��ProvisionGuestProxyAgentT)�report_failurezNo OVF or IMDS availablez%Free BSD is not supported for PPS VMszDHCP failed while in source PPSzextended.compute.ppsType)�key�value)�imds_mdZIMDSr)r��files�metadata�userdata_rawz Username retrieved from IMDS: %sz Hostname retrieved from IMDS: %sr�z(Disable password retrieved from IMDS: %sZdisable_passwordr�)�username�hostnameZ
disableSshPwd�ovf-env.xmlz)Failed to construct OVF from IMDS data %szRetrieved userdata from IMDSr�zBad userdata in IMDSzusing files cached in %sZrandom_seedr4F)r�r���pubkey_infoznegotiating returned %s�public-keys)=r��list_possible_azure_dsr�rKr�
is_FreeBSD�mount_cb�load_azure_ds_dirr�r)rprqr �MountFailedErrorrr�boolr�rr��getr��get_metadata_from_imdsr
�InvalidMetaDataException�_determine_pps_typer5r:r�r<�_wait_for_pps_running_reuser=�_wait_for_pps_savable_reuser;�_wait_for_pps_os_disk_shutdown�_wait_for_pps_unknown_reuse�_reprovision�_ppstype_from_imdsr�r�rZ"ReportableErrorImdsInvalidMetadata�validate_imds_network_metadatar��updater��_username_from_imds�_hostname_from_imds�_disable_password_from_imdsr$�	Exception�_userdata_from_imds�base64Z	b64decoderarI�_get_random_seed�_iid�_negotiated�!_determine_wireserver_pubkey_info�
_report_ready�_cleanup_markers)r��crawled_data�ddirZ
ovf_source�mdr�r�r��src�msgZrequires_imds_metadatar�r��pps_typeZimds_ppstypeZ
imds_usernameZ
imds_hostnameZimds_disable_password�contents�eZ
imds_userdatar�r��ssh_keysr1r1r2�crawl_metadatabs6

����
��









���������
��

��zDataSourceAzure.crawl_metadata)r�rVc	
Cs�t�}|d}|jsd}nd}d}d}ztj||d�WSty�}zDt|�}t�|}tj||d�}|js~t|j	t
j�r~d}WYd}~n@d}~0ty�}z t|�}tj
|d�}WYd}~n
d}~00|j||d�td|tjd	�iS)
Ni,�)�max_connection_errors�retry_deadline)�	exceptionr�F)rr�z!Ignoring IMDS metadata due to: %sro)rr�rZ fetch_metadata_with_api_fallbackr,r�rZReportableErrorImdsUrlErrorr��cause�requests�ConnectionError�
ValueErrorZ+ReportableErrorImdsMetadataParsingExceptionr�r)rprr)	r�r�r�rrZerror_stringZerror_reportr�r�r1r1r2r�<sB�
����z&DataSourceAzure.get_metadata_from_imdsr1cstt|��|�tj|_dS)z.Reset any cached class attributes to defaults.N)r�r��clear_cached_attrsr
�UNSET�_metadata_imds)r�Z
attr_defaultsr�r1r2rjsz"DataSourceAzure.clear_cached_attrscCs4tj��}|durdS|jdur$dSt|jd���S)zQCheck platform environment to report if this datasource may
        run.
        NTFr�)rZChassisAssetTagZquery_systemr�r�exists)r�Zchassis_tagr1r1r2�	ds_detectos

zDataSourceAzure.ds_detectc
Cs�z
t�Wn0ty:}zt�d|�WYd}~n
d}~00z
t�Wn0tyv}zt�d|�WYd}~n
d}~00z�z|��}Wn�tjy�}z"|�|�WYd}~W|�	�dSd}~0t�y}z,t�
|�}|�|�WYd}~W|�	�dSd}~00W|�	�n
|�	�0|j�rH|jjdk�rH|j
�d��rHt�t}tj�|��r�td|tjd�t�|d	tg�|_ntd
|tjd�|d	|_|dd|_t�|dtg�|_|d
|_t|j
d|ddd�dS)z�Crawl and process datasource metadata caching metadata as attrs.

        @return: True on success, False on error, invalid or disabled
            datasource.
        z Failed to get boot telemetry: %sNz$Failed to get system information: %sFZubuntur�zXEphemeral resource disk '%s' exists. Merging default Azure cloud ephemeral disk configs.ror�zdEphemeral resource disk '%s' does not exist. Not merging default Azure cloud ephemeral disk configs.r�rr�r�r�i�)�dirmodeT)r&rrprrr(rr�ReportableErrorr�r�Z!ReportableErrorUnhandledExceptionr�r�r�r��*maybe_remove_ubuntu_network_config_scripts�RESOURCE_DISK_PATHr�r�rr)rqrr��#BUILTIN_CLOUD_EPHEMERAL_DISK_CONFIGr�r�DEFAULT_METADATAr�r��write_files)r�rr
r�r��devpathr1r1r2�	_get_data~sp
"
"
�

��
�
���
���

�
�zDataSourceAzure._get_datacCs&|jrd|jvr|��St|jd�S)Nr4)r�rr�r�r1r1r2�get_instance_id�szDataSourceAzure.get_instance_idcCs|jd�|�S)Nr�)r�r�)r�r�r1r1r2�device_name_to_device�sz%DataSourceAzure.device_name_to_devicec	Cs2z|�|jd�WSttfy(Yn0|��S)z+
        Retrieve public SSH keys.
        r)�_get_public_keys_from_imdsr��KeyErrorr�_get_public_keys_from_ovfr�r1r1r2�get_public_ssh_keys�s
z#DataSourceAzure.get_public_ssh_keys)r�rVcCs�zdd�|ddD�}Wn&ty@d}t|tjd��Yn0tdd�|D��rnd	}t|tjd�t|��d
�t|��}t|tjd�|S)z�Get SSH keys from IMDS metadata.

        :raises KeyError: if IMDS metadata is malformed/missing.
        :raises ValueError: if key format is not supported.

        :returns: List of keys.
        cSsg|]}|d�qS)ZkeyDatar1)rhZ
public_keyr1r1r2rj�s�z>DataSourceAzure._get_public_keys_from_imds.<locals>.<listcomp>�computeZ
publicKeysz"No SSH keys found in IMDS metadatarocss|]}t|d�VqdS))r�N)�_key_is_openssh_formatted)rhr�r1r1r2�	<genexpr>�r�z=DataSourceAzure._get_public_keys_from_imds.<locals>.<genexpr>zKey(s) not in OpenSSH formatzRetrieved {} keys from IMDS)r-r)rprq�anyrr�rJ)r�r�r�log_msgr1r1r2r,�s
�
z*DataSourceAzure._get_public_keys_from_imdscCsXg}z*|jd}d�t|��}t|tjd�Wn$tyRd}t|tjd�Yn0|S)zYGet SSH keys that were fetched from wireserver.

        :returns: List of keys.
        r�zRetrieved {} keys from OVFrozNo keys available from OVF)r�r�rJr)rprqr-)r�rr4r1r1r2r.�s
z)DataSourceAzure._get_public_keys_from_ovfcCs|jS�N�r�r�r1r1r2�get_config_objszDataSourceAzure.get_config_objcCst�|���Sr5)r
Zinstance_id_matches_system_uuidr*)r�r�r1r1r2�check_instance_id	sz!DataSourceAzure.check_instance_idcCsZtj�|j�d�d�}t��}tj�|�rVt�	|��
�}t�|�}|��||fvrV|S|S)Nr�r4)
r�r�rar�Z	get_cpathrZquery_system_uuidrrZload_text_file�stripZbyte_swap_system_uuidrb)r�ZpreviousZ
prev_iid_pathZsystem_uuidZ
swapped_idr1r1r2r
s�
zDataSourceAzure._iidc
Cs�zpd}tjddtd��t�|�}Wd�n1s60Y|dur\d}t|tjd�ntd|tjd�Wn8t	y�}z tt
|�tjd��WYd}~n
d}~00dS)z�Use the netlink socket provided to wait for nic detach event.
        NOTE: The function doesn't close the socket. The caller owns closing
        the socket and disposing it safely.
        Nzwait-for-nic-detachzwait for nic detachr�zHPreprovisioned nic not detached as expected. Proceeding without failing.roz%The preprovisioned nic %s is detached)rr�r"rZwait_for_nic_detach_eventr)rprrrq�AssertionErrorr�r�)r��nl_sock�ifnamerr�r1r1r2�_wait_for_nic_detachs&�(��
z$DataSourceAzure._wait_for_nic_detachr�皙�����?)r<�retriesr�cCsdt|�D]<}|jj�|�r0td|tjd�q`|d|krt|�qtd|||ftjd�dS)NzThe link %s is up.rorDz;The link %s is not up after %f seconds, continuing anyways.)�ranger�Z
networkingZtry_set_link_upr)rp�infor)r�r<r?r�rnr1r1r2�wait_for_link_up>s
�

��z DataSourceAzure.wait_for_link_upcCs@|j}t�d|�t�|djt��t�d��t	dtj
d�dS)Nz*Creating a marker file to report ready: %sz{pid}: {time}
)�pidrzRSuccessfully created reported ready marker file while in the preprovisioning pool.ro)r�rprAr�
write_filer�r��getpidrr)rq)r�r�r1r1r2�_create_report_ready_markerRs��z+DataSourceAzure._create_report_ready_marker)�
create_marker�expect_url_error)rGrHrVc
Cs�z|��Wnftyr}zN|r@t|t�r@tdtjd�d|_nd}t|tjd�t	�
|�|�WYd}~n
d}~00d|_|r�|��dS)z�Report ready for PPS, creating the marker file upon completion.

        :raises sources.InvalidMetaDataException: On error reporting ready.
        z,Ignoring http call failure, it was expected.roNz9Failed reporting ready while in the preprovisioning pool.F)
rrr�r,r)rprqr�r�r
r�rrF)r�rGrHr�rr1r1r2�_report_ready_for_pps_s ��"z%DataSourceAzure._report_ready_for_ppsc
Cs�t�d�z�g}d}d}tjddt|�td��t�||�}Wd�n1sR0Y|�|�t	d|tjd�|�
|�|s�t�d	|�|j|d
dd�}|r�t�d�q�q|��qWn6t
y�}zt	t|�tjd�WYd}~n
d}~00dS)
z6Wait until the primary nic for the vm is hot-attached.z*Waiting for primary nic to be hot-attachedFNzwait-for-nic-attachz4wait for nic attach after %d nics have been attachedr�zDetected nic %s attached.roz!Checking if %s is the primary nicr�)r�r�r�zFound primary nic for this VM.)rprArr�rJr"rZwait_for_nic_attach_event�appendr)rBr�r�r:r�r�)r�r;Z
nics_foundZprimary_nic_foundr<r�r1r1r2�"_wait_for_hot_attached_primary_nic�sB
���"

�
�
z2DataSourceAzure._wait_for_hot_attached_primary_nicc
CsLz
t��WStjyF}z"td|��tjd��WYd}~n
d}~00dS)Nz!Failed to create netlink socket: ro)rZcreate_bound_netlink_socketZNetlinkCreateSocketErrorr)rpr�)r�r�r1r1r2�_create_bound_netlink_socket�s
�z,DataSourceAzure._create_bound_netlink_socketcCs.|jdd�tdtjd�td�t���dS)z4Report ready and wait for host to initiate shutdown.F)rGz"Waiting for host to shutdown VM...roi�3�N)rIr)rprArrZReportableErrorOsDiskPpsFailurer�r1r1r2r��s�z.DataSourceAzure._wait_for_pps_os_disk_shutdowncCs�|��}z�|jdus |jjdur(td��|jj}|��t�d|�tjddt	d��Xzt
�||�Wn6ty�}zt
d|tjd�WYd}~n
d}~00Wd�n1s�0YW|��n
|��0|��dS)	z9Report ready and wait for nic link to switch upon re-use.Nzmissing ephemeral contextz#Wait for vnetswitch to happen on %sz!wait-for-media-disconnect-connectzwait for vnet switchr�z'Error while waiting for vnet switch: %sro)rLr�r�r�rIrprqrr�r"rZ!wait_for_media_disconnect_connectr:r)r��closer�)r�r;r�rr1r1r2r��s6�
����<z+DataSourceAzure._wait_for_pps_running_reusec
Cs�|��}zx|jdd�z|��Wn>tjy`}z$td|tjd�d|_WYd}~n
d}~00|�	|�|�
|�W|��n
|��0dS)z@Report ready and wait for nic(s) to be hot-attached upon re-use.T)rHzLIgnoring failure while tearing down networking, NIC was likely unplugged: %rroN)rLrIr�rrvr)rprAr�r=rKrM)r�r;rr1r1r2r��s ��
z+DataSourceAzure._wait_for_pps_savable_reusecCs&tj�|j�rdS|��|��dS)z0Report ready if needed for unknown/recovery PPS.N)r�r��isfiler�rIr�r�r1r1r2r�sz+DataSourceAzure._wait_for_pps_unknown_reusec	Cs�d}d}|s�|��sD|d7}z|jdd�WntyBYqYn0tjddtd��Hzt��}Wn*ty�|�	�YWd�qYn0Wd�q1s�0Yqt
d	|tjd
�|S)z0Poll IMDs for reprovisiondata XML document data.rNrDr�r�zget-reprovision-data-from-imdszget reprovision data from imdsr�z#attempted dhcp %d times after reusero)
r�r�rrr�r"rZfetch_reprovision_datar,r�r)rprq)r�Z
dhcp_attemptsZreprovision_datar1r1r2�
_poll_imdss0
�6�zDataSourceAzure._poll_imds)r�r�rVc
Cs*td|����tjd�t�t�|�}|r0|S|��r�z(tdtjd�t	|j
|d�d|_WdSty�}ztd|tjd�WYd}~n
d}~00zTtdtjd�|�
�z|jd	d
�Wnty�Yn0t	|j
|d�d|_WdSt�y$}ztd|tjd�WYd}~n
d}~00dS)
a�Report failure to Azure host and fabric.

        For errors that may be recoverable (e.g. DHCP), host_only provides a
        mechanism to report the failure that can be updated later with success.
        DHCP will not be attempted if host_only=True and networking is down.

        @param error: Error to report.
        @param host_only: Only report to host (error may be recoverable).
        @return: The success status of sending the failure signal.
        z#Azure datasource failure occurred: roz>Using cached ephemeral dhcp context to report failure to Azure)�endpointr�Tz@Failed to report failure using cached ephemeral dhcp context: %sNz3Using new ephemeral dhcp to report failure to Azurer�r�z5Failed to report failure using new ephemeral dhcp: %sF)r)Zas_encoded_reportrpr�r*rZreport_failure_to_hostr�rqr+r�rrr�r�r)r�r�r�Zreportedrr1r1r2r�;s^�
�������zDataSourceAzure._report_failurer�)r�rVc
Csrt�t��zt|j|j|j|d�}Wn8ty`}z td|t	j
d��WYd}~n
d}~00d|_d|_|S)z�Tells the fabric provisioning has completed.

        :param pubkey_info: Fingerprints of keys to request from Wireserver.

        :raises Exception: if failed to report.

        :returns: List of SSH keys, if requested.
        )rPr�Ziso_devr�zQError communicating with Azure fabric; You may experience connectivity issues: %sroNT)r*rZreport_success_to_hostr'r�r�r�rr)rprrr)r�r�r�rr1r1r2r}s(�
��zDataSourceAzure._report_readyc
CsPz|dddWStyJ}z td|tjd�WYd}~dSd}~00dS)NZextendedr0ZppsTypez2Could not retrieve pps configuration from IMDS: %sro)rr)rprq)r�r�rr1r1r2r��s�z"DataSourceAzure._ppstype_from_imds)�ovf_cfgr�rVcCs�tj�|j�rtj}n�|�dd�tjjks<|�	|�tjjkrDtj}np|�dd�tj
jksj|�	|�tj
jkrrtj
}nB|�d�dus�|�dd�tjjks�|�	|�tjjkr�tj}ntj}t
d|jtjd�|S)z@Determine PPS type using OVF, IMDS data, and reprovision marker.�PreprovisionedVMTypeN�PreprovisionedVmTzPPS type: %sro)r�r�rNr�r5r>r�r=r�r�r;r<r:r)rprA)r�rQr�rr1r1r2r��s4�����
����z#DataSourceAzure._determine_pps_typecCsZ|��}tjddtd��.t|�\}}}|||d|ifWd�S1sL0YdS)zrInitiate the reprovisioning workflow.

        Ephemeral networking is up upon successful reprovisioning.
        zreprovisioning-read-azure-ovfz$read azure ovf during reprovisioningr�r�N)rOrr�r"�read_azure_ovf)r�rr�udr�r1r1r2r��s�zDataSourceAzure._reprovision)r�r�rVc	Csbd}z|�|�WnJttfy\|�dd�}d�|durDt|�nd�}t|tjd�Yn0|S)z�Determine the fingerprints we need to retrieve from Wireserver.

        :return: List of keys to request from Wireserver, if any, else None.
        N�_pubkeysz"Retrieved {} fingerprints from OVFrro)	r,r-rr�r�rJr)rprq)r�r�r�r�r4r1r1r2r�s�z1DataSourceAzure._determine_wireserver_pubkey_infocCst�|j�dS)zCleanup any marker files.N)r�del_filer�r�r1r1r2r	�sz DataSourceAzure._cleanup_markerscCs:|j��}z"t|||j�td�d�Wt�nt�0dS)NF)�is_new_instance�
preserve_ntfs)r�Z
get_ipath_cur�address_ephemeral_resizer�r��DS_CFG_KEY_PRESERVE_NTFSr*)r�r�rX�instance_dirr1r1r2�activate�s
�zDataSourceAzure.activatecCs|j�di��di��d�S)Nrr0ZplatformFaultDomain�r�r�r�r1r1r2�availability_zone�s���z!DataSourceAzure.availability_zonec
Cs�|jrp|jtjkrp|j�d�rpzt|jd|j�d�d�WStyn}zt�dt	|��WYd}~n
d}~00zt
�WSty�}zt�dt	|��WYd}~n
d}~00iS)z:Generate network configuration according to configuration.r��networkr�)r�z?Failed generating network config from IMDS network metadata: %sNz-Failed generating fallback network config: %s)rr
rr�r��6generate_network_config_from_instance_network_metadatarrpr�r��-_generate_network_config_from_fallback_config)r�rr1r1r2�_generate_network_configs.�
�
����&z(DataSourceAzure._generate_network_configcCs(|jr|jtjkr|jS|��|_|jS)z,Provide network configuration v2 dictionary.)r�r
rrcr�r1r1r2�network_config!s
zDataSourceAzure.network_configcCs|j�di��di��d�S)Nrr0�locationr^r�r1r1r2�region+szDataSourceAzure.regioncs�t�}z|d}dd�|dD��Wn,tyPtd|�d�tjd�YdS0�fdd�|D�}|sld	Std
||ftjd�|jr�|jjs�dSt�	|jj�}|r�t
|t�s�dSt|�}||vr�td||ftjd�dS)z=Validate IMDS network config and report telemetry for errors.r`cSsg|]}t|d��qS)�
macAddressrgrmr1r1r2rj6s�zBDataSourceAzure.validate_imds_network_metadata.<locals>.<listcomp>r�z6IMDS network metadata has incomplete configuration: %rroFcsg|]}|�vr|�qSr1r1)rh�m�Z	imds_macsr1r2rjBr�Tz>IMDS network metadata is missing configuration for NICs %r: %rz3IMDS network metadata is missing primary NIC %r: %r)
rlr-r)r�rprrr�r�rZget_interface_macr�r�rd)r�r�Z
local_macsrdZmissing_macsZprimary_macr1rir2r�/sJ�
������z.DataSourceAzure.validate_imds_network_metadata)r1)N)r�r>)F)Nr7r8r9ZdsnamerZNETWORKrZBOOT_NEW_INSTANCE�BOOTZdefault_update_eventsrr
rrZ_ci_pkl_versionr��intr�r�r�r#rr�r�r
r�r�r�r�r�rrr�rr r)r*r+r	r/�dictr,r.r7r8rr=�floatrBrFrIrK�socketrLr�r�r�r��bytesrOrr"r�rr�r5r�r�rr	r]�propertyr_rcrdrfr��
__classcell__r1r1r�r2r�8s�����
6
Z-

H

��
��&
8

$

��A�

�"


�



	
r�cCs,z|dddWSty&YdS0dS)Nr0�	osProfileZ
adminUsername�r-�Z	imds_datar1r1r2r�`sr�cCs(z|ddWSty"YdS0dS)Nr0ZuserDatarsrtr1r1r2rgsrcCs,z|dddWSty&YdS0dS)Nr0rrZcomputerNamersrtr1r1r2r�nsr�cCs0z|ddddkWSty*YdS0dS)Nr0rrZdisablePasswordAuthentication�truersrtr1r1r2rus��rcCsFd|��vrdSt��}z|�|�}Wnty:YdS0|jduS)z?
    Validate whether or not the key is OpenSSH-formatted.
    z
FN)r9rZAuthKeyLineParser�parse�	TypeErrorZkeytype)r��parserZaklr1r1r2r1sr1cCs`dD]V}g}td|�D]6}||t|�}tj�|�r|�|tj�|�f�q|r|SqgS)N)z-part�przrD)r@r�r�r�rrJ�realpath)r(ZmaxnumZsuff�foundZpnumZppathr1r1r2�_partitions_on_device�s
r|cCs*tjddd�}t�d|�tj�|�|vS)Nz	TYPE=ntfsT)Zno_cachezntfs_devices found = %s)r�find_devs_withrprqr�r�rz)r(Zntfs_devicesr1r1r2�_has_ntfs_filesystem�sr~cCs"|rdd�t�tf}d|fStj�|�s6dd|fSt�d|tj�|��t	|�}t
|�dkrldd|fSt
|�dkr�d	|d
�dd�|D��f}d|fSt
|�dkr�|d
\}}n|d\}}t|�s�d|||f}d|fStdd��}d|||f}t
jddtd����}ztj||dddidd�}	Wn�tj�y�}
zhd|_dt|
�v�rxd|dfWYd}
~
Wd�Sd|d||
ffWYd}
~
Wd�Sd}
~
00|	dk�r�d|	|_t�dd�t�t�d|d |	fWd�SWd�n1�s0Yd|d!fS)"a�Determine if the ephemeral drive at devpath should be reformatted.

    A fresh ephemeral disk is formatted by Azure and will:
      a.) have a partition table (dos or gpt)
      b.) have 1 partition that is ntfs formatted, or
          have 2 partitions with the second partition ntfs formatted.
          (larger instances with >2TB ephemeral disk have gpt, and will
           have a microsoft reserved partition as part 1.  LP: #1686514)
      c.) the ntfs partition will have no files other than possibly
          'dataloss_warning_readme.txt'

    User can indicate that NTFS should never be destroyed by setting
    DS_CFG_KEY_PRESERVE_NTFS in dscfg.
    If data is found on NTFS, user is warned to set DS_CFG_KEY_PRESERVE_NTFS
    to make sure cloud-init does not accidentally wipe their data.
    If cloud-init cannot mount the disk to check for data, destruction
    will be allowed, unless the dscfg key is set.z:config says to never destroy NTFS (%s.%s), skipping checksrEFzdevice %s does not existzResolving realpath of %s -> %srzdevice %s was not partitionedrAz&device %s had 3 or more partitions: %srtcSsg|]}|d�qS)rDr1)rhryr1r1r2rj�r�z*can_dev_be_reformatted.<locals>.<listcomp>rDz5partition %s (%s) on device %s was not ntfs formattedcs(tddg��t�fdd�t�|�D��S)Nzdataloss_warning_readme.txtzsystem volume informationcsg|]}|���vr|�qSr1)rb)rh�f�Zignoredr1r2rj�r�z?can_dev_be_reformatted.<locals>.count_files.<locals>.<listcomp>)�setrJr��listdir)Zmpr1r�r2�count_files�s�z+can_dev_be_reformatted.<locals>.count_filesz1partition %s (%s) on device %s was ntfs formattedzmount-ntfs-and-countr�Zntfs�LANG�C)r�Zupdate_env_for_mountZ	log_errorzcannot mount ntfszunknown filesystem type 'ntfs'Tz^ but this system cannot mount NTFS, assuming there are no important files. Formatting allowed.Nz but mount of %s failed: %szmounted and counted %d fileszxit looks like you're using NTFS on the ephemeral disk, to ensure that filesystem does not get wiped, set %s.%s in configz but had %d files on it.z3 and had no important files. Safe for reformatting.)rar�r[r�r�rrprqrzr|rJr~r#rr�r"rr�r�r�r�rr)r(rYrZ
partitionsZ	cand_partZ	cand_pathr��bmsgZevtZ
file_countrr1r1r2�can_dev_be_reformatted�s�����
���
�8

�>r�F)r\r(rXrYc
Cstj�|�s"td|tjd�dStd|tjd�d}d}|rJd\}}nt||�\}}t�d||�|sndSdD]�}tj�|dd	|�}d
||f}tj�|�r�zt�|�t�d|�Wn2t	y�}	zt�
d||	�WYd}	~	n
d}	~	00qrt�d
|�qrdS)Nz,Ephemeral resource disk '%s' does not exist.roz$Ephemeral resource disk '%s' exists.F)TzFirst instance boot.zreformattable=%s: %s)r�ZmountsZsemZconfig_zMarker "%s" for module "%s"z%s removed.z%s: remove failed! (%s)z%s did not exist.)r�r�rr)rprqr�ra�unlinkr�rr)
r\r(rXrY�resultr�modZsempathr�rr1r1r2rZs:��

&rZcCsjdd�}|sdS|si}t�||�|��D]8\}}tj�||�}d|vrT|||�}tj||dd�q,dS)NcSsfz>t�|�}|��D]}d|jvr|jtkrt|_qt�|�WSty`t�	d|�|YS0dS)z>Azure provides the UserPassword in plain text. So we redact itZUserPasswordz#failed to redact userpassword in %sN)
�ETZ
fromstring�iter�tag�text�DEF_PASSWD_REDACTIONZtostringrrpZcritical)Zcnt�fnamer��elemr1r1r2�_redact_password@s
��z%write_files.<locals>._redact_passwordr�i�)�filename�content�mode)rZ
ensure_dirrSr�r�rarD)Zdatadirr�r!r�r�r�r�r1r1r2r'>s
r'cCst�|�}i}i}|jpd}|jr,|j|d<|jr<|j|d<|jdurT|j|d<n|jrbd|d<i}|jrv|j|d<|jr�d|d	<t|jkr�t	|j�|d
<|r�d|i|d<|j
|d
<td|j
tj
d�|j|d<td|jtj
d�|j|d<td|jtj
d�|||fS)z�Parse OVF XML contents.

    :return: Tuple of metadata, configuration, userdata dicts.

    :raises NonAzureDataSource: if XML is not in Azure's format.
    :raises errors.ReportableError: if XML is unparsable or invalid.
    rzr�rVNZ
ssh_pwauthTr�FZlock_passwdZ
hashed_passwdr�r�rSzPreprovisionedVm: %srorRzPreprovisionedVMType: %sr�zProvisionGuestProxyAgent: %s)r!Z
parse_textZcustom_datar�Zpublic_keysZdisable_ssh_password_auth�passwordr�r��encrypt_passZpreprovisioned_vmr)rprAZpreprovisioned_vm_typeZprovision_guest_proxy_agent)rZovf_envrr�rUZdefuserr1r1r2rT[sJ	







�
�
�rTcCst|�Sr5)r.)r�r1r1r2r��sr�cCs^z:t|��}|�d�Wd�WdS1s.0YWntyXt�d|�Yn0dS)z;Return boolean indicating path to cdrom device has content.iNTzcdrom (%s) is not configuredF)�open�read�IOErrorrprq)�	cdrom_dev�fpr1r1r2�_check_freebsd_cdrom�s

&r�cCs(|durdStj|dd�}t�|���S)zIReturn content random seed file if available, otherwise,
    return None.NT)�quiet)rZload_binary_filerZ	b64encode�decode)�sourcer�r1r1r2r�s
rccsT|VtVt��r(d}t|�rF|VndD]}t�d|�EdHq,|rP|VdS)Nz/dev/cd0)Ziso9660r�zTYPE=%s)�DEFAULT_PROVISIONING_ISO_DEVrr�r�r})r�Z	cache_dirr�Zfstyper1r1r2r��sr�c	Cs�tj�|d�}tj�|�s"td��t�d��Bt|d��}|��}Wd�n1sV0YWd�n1st0Yt	|�\}}}|||d|ifS)Nr�zNo ovf-env file foundzReading ovf-env.xml�rb)
r�r�rarNr rZTimedr�r�rT)Z
source_dirZovf_filer�rrrUr�r1r1r2r��sDr�)�network_metadatar�rVc	Cs�did�}t|d�D�]j\}}d}dj|d�}d|dd	i}|d
krPd|d<d|dd
�}dD]�}	|�|	i��dg�}
|
s�t�d|	|�q`d}|	dkr�d}nd}|
r�d|d<||d<|s�q`|
dd�D]N}||	dd
�d|�}
|d}|�d�s�g|d<|d�dj||
d��q�q`|�rr|�rrt|d�}|�d|��i|d��t	|�}|�rd||d d!<||d"|<qt�d#|||�q|S)$z�Convert imds network metadata dictionary to network v2 configuration.

    :param: network_metadata: Dict of "network" key from instance metadata.

    :return: Dictionary containing network version 2 standard configuration.
    rA)�version�	ethernetsr�Fzeth{idx})�idxzroute-metricrDr�rzuse-dnsT)Zdhcp4zdhcp4-overrides�dhcp6)�ipv4Zipv6Z	ipAddresszNo %s addresses found for: %rr�Z24Z128r�zdhcp6-overridesNZsubnet�prefixZprivateIpAddress�	addressesz
{ip}/{prefix})�ipr�rgZ
macaddress)�matchzset-namer�r�r�z<No configuration for: %s (dev_config=%r) (has_ip_address=%r))
�	enumerater�r�rprqrJrdr�rbrs)r�r�Z	netconfigr�ZintfZhas_ip_addressZnicnameZ
dhcp_overrideZ
dev_configZ	addr_typer��default_prefix�addrZ	netPrefixZ	privateIprZr�r1r1r2ra�sh
��
���racCstjdd�}|duriS|S)ztGenerate fallback network config.

    @return: Dictionary containing network version 2 standard configuration.
    T)Z
config_driverN)rZgenerate_fallback_configr6r1r1r2rb&srbcCsh|st}d}|D]R}tj�|�r|s@t�dtjjtj	jg�d}tj�
|�rXt�|�qt�
|�qdS)a(Remove Azure-specific ubuntu network config for non-primary nics.

    @param paths: List of networking scripts or directories to remove when
        present.

    In certain supported ubuntu images, static udev rules or netplan yaml
    config is delivered in the base ubuntu image to support dhcp on any
    additional interfaces which get attached by a customer at some point
    after initial boot. Since the Azure datasource can now regenerate
    network configuration as metadata reports these new devices, we no longer
    want the udev rules or netplan's 90-hotplug-azure.yaml to configure
    networking on eth1 or greater as it might collide with cloud-init's
    configuration.

    Remove the any existing extended network scripts if the datasource is
    enabled to write network per-boot.
    Fz|Removing Ubuntu extended network scripts because cloud-init updates Azure network configuration on the following events: %s.TN)�UBUNTU_EXTENDED_NETWORK_SCRIPTSr�r�rrprArrjr�ZBOOT_LEGACY�isdirrZdel_dirrW)r�Zloggedr�r1r1r2r#2s�r#cCst�|t�Sr5)r
Zlist_from_depends�datasources)Zdependsr1r1r2�get_datasource_listbsr�)N)r-)N)N)�r�	functoolsZloggingr�Zos.pathrGrnZxml.etree.ElementTreeZetreeZElementTreer��enumr�pathlibrrrr�typingrrr	r
rZ	cloudinitrrr
rrrZcloudinit.eventrrZ
cloudinit.netrZcloudinit.net.dhcprrrZcloudinit.net.ephemeralrrZcloudinit.reportingrZcloudinit.sources.azurerrrrZcloudinit.sources.helpersrZcloudinit.sources.helpers.azurerr r!r"r#r$r%r&r'r(r)r*r+Zcloudinit.url_helperr,Zcrypt�partialZrand_strr.�__annotations__r/�AttributeErrorZpasslib.hashZpasslib�hashZsha512_cryptZ	getLoggerr7rpZDS_NAMEr&r$Z
DEFAULT_FSZAGENT_SEED_DIRr�r5r?r�r�rQrTrYrdrlrsryr|rr�r�r�Zres_diskrqr�r%r�r[r�r�r�r�rr�rr1r|r~r�r�rZr'rTr�r�rr�r�rlrarbr#ZDataSourceAzureNetZDEP_FILESYSTEMr�r�r1r1r1r2�<module>s
 <�


	+




�	��
�2




m��+
7



�P&
�

© 2025 Cubjrnet7