# Path: apic_ml2/neutron/plugins/ml2/drivers/cisco/apic/constants.py
# AGENT_TYPE_DVS = 'DVS agent'
# APIC_SYNC_NETWORK = 'apic-sync-network'
# HOST_SNAT_NETWORK_PREFIX = 'host-snat-network-for-internal-use-'
# HOST_SNAT_POOL = 'host-snat-pool-for-internal-use'
# HOST_SNAT_POOL_PORT = 'host-snat-pool-port-for-internal-use'
# DEVICE_OWNER_SNAT_PORT = 'host-snat-pool-port-device-owner-internal-use'
# VIF_TYPE_DVS = "dvs"
# 
# Path: apic_ml2/neutron/plugins/ml2/drivers/cisco/apic/exceptions.py
# class ReservedSynchronizationName(n_exc.BadRequest):


from neutron.common import constants as n_constants
from neutron import context
from neutron import manager
from neutron.plugins.ml2 import db as l2_db
from neutron.plugins.ml2 import driver_context
from oslo_log import log as logging
from oslo_service import loopingcall
from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import constants
from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import exceptions as aexc


class ApicBaseSynchronizer(SynchronizerBase):

    def sync_base(self):
        self.sync(self._sync_base)

    def _sync_base(self):
        ctx = context.get_admin_context()
        # Sync Networks
        # Unroll to avoid unwanted additions during sync
        networks = [x for x in self.core_plugin.get_networks(ctx)]
        for network in networks:
            if (network['name'].startswith(
                    constants.HOST_SNAT_NETWORK_PREFIX) or
                    constants.APIC_SYNC_NETWORK == network['name']):
                continue

            mech_context = driver_context.NetworkContext(
                self.core_plugin, ctx, network)
            try:
                self.driver.create_network_postcommit(mech_context)
            except aexc.ReservedSynchronizationName as e:
                LOG.debug(e.message)
            except Exception as e:
                LOG.exception(e)

        # Sync Subnets
        subnets = [x for x in self.core_plugin.get_subnets(ctx)]
        for subnet in subnets:

# Path: apic_ml2/neutron/plugins/ml2/drivers/cisco/apic/constants.py
# AGENT_TYPE_DVS = 'DVS agent'
# APIC_SYNC_NETWORK = 'apic-sync-network'
# HOST_SNAT_NETWORK_PREFIX = 'host-snat-network-for-internal-use-'
# HOST_SNAT_POOL = 'host-snat-pool-for-internal-use'
# HOST_SNAT_POOL_PORT = 'host-snat-pool-port-for-internal-use'
# DEVICE_OWNER_SNAT_PORT = 'host-snat-pool-port-device-owner-internal-use'
# VIF_TYPE_DVS = "dvs"
# 
# Path: apic_ml2/neutron/plugins/ml2/drivers/cisco/apic/exceptions.py
# class ReservedSynchronizationName(n_exc.BadRequest):


# Path: apic_ml2/neutron/plugins/ml2/drivers/cisco/apic/apic_sync.py
from neutron.common import constants as n_constants
from neutron import context
from neutron import manager
from neutron.plugins.ml2 import db as l2_db
from neutron.plugins.ml2 import driver_context
from oslo_log import log as logging
from oslo_service import loopingcall
from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import constants
from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import exceptions as aexc



class ApicBaseSynchronizer(SynchronizerBase):

    def sync_base(self):
        self.sync(self._sync_base)

    def _sync_base(self):
        ctx = context.get_admin_context()
        # Sync Networks
        # Unroll to avoid unwanted additions during sync
        networks = [x for x in self.core_plugin.get_networks(ctx)]
        for network in networks:
            if (network['name'].startswith(
                    constants.HOST_SNAT_NETWORK_PREFIX) or
                    constants.APIC_SYNC_NETWORK == network['name']):
                continue

            mech_context = driver_context.NetworkContext(
                self.core_plugin, ctx, network)
            try:
                self.driver.create_network_postcommit(mech_context)
            except aexc.ReservedSynchronizationName as e:
                LOG.debug(e.message)
            except Exception as e:
                LOG.exception(e)

        # Sync Subnets
        subnets = [x for x in self.core_plugin.get_subnets(ctx)]
        for subnet in subnets:

            if constants.HOST_SNAT_POOL in subnet['name']: