3 \�me7D � @ s: d Z ddlZddlZddlZddlZddlZddlmZmZ ddl m Z ddlmZm Z mZmZmZmZmZ ddlZddlmZ ddlmZ ddlmZ dd lmZmZmZmZmZ dd l m!Z! ej"e#�Z$dZ%dZ&d Z'ddddddd�Z(e)d�dd�Z*d9eee) e e)ef d�dd�Z+G dd� de�Z,G dd� de�Z-G dd� de�Z.e)e/d�dd �Z0G d!d"� d"ej1�Z2e3d�d#d$�Z4d:ej5e)e3d&�d'd(�Z6d;ej5e)e3ej7d)�d*d+�Z8G d,d-� d-e�Z9G d.d/� d/�Z:e&e9j;fe)e9e/d0�d1d2�Z<e2ej=ffgZ>d3d4� Z?e#d5k�r6ddl@Z@d6ZAe@jBeAd7�ZCeCjD� eEejFe<e9j;d8��� dS )<a� Datasource for LXD, reads /dev/lxd/sock representation of instance data. Notes: * This datasource replaces previous NoCloud datasource for LXD. * Older LXD images may not have updates for cloud-init so NoCloud may still be detected on those images. * Detect LXD datasource when /dev/lxd/sock is an active socket file. * Info on dev-lxd API: https://documentation.ubuntu.com/lxd/en/latest/dev-lxd/ � N)�Flag�auto)�JSONDecodeError)�Any�Dict�List�Optional�Tuple�Union�cast)�HTTPAdapter)�HTTPConnection)�HTTPConnectionPool)� atomic_helper�sources�subp� url_helper�util)�find_fallback_nicz /dev/lxd/sockz1.0z http://lxdz user-dataznetwork-configzvendor-data)zcloud-init.user-datazcloud-init.network-configzcloud-init.vendor-datazuser.user-datazuser.network-configzuser.vendor-data)�returnc C s� d} t jd�r�yt j dg�\}}W n. t jk rP } ztjd|� | S d }~X nX |j� d kr�tj� d d }|dkrzd S |d kr�dS dS | S )NZeth0zsystemd-detect-virtzHUnable to run systemd-detect-virt: %s. Rendering default network config.�kvm�qemu�uname� Zppc64leZenp0s5Zs390xZenc9Zenp5s0)r r )r ZwhichZProcessExecutionError�LOG�warning�stripr Zsystem_info)Zdefault_nameZ virt_type�_�errZarch� r �#/usr/lib/python3.6/DataSourceLXD.py�_get_fallback_interface_name/ s&