# 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
# 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.


__all__ = ['CachedSwitch']


class Cache(object):
    object_type = None
    object_key = None

    def __init__(self, *key_value_tuples):
        self.refresh_items = set()
        self.dict = OrderedDict(*key_value_tuples)

    def create_fake_object(self, item):
        params = {self.object_key: item}
        return self.object_type(**params)

    def invalidated(self):
        self.refresh_items.add(None)
        return self


# 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

# 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.


__all__ = ['CachedSwitch']


class Cache(object):
    object_type = None
    object_key = None

    def __init__(self, *key_value_tuples):
        self.refresh_items = set()
        self.dict = OrderedDict(*key_value_tuples)

    def create_fake_object(self, item):
        params = {self.object_key: item}
        return self.object_type(**params)

    def invalidated(self):
        self.refresh_items.add(None)
        return self


    def __getitem__(self, item):