# 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/utils.py
# def set_mask(data, mask):
# def unset_mask(data, mask, bit_size=32):


from oslo_log import log as logging
from oslo_utils import excutils
from pyroute2 import iproute
from pyroute2.netlink import exceptions as ipexc
from pyroute2.netlink.rtnl import ifinfmsg
from os_vif import exception
from os_vif.internal.ip import ip_command
from os_vif import utils
    def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
            vlan_id=None, ageing=None):
        check_exit_code = check_exit_code or []
        with iproute.IPRoute() as ip:
            args = {'ifname': device,
                    'kind': dev_type}
            if self.TYPE_VLAN == dev_type:
                args['vlan_id'] = vlan_id
                args['link'] = self.lookup_interface(ip, link)
            elif self.TYPE_VETH == dev_type:
                args['peer'] = peer
            elif self.TYPE_BRIDGE == dev_type:
                # NOTE(sean-k-mooney): the keys are defined in the pyroute2
                # codebase but are not documented. see the nla_map field
                # in the bridge_data class located in the
                # pyroute2.netlink.rtnl.ifinfmsg module for mode details
                # https://github.com/svinota/pyroute2/blob/3ba9cdde34b2346ef8c2f8ba17cef5dbeb4c6d52/pyroute2/netlink/rtnl/ifinfmsg/__init__.py#L776-L820
                args['IFLA_BR_FORWARD_DELAY'] = 0  # set no delay
                args['IFLA_BR_STP_STATE'] = 0  # disable spanning tree
                args['IFLA_BR_MCAST_SNOOPING'] = 0  # disable snooping
                # NOTE(sean-k-mooney): we conditionally enable mac ageing as
                # this code is shared between the ovs and linux bridge
                # plugins. For linux bridge we want to allow the default
                # ageing of 300 seconds, whereas for ovs with the ip-tables
                # firewall we want to disable ageing. None was chosen as
                # the default value of ageing to allow the caller to determine
                # what policy to use and keep this code generic.
                if ageing is not None:
                    args['IFLA_BR_AGEING_TIME'] = ageing
            else:

# 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/utils.py
# def set_mask(data, mask):
# def unset_mask(data, mask, bit_size=32):


# Path: os_vif/internal/ip/linux/impl_pyroute2.py
from oslo_log import log as logging
from oslo_utils import excutils
from pyroute2 import iproute
from pyroute2.netlink import exceptions as ipexc
from pyroute2.netlink.rtnl import ifinfmsg
from os_vif import exception
from os_vif.internal.ip import ip_command
from os_vif import utils

    def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
            vlan_id=None, ageing=None):
        check_exit_code = check_exit_code or []
        with iproute.IPRoute() as ip:
            args = {'ifname': device,
                    'kind': dev_type}
            if self.TYPE_VLAN == dev_type:
                args['vlan_id'] = vlan_id
                args['link'] = self.lookup_interface(ip, link)
            elif self.TYPE_VETH == dev_type:
                args['peer'] = peer
            elif self.TYPE_BRIDGE == dev_type:
                # NOTE(sean-k-mooney): the keys are defined in the pyroute2
                # codebase but are not documented. see the nla_map field
                # in the bridge_data class located in the
                # pyroute2.netlink.rtnl.ifinfmsg module for mode details
                # https://github.com/svinota/pyroute2/blob/3ba9cdde34b2346ef8c2f8ba17cef5dbeb4c6d52/pyroute2/netlink/rtnl/ifinfmsg/__init__.py#L776-L820
                args['IFLA_BR_FORWARD_DELAY'] = 0  # set no delay
                args['IFLA_BR_STP_STATE'] = 0  # disable spanning tree
                args['IFLA_BR_MCAST_SNOOPING'] = 0  # disable snooping
                # NOTE(sean-k-mooney): we conditionally enable mac ageing as
                # this code is shared between the ovs and linux bridge
                # plugins. For linux bridge we want to allow the default
                # ageing of 300 seconds, whereas for ovs with the ip-tables
                # firewall we want to disable ageing. None was chosen as
                # the default value of ageing to allow the caller to determine
                # what policy to use and keep this code generic.
                if ageing is not None:
                    args['IFLA_BR_AGEING_TIME'] = ageing
            else:

                raise exception.NetworkInterfaceTypeNotDefined(type=dev_type)