# 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
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



LOG = logging.getLogger(__name__)


class PyRoute2(ip_command.IpCommand):

    def _ip_link(self, ip, command, check_exit_code, **kwargs):
        try:
            LOG.debug('pyroute2 command %(command)s, arguments %(args)s' %
                      {'command': command, 'args': kwargs})
            return ip.link(command, **kwargs)
        except ipexc.NetlinkError as e:

# 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

#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



LOG = logging.getLogger(__name__)


class PyRoute2(ip_command.IpCommand):

    def _ip_link(self, ip, command, check_exit_code, **kwargs):
        try:
            LOG.debug('pyroute2 command %(command)s, arguments %(args)s' %
                      {'command': command, 'args': kwargs})
            return ip.link(command, **kwargs)
        except ipexc.NetlinkError as e:

            with excutils.save_and_reraise_exception() as ctx: