# Path: netman/core/objects/bond.py
# class Bond(BaseInterface):
#     def __init__(self, number=None, link_speed=None, members=None, **interface):
#         super(Bond, self).__init__(**interface)
#         self.number = number
#         self.link_speed = link_speed
#         self.members = members or []
# 
#     @property
#     def interface(self):
#         warnings.warn('Deprecated: Use directly the members of Bond instead.', DeprecationWarning)
#         return Interface(
#             shutdown=self.shutdown,
#             port_mode=self.port_mode,
#             access_vlan=self.access_vlan,
#             trunk_native_vlan=self.trunk_native_vlan,
#             trunk_vlans=self.trunk_vlans,
#         )
# 
# Path: netman/core/objects/port_modes.py
# ACCESS = "ACCESS"
# 
# TRUNK = "TRUNK"
# 
# Path: netman/core/objects/switch_base.py
# class SwitchBase(SwitchOperations):
#     def __init__(self, switch_descriptor):
#         self.switch_descriptor = switch_descriptor
#         self.logger = logging.getLogger("{module}.{hostname}".format(module=self.__module__, hostname=self.switch_descriptor.hostname))
#         self.connected = False
#         self.in_transaction = False
# 
#     def connect(self):
#         self._connect()
#         self.connected = True
# 
#     def disconnect(self):
#         self._disconnect()
#         self.connected = False
# 
#     def start_transaction(self):
#         self._start_transaction()
#         self.in_transaction = True
# 
#     def end_transaction(self):
#         self._end_transaction()
#         self.in_transaction = False
# 
#     def _connect(self):
#         """
#         Adpapters should implement this rather than connect
#         """
#         raise NotImplementedError()
# 
#     def _disconnect(self):
#         """
#         Adpapters should implement this rather than disconnect
#         """
#         raise NotImplementedError()
# 
#     def _start_transaction(self):
#         """
#         Adpapters should implement this rather than connect
#         """
#         raise NotImplementedError()
# 
#     def _end_transaction(self):
#         """
#         Adpapters should implement this rather than disconnect
#         """
#         raise NotImplementedError()
# 
#     @contextmanager
#     def transaction(self):
#         self.start_transaction()
#         try:
#             yield self
#             self.commit_transaction()
#         except Exception as e:
#             if self.logger:
#                 self.logger.exception(e)
#             self.rollback_transaction()
#             raise
#         finally:
#             self.end_transaction()


import copy
from collections import OrderedDict
from netman.core.objects.bond import Bond
from netman.core.objects.interface import Interface
from netman.core.objects.interface_states import OFF, ON
from netman.core.objects.port_modes import ACCESS, TRUNK
from netman.core.objects.switch_base import SwitchBase
from netman.core.objects.vlan import Vlan
from netman.core.objects.vrrp_group import VrrpGroup
    def add_ip_to_vlan(self, vlan_number, ip_network):
        self.real_switch.add_ip_to_vlan(vlan_number, ip_network)
        self.vlans_cache[vlan_number].ips.append(ip_network)

    def remove_ip_from_vlan(self, vlan_number, ip_network):
        self.real_switch.remove_ip_from_vlan(vlan_number, ip_network)
        self.vlans_cache[vlan_number].ips = [
            net for net in self.vlans_cache[vlan_number].ips
            if str(net) != str(ip_network)]

    def set_vlan_vrf(self, vlan_number, vrf_name):
        self.real_switch.set_vlan_vrf(vlan_number, vrf_name)
        self.vlans_cache[vlan_number].vrf_forwarding = vrf_name

    def unset_vlan_vrf(self, vlan_number):
        self.real_switch.unset_vlan_vrf(vlan_number)
        self.vlans_cache[vlan_number].vrf_forwarding = None

    def set_access_mode(self, interface_id):
        self.real_switch.set_access_mode(interface_id)
        self.interfaces_cache[interface_id].port_mode = ACCESS
        self.interfaces_cache[interface_id].trunk_native_vlan = None
        self.interfaces_cache[interface_id].trunk_vlans = []

    def set_trunk_mode(self, interface_id):
        self.real_switch.set_trunk_mode(interface_id)
        self.interfaces_cache[interface_id].port_mode = TRUNK

    def set_bond_access_mode(self, bond_number):
        self.real_switch.set_bond_access_mode(bond_number)

# Path: netman/core/objects/bond.py
# class Bond(BaseInterface):
#     def __init__(self, number=None, link_speed=None, members=None, **interface):
#         super(Bond, self).__init__(**interface)
#         self.number = number
#         self.link_speed = link_speed
#         self.members = members or []
# 
#     @property
#     def interface(self):
#         warnings.warn('Deprecated: Use directly the members of Bond instead.', DeprecationWarning)
#         return Interface(
#             shutdown=self.shutdown,
#             port_mode=self.port_mode,
#             access_vlan=self.access_vlan,
#             trunk_native_vlan=self.trunk_native_vlan,
#             trunk_vlans=self.trunk_vlans,
#         )
# 
# Path: netman/core/objects/port_modes.py
# ACCESS = "ACCESS"
# 
# TRUNK = "TRUNK"
# 
# Path: netman/core/objects/switch_base.py
# class SwitchBase(SwitchOperations):
#     def __init__(self, switch_descriptor):
#         self.switch_descriptor = switch_descriptor
#         self.logger = logging.getLogger("{module}.{hostname}".format(module=self.__module__, hostname=self.switch_descriptor.hostname))
#         self.connected = False
#         self.in_transaction = False
# 
#     def connect(self):
#         self._connect()
#         self.connected = True
# 
#     def disconnect(self):
#         self._disconnect()
#         self.connected = False
# 
#     def start_transaction(self):
#         self._start_transaction()
#         self.in_transaction = True
# 
#     def end_transaction(self):
#         self._end_transaction()
#         self.in_transaction = False
# 
#     def _connect(self):
#         """
#         Adpapters should implement this rather than connect
#         """
#         raise NotImplementedError()
# 
#     def _disconnect(self):
#         """
#         Adpapters should implement this rather than disconnect
#         """
#         raise NotImplementedError()
# 
#     def _start_transaction(self):
#         """
#         Adpapters should implement this rather than connect
#         """
#         raise NotImplementedError()
# 
#     def _end_transaction(self):
#         """
#         Adpapters should implement this rather than disconnect
#         """
#         raise NotImplementedError()
# 
#     @contextmanager
#     def transaction(self):
#         self.start_transaction()
#         try:
#             yield self
#             self.commit_transaction()
#         except Exception as e:
#             if self.logger:
#                 self.logger.exception(e)
#             self.rollback_transaction()
#             raise
#         finally:
#             self.end_transaction()


# Path: netman/adapters/switches/cached.py
import copy
from collections import OrderedDict
from netman.core.objects.bond import Bond
from netman.core.objects.interface import Interface
from netman.core.objects.interface_states import OFF, ON
from netman.core.objects.port_modes import ACCESS, TRUNK
from netman.core.objects.switch_base import SwitchBase
from netman.core.objects.vlan import Vlan
from netman.core.objects.vrrp_group import VrrpGroup

    def add_ip_to_vlan(self, vlan_number, ip_network):
        self.real_switch.add_ip_to_vlan(vlan_number, ip_network)
        self.vlans_cache[vlan_number].ips.append(ip_network)

    def remove_ip_from_vlan(self, vlan_number, ip_network):
        self.real_switch.remove_ip_from_vlan(vlan_number, ip_network)
        self.vlans_cache[vlan_number].ips = [
            net for net in self.vlans_cache[vlan_number].ips
            if str(net) != str(ip_network)]

    def set_vlan_vrf(self, vlan_number, vrf_name):
        self.real_switch.set_vlan_vrf(vlan_number, vrf_name)
        self.vlans_cache[vlan_number].vrf_forwarding = vrf_name

    def unset_vlan_vrf(self, vlan_number):
        self.real_switch.unset_vlan_vrf(vlan_number)
        self.vlans_cache[vlan_number].vrf_forwarding = None

    def set_access_mode(self, interface_id):
        self.real_switch.set_access_mode(interface_id)
        self.interfaces_cache[interface_id].port_mode = ACCESS
        self.interfaces_cache[interface_id].trunk_native_vlan = None
        self.interfaces_cache[interface_id].trunk_vlans = []

    def set_trunk_mode(self, interface_id):
        self.real_switch.set_trunk_mode(interface_id)
        self.interfaces_cache[interface_id].port_mode = TRUNK

    def set_bond_access_mode(self, bond_number):
        self.real_switch.set_bond_access_mode(bond_number)

        self.bonds_cache[bond_number].port_mode = ACCESS