3 \�me�# � @ s� U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dljj Z d dlmZ d dl mZ d dlmZmZ d dlmZmZmZmZ d dlZd dlmZmZmZmZmZ d dlmZmZ d dl m!Z! d d l"m#Z#m$Z$m%Z% d d l&m'Z'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d d l0m1Z1 d dl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZC y.d dlDZDejEeDjDdejFdd�� �d�ZGeGW nP eHeIfk �r� yd dlJZJeJjKjLjKZGW n eHk �r� dd� ZGY nX Y nX ejMeN�ZOdZPddiZQdZRdZSdZTdZUG dd� de�ZVdZWeeX Wd d!d"d#gZYd$d%� ZZd&d'� Z[eXeXeeX d(�d)d*�Z\eXeXd+�d,d-�Z]e8eeX d.�d/d0��Z^e8eXeeX d+�d1d2��Z_d|eXd.�d3d4�Z`d5d6� Zad7d8� Zbd9d:� ZceeX d.�d;d<�Zdeje� �rd=ZSedd>�Zfefdk �r eOjgd?� d@ef ZRn eOjgdA� dZWeTdBeRidCdCdD�ZhdBdEdFgdCdG�ieSdHdI�gdJ�ZidKePgZjdLZkdMZldNZmG dOdP� dPejn�ZodQdR� ZpdSdT� ZqdUdV� ZrdWdX� ZsdYdZ� Ztd}d[d\�Zue8d]d^� �Zve8d_d`� �Zwe8eRdadafeXeXexexdb�dcdd��Zye8d~dedf��Zze8dgdh� �Z{didj� Z|e8dkdl� �Z}e8eWfdmdn��Z~e8dodp� �Ze8dqdr� �Z�e8e�exe�ds�dtdu��Z�e8e�d.�dvdw��Z�e8ddxdy��Z�eoZ�eoej�ffgZ�dzd{� Z�dS )�� N)�Enum)�Path)�sleep�time)�Any�Dict�List�Optional)�net�sources�ssh_util�subp�util)� EventScope� EventType)� device_driver)�NoDHCPLeaseError�NoDHCPLeaseInterfaceError�NoDHCPLeaseMissingDhclientError)�EphemeralDHCPv4�EphemeralIPv4Network)�events)�errors�identity�imds�kvp)�netlink)�DEFAULT_WIRESERVER_ENDPOINT�BrokenAzureDataSource�NonAzureDataSource� OvfEnvXml�azure_ds_reporter�azure_ds_telemetry_reporter�build_minimal_ovf�dhcp_log_cb�get_boot_telemetry�get_ip_from_lease_value�get_metadata_from_fabric�get_system_info�push_log_to_kvp�report_diagnostic_event�report_failure_to_fabric)�UrlErrorz$6$� )Zstrlen)Zsaltc C s t d��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)�_� r0 �%/usr/lib/python3.6/DataSourceAzure.py� blowfish_hashB s r2 �Azurezinstance-idziid-AZURE-NODEz/dev/disk/cloud/azure_resourceZext4z/var/lib/waagentz/dev/sr0c @ s e Zd ZdZdZdZdZdZdS )�PPSType�NoneZPreprovisionedOSDiskZRunningZSavableZUnknownN)�__name__� __module__�__qualname__�NONE�OS_DISK�RUNNING�SAVABLE�UNKNOWNr0 r0 r0 r1 r4 Y s r4 z/sys/firmware/acpi/tables/OEM0z"/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.dc C s� xz| j � D ]n}tjd|�r |j� }t|�dkr |d jd�}t|�dkr |d dkr |d j|�r |d jd�}|d S q W d 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_outrA �lineZfields�columns�compsr0 r0 r1 �"find_storvscid_from_sysctl_pnpinfom s rN c C s2 x,| j � D ] }tj||�r |j� }|d S q W dS )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 r N)rD rE rF rG )�camcontrol_outZdisk_drvrK �itemsr0 r0 r1 �find_busdev_from_disk� s rQ )rO �busdev�returnc C sN xH| j � D ]<}tj||�r |jd�}t|�dkr |d jd�}|d S q W dS )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) �(r? rB �,r N)rD rE rF rG rH )rO rR rK rP Zdev_passr0 r0 r1 �find_dev_from_busdev� s rV )�macrS c C sZ t | �dkrRdj| dd� | dd� | dd� | dd� | dd� | dd� g�} | j� S ) z1Normalize mac address with colons and lower-case.� �:r r? � � � � )rH �join�lower)rW r0 r0 r1 �normalize_mac_address� s Br` )rS c C s dd� t j� D �S )z-Get Hyper-V NICs as normalized MAC addresses.c S s$ g | ]}|d dkrt |d ��qS )r? � hv_netvscrB )r` )�.0�nr0 r0 r1 � <listcomp>� s z1get_hv_netvsc_macs_normalized.<locals>.<listcomp>)r �get_interfacesr0 r0 r0 r1 �get_hv_netvsc_macs_normalized� s rf c sf � fdd�t j� D �}d|kr"dS t|�dkrLtd� |f tjd� |d S td� |f tjd� d S ) z0Determine the device driver to match on, if any.c s$ g | ]}� t |d �kr|d �qS )rB r? )r` )rb �i)rW r0 r1 rd � s z3determine_device_driver_for_mac.<locals>.<listcomp>ra rB z4Assuming driver for interface with mac=%s drivers=%r)�logger_funcr z=Unable to specify driver for interface with mac=%s drivers=%rN)r re rH r* �LOG�debug�warning)rW Zdriversr0 )rW r1 �determine_device_driver_for_mac� s rl c C s: yt j | �jS t jk r4 tjddj| �� |S X d S )NzFailed to execute: %s� )r �stdout�ProcessExecutionErrorri rj r^ )�cmd�fail_retr0 r0 r1 �execute_or_debug� s rr c C s t ddgdd�S )NZsysctlzdev.storvsc� )rq )rr r0 r0 r0 r1 �get_dev_storvsc_sysctl� s rt c C s t dddg�S )N� camcontrol�devlistz-b)rr r0 r0 r0 r1 �get_camcontrol_dev_bus� s rw c C s t ddg�S )Nru rv )rr r0 r0 r0 r1 �get_camcontrol_dev� s rx c C s� d}| dkrd}| d } dt | � }dj||�}t� }t||�}|sRtjd� d S t� }t� }dj|�}t||�} | r�t || �} | d kr�tjd � d S | S d j|�}t||�} | r�t || �} | d kr�tjd � d S | S d S )NZ00000000rB Z00000001r? Z000z{0}-{1}z#Fail to find storvsc id from sysctlz blkvsc{0}zFail to find /dev/daXz storvsc{0}) �str�formatrt rN ri rj rw rx rQ rV )Zport_idZg0Zg1Zg0g1rJ Z storvscidZcamcontrol_b_outrO ZblkvscZscbusxZdevnameZstorvscr0 r0 r1 �get_resource_disk_on_freebsd� s<