# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_ovs/constants.py
# PLUGIN_NAME = 'ovs'
# OVS_VHOSTUSER_INTERFACE_TYPE = 'dpdkvhostuser'
# OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE = 'dpdkvhostuserclient'
# OVS_VHOSTUSER_PREFIX = 'vhu'
# OVS_DATAPATH_SYSTEM = 'system'
# OVS_DATAPATH_NETDEV = 'netdev'
# PLATFORM_LINUX = 'linux2'
# PLATFORM_WIN32 = 'win32'
# OVS_DPDK_INTERFACE_TYPE = 'dpdk'
# DEAD_VLAN = 4095
# 
# Path: vif_plug_ovs/exception.py
# class AgentError(osv_exception.ExceptionBase):
# class MissingPortProfile(osv_exception.ExceptionBase):
# class WrongPortProfile(osv_exception.ExceptionBase):
# class RepresentorNotFound(osv_exception.ExceptionBase):
# class PciDeviceNotFoundById(osv_exception.ExceptionBase):
# 
# Path: vif_plug_ovs/privsep.py



import glob
import os
import re
import sys
from os_vif.internal.ip.api import ip as ip_lib
from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_utils import excutils
from vif_plug_ovs import constants
from vif_plug_ovs import exception
from vif_plug_ovs import privsep

# phys_port_name only contains the VF number
INT_RE = re.compile(r"^(\d+)$")
# phys_port_name contains VF## or vf##
VF_RE = re.compile(r"vf(\d+)", re.IGNORECASE)
# phys_port_name contains PF## or pf##
PF_RE = re.compile(r"pf(\d+)", re.IGNORECASE)
# bus_info (bdf) contains <bus>:<dev>.<func>
PF_FUNC_RE = re.compile(r"\.(\d+)", 0)
# phys_port_name contains p##
UPLINK_PORT_RE = re.compile(r"p(\d+)", re.IGNORECASE)

_SRIOV_TOTALVFS = "sriov_totalvfs"
NIC_NAME_LEN = 14


def _update_device_mtu(dev, mtu):
    if not mtu:
        return
    if sys.platform != constants.PLATFORM_WIN32:
        # Hyper-V with OVS does not support external programming of
        # virtual interface MTUs via netsh or other Windows tools.
        # When plugging an interface on Windows, we therefore skip
        # programming the MTU and fallback to DHCP advertisement.
        set_device_mtu(dev, mtu)


@privsep.vif_plug.entrypoint
def delete_net_dev(dev):
    """Delete a network device only if it exists."""

# Path: os_vif/internal/ip/api.py
# LOG = logging.getLogger(__name__)
# 
# Path: vif_plug_ovs/constants.py
# PLUGIN_NAME = 'ovs'
# OVS_VHOSTUSER_INTERFACE_TYPE = 'dpdkvhostuser'
# OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE = 'dpdkvhostuserclient'
# OVS_VHOSTUSER_PREFIX = 'vhu'
# OVS_DATAPATH_SYSTEM = 'system'
# OVS_DATAPATH_NETDEV = 'netdev'
# PLATFORM_LINUX = 'linux2'
# PLATFORM_WIN32 = 'win32'
# OVS_DPDK_INTERFACE_TYPE = 'dpdk'
# DEAD_VLAN = 4095
# 
# Path: vif_plug_ovs/exception.py
# class AgentError(osv_exception.ExceptionBase):
# class MissingPortProfile(osv_exception.ExceptionBase):
# class WrongPortProfile(osv_exception.ExceptionBase):
# class RepresentorNotFound(osv_exception.ExceptionBase):
# class PciDeviceNotFoundById(osv_exception.ExceptionBase):
# 
# Path: vif_plug_ovs/privsep.py



# Path: vif_plug_ovs/linux_net.py
import glob
import os
import re
import sys
from os_vif.internal.ip.api import ip as ip_lib
from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_utils import excutils
from vif_plug_ovs import constants
from vif_plug_ovs import exception
from vif_plug_ovs import privsep


# phys_port_name only contains the VF number
INT_RE = re.compile(r"^(\d+)$")
# phys_port_name contains VF## or vf##
VF_RE = re.compile(r"vf(\d+)", re.IGNORECASE)
# phys_port_name contains PF## or pf##
PF_RE = re.compile(r"pf(\d+)", re.IGNORECASE)
# bus_info (bdf) contains <bus>:<dev>.<func>
PF_FUNC_RE = re.compile(r"\.(\d+)", 0)
# phys_port_name contains p##
UPLINK_PORT_RE = re.compile(r"p(\d+)", re.IGNORECASE)

_SRIOV_TOTALVFS = "sriov_totalvfs"
NIC_NAME_LEN = 14


def _update_device_mtu(dev, mtu):
    if not mtu:
        return
    if sys.platform != constants.PLATFORM_WIN32:
        # Hyper-V with OVS does not support external programming of
        # virtual interface MTUs via netsh or other Windows tools.
        # When plugging an interface on Windows, we therefore skip
        # programming the MTU and fallback to DHCP advertisement.
        set_device_mtu(dev, mtu)


@privsep.vif_plug.entrypoint
def delete_net_dev(dev):
    """Delete a network device only if it exists."""

    if ip_lib.exists(dev):