3 �~�f� � @ sJ d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm Z m Z mZmZ d dl mZ d dlmZmZ d dlmZmZ eje�ZdZdZdd d dgZdd dddddddddgZejd�fdd�Zdd� Zd�dd�Zd�dd �Z d�d!d"�Z!d#d$� Z"d%d&� Z#d'd(� Z$d)d*� Z%d+d,� Z&d-d.� Z'd/d0� Z(d1d2� Z)ej*dd3�e+d4�d5d6��Z,ej*dd3�e-d4�d7d8��Z.e/e+d9�d:d;�Z0d�d<d=�Z1d>d?� Z2d@dA� Z3d�e+d4�dBdC�Z4d�dDdE�Z5d�dFdG�Z6dHdI� Z7dJdK� Z8dLdM� Z9dNdO� Z:dPdQ� Z;G dRdS� dSe<�Z=dTdU� Z>e e/ d4�dVdW�Z?ee/ d4�dXdY�Z@e e/ d4�dZd[�ZAee/ d4�d\d]�ZBe e/ d4�d^d_�ZCee/ d4�d`da�ZDe e/ d4�dbdc�ZEee/ d4�ddde�ZFd�dfdg�ZGdhdi� ZHd�dkdl�ZId�dndo�ZJd�dpdq�ZKdrds� ZLdtdu� ZMeNd4�dvdw�ZOe/ee/ dx�dydz�ZPeNd4�d{d|�ZQeNd4�d}d~�ZReNd4�dd��ZSeNd4�d�d��ZTd�e+e+e+e+e+e+e+e-d��d�d��ZUed� e ee/e/e/e/f dd��d�d��ZVd�d�� ZWe e/ef e+d��d�d��ZXee/d��d�d��ZYe/e+d��d�d��ZZe/e+d��d�d��Z[e/e+d��d�d��Z\e/e+d��d�d��Z]e/e+d��d�d��Z^e/e+d��d�d��Z_e+d4�d�d��Z`e/d4�d�d��Zaebd4�d�d��Zcebd4�d�d��Zde/e/e/d��d�d��ZeG d�d�� d�ef�ZgdS )�� N)�Any�Callable�Dict�List�Optional�Tuple)�urlparse)�subp�util)�UrlError�readurlz/sys/class/net/Zeth0�dhcp6Z ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-statefulz ovs-vsctlz--formatZcsvz --no-headingsz --timeoutZ10z --columns�name�find� interfacez type=internalz([0-9]+)c C s dd� t j|| �D �S )aD Sorting for Humans: natural sort order. Can be use as the key to sort functions. This will sort ['eth0', 'ens3', 'ens10', 'ens12', 'ens8', 'ens0'] as ['ens0', 'ens3', 'ens8', 'ens10', 'ens12', 'eth0'] instead of the simple python way which will produce ['ens0', 'ens10', 'ens12', 'ens3', 'ens8', 'eth0'].c S s$ g | ]}|j � rt|�n|j� �qS � )�isdigit�int�lower)�.0�textr r �/usr/lib/python3.6/__init__.py� <listcomp>4 s z$natural_sort_key.<locals>.<listcomp>)�re�split)�sZ_nsrer r r �natural_sort_key, s r c C s t S )z3Simple function to return the global SYS_CLASS_NET.)� SYS_CLASS_NETr r r r �get_sys_class_path9 s r � c C s t � | d | S )N�/)r )�devname�pathr r r �sys_dev_path>