# Path: os_vif/exception.py
# class ExceptionBase(Exception):
# class LibraryNotInitialized(ExceptionBase):
# class NoMatchingPlugin(ExceptionBase):
# class NoMatchingPortProfileClass(ExceptionBase):
# class NoSupportedPortProfileVersion(ExceptionBase):
# class NoMatchingVIFClass(ExceptionBase):
# class NoSupportedVIFVersion(ExceptionBase):
# class PlugException(ExceptionBase):
# class UnplugException(ExceptionBase):
# class NetworkMissingPhysicalNetwork(ExceptionBase):
# class NetworkInterfaceNotFound(ExceptionBase):
# class NetworkInterfaceTypeNotDefined(ExceptionBase):
# class ExternalImport(ExceptionBase):
# class NotImplementedForOS(ExceptionBase):
#     def __init__(self, message=None, **kwargs):
#     def format_message(self):
# 
# Path: os_vif/internal/ip/ip_command.py
# class IpCommand(metaclass=abc.ABCMeta):
#     TYPE_VETH = 'veth'
#     TYPE_VLAN = 'vlan'
#     TYPE_BRIDGE = 'bridge'
#     def set(self, device, check_exit_code=None, state=None, mtu=None,
#             address=None, promisc=None, master=None):
#     def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
#             vlan_id=None, ageing=None):
#     def delete(self, device, check_exit_code=None):
#     def exists(self, device):


import netifaces
from oslo_log import log as logging
from os_vif import exception
from os_vif.internal.ip import ip_command
#    under the License.




LOG = logging.getLogger(__name__)


class Netifaces(ip_command.IpCommand):

    def exists(self, device):
        """Return True if the device exists in the namespace."""
        try:
            return bool(netifaces.ifaddresses(device))
        except ValueError:
            LOG.warning("The device does not exist on the system: %s", device)
            return False
        except OSError:
            LOG.error("Failed to get interface addresses: %s", device)
            return False

    def set(self, device, check_exit_code=None, state=None, mtu=None,
            address=None, promisc=None, master=None):
        exception.NotImplementedForOS(function='ip.set', os='Windows')

    def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
            vlan_id=None):
        exception.NotImplementedForOS(function='ip.add', os='Windows')

    def delete(self, device, check_exit_code=None):

# Path: os_vif/exception.py
# class ExceptionBase(Exception):
# class LibraryNotInitialized(ExceptionBase):
# class NoMatchingPlugin(ExceptionBase):
# class NoMatchingPortProfileClass(ExceptionBase):
# class NoSupportedPortProfileVersion(ExceptionBase):
# class NoMatchingVIFClass(ExceptionBase):
# class NoSupportedVIFVersion(ExceptionBase):
# class PlugException(ExceptionBase):
# class UnplugException(ExceptionBase):
# class NetworkMissingPhysicalNetwork(ExceptionBase):
# class NetworkInterfaceNotFound(ExceptionBase):
# class NetworkInterfaceTypeNotDefined(ExceptionBase):
# class ExternalImport(ExceptionBase):
# class NotImplementedForOS(ExceptionBase):
#     def __init__(self, message=None, **kwargs):
#     def format_message(self):
# 
# Path: os_vif/internal/ip/ip_command.py
# class IpCommand(metaclass=abc.ABCMeta):
#     TYPE_VETH = 'veth'
#     TYPE_VLAN = 'vlan'
#     TYPE_BRIDGE = 'bridge'
#     def set(self, device, check_exit_code=None, state=None, mtu=None,
#             address=None, promisc=None, master=None):
#     def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
#             vlan_id=None, ageing=None):
#     def delete(self, device, check_exit_code=None):
#     def exists(self, device):


# Path: os_vif/internal/ip/windows/impl_netifaces.py
import netifaces
from oslo_log import log as logging
from os_vif import exception
from os_vif.internal.ip import ip_command

#    under the License.




LOG = logging.getLogger(__name__)


class Netifaces(ip_command.IpCommand):

    def exists(self, device):
        """Return True if the device exists in the namespace."""
        try:
            return bool(netifaces.ifaddresses(device))
        except ValueError:
            LOG.warning("The device does not exist on the system: %s", device)
            return False
        except OSError:
            LOG.error("Failed to get interface addresses: %s", device)
            return False

    def set(self, device, check_exit_code=None, state=None, mtu=None,
            address=None, promisc=None, master=None):
        exception.NotImplementedForOS(function='ip.set', os='Windows')

    def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
            vlan_id=None):
        exception.NotImplementedForOS(function='ip.add', os='Windows')

    def delete(self, device, check_exit_code=None):

        exception.NotImplementedForOS(function='ip.delete', os='Windows')