# Path: networking_vsphere/_i18n.py
# DOMAIN = "networking_vsphere"
# _C = _translators.contextual_form
# _P = _translators.plural_form
# _LI = _translators.log_info
# _LW = _translators.log_warning
# _LE = _translators.log_error
# _LC = _translators.log_critical
# def get_available_languages():
# 
# Path: networking_vsphere/extensions/ovsvapp_cluster.py
# def convert_none_to_empty_list(value):
# def validate_clusters_list(data, valid_values=None):
#     def get_name(cls):
#     def get_alias(cls):
#     def get_description(cls):
#     def get_namespace(cls):
#     def get_updated(cls):
#     def get_resources(cls):
#     def get_extended_resources(self, version):
#     def get_ovsvapp_cluster(self, context, vcenter_id, fields=None):
#     def get_ovsvapp_clusters(self, context, filters=None, fields=None):
#     def create_ovsvapp_cluster(self, context, ovsvapp_cluster):
#     def update_ovsvapp_cluster(self, context, id, ovsvapp_cluster):
# RESOURCE_ATTRIBUTE_MAP = {
#     'ovsvapp_clusters': {
#         'tenant_id': {'allow_post': True, 'allow_put': False,
#                       'validate': {'type:string': None},
#                       'required_by_policy': True,
#                       'is_visible': False},
#         'vcenter_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'clusters': {'allow_post': True, 'allow_put': True,
#                      'convert_to': convert_none_to_empty_list,
#                      'validate': {'type:clusters_list': None},
#                      'default': None, 'is_visible': True},
#     }
# }
# class Ovsvapp_cluster(extensions.ExtensionDescriptor):
# class OVSvAppClusterPluginBase(object):
# 
# Path: networking_vsphere/extensions/ovsvapp_mitigated_cluster.py
# RESOURCE_ATTRIBUTE_MAP = {
#     'ovsvapp_mitigated_clusters': {
#         'tenant_id': {'allow_post': True, 'allow_put': False,
#                       'validate': {'type:string': None},
#                       'required_by_policy': True,
#                       'is_visible': False},
#         'vcenter_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'cluster_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'being_mitigated': {'allow_post': True, 'allow_put': True,
#                             'is_visible': True, 'default': False,
#                             'convert_to': attr.convert_to_boolean},
#         'threshold_reached': {'allow_post': True, 'allow_put': True,
#                               'is_visible': True, 'default': False,
#                               'convert_to': attr.convert_to_boolean},
#     }
# }
# class Ovsvapp_mitigated_cluster(extensions.ExtensionDescriptor):
# class OVSvAppMitigatedClusterPluginBase(object):
#     def get_name(cls):
#     def get_alias(cls):
#     def get_description(cls):
#     def get_namespace(cls):
#     def get_updated(cls):
#     def get_resources(cls):
#     def get_extended_resources(self, version):
#     def get_ovsvapp_mitigated_cluster(self, context, vcenter_id, fields=None):
#     def update_ovsvapp_mitigated_cluster(self, context, id,
#                                          ovsvapp_mitigated_cluster):
#     def get_ovsvapp_mitigated_clusters(self, context, filters=None,
#                                        fields=None):
#     def delete_ovsvapp_mitigated_cluster(self, context, id, filters=None):


from oslo_log import log
from neutron.common import exceptions as exc
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from networking_vsphere._i18n import _, _LE, _LI, _LW
from networking_vsphere.db import ovsvapp_models as models
from networking_vsphere.extensions import ovsvapp_cluster
from networking_vsphere.extensions import ovsvapp_mitigated_cluster as vapp_mc
import sqlalchemy.orm.exc as sa_exc
        if assign:
            count = allocation.network_port_count + 1
            allocation.update({'network_port_count': count})
            LOG.debug("Incremented the allocated port count for network "
                      "%s.", res)
    except sa_exc.NoResultFound:
        if not assign:
            raise Exception()
        try:
            allocation = session.query(models.ClusterVNIAllocations).filter(
                models.ClusterVNIAllocations.vcenter_id == res['vcenter_id'],
                models.ClusterVNIAllocations.cluster_id == res['cluster_id'],
                models.ClusterVNIAllocations.allocated == 0
            ).first()
            if allocation:
                lvid = allocation.lvid
                allocation.update({'network_id': res['network_id'],
                                   'allocated': True,
                                   'network_port_count': 1})
                LOG.info(_LI("Assigned local vlan %(lvid)s for the network "
                             "%(network)s on the cluster %(cluster)s."),
                         {'network': port_info['network_id'],
                          'cluster': port_info['cluster_id'],
                          'lvid': lvid})
            else:
                LOG.error(_LE("All available VLANs are used up in the cluster "
                              "%(cluster)s of vCenter %(vcenter)s."),
                          {'cluster': res['cluster_id'],
                           'vcenter': res['vcenter_id']})
        except Exception as e:

# Path: networking_vsphere/_i18n.py
# DOMAIN = "networking_vsphere"
# _C = _translators.contextual_form
# _P = _translators.plural_form
# _LI = _translators.log_info
# _LW = _translators.log_warning
# _LE = _translators.log_error
# _LC = _translators.log_critical
# def get_available_languages():
# 
# Path: networking_vsphere/extensions/ovsvapp_cluster.py
# def convert_none_to_empty_list(value):
# def validate_clusters_list(data, valid_values=None):
#     def get_name(cls):
#     def get_alias(cls):
#     def get_description(cls):
#     def get_namespace(cls):
#     def get_updated(cls):
#     def get_resources(cls):
#     def get_extended_resources(self, version):
#     def get_ovsvapp_cluster(self, context, vcenter_id, fields=None):
#     def get_ovsvapp_clusters(self, context, filters=None, fields=None):
#     def create_ovsvapp_cluster(self, context, ovsvapp_cluster):
#     def update_ovsvapp_cluster(self, context, id, ovsvapp_cluster):
# RESOURCE_ATTRIBUTE_MAP = {
#     'ovsvapp_clusters': {
#         'tenant_id': {'allow_post': True, 'allow_put': False,
#                       'validate': {'type:string': None},
#                       'required_by_policy': True,
#                       'is_visible': False},
#         'vcenter_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'clusters': {'allow_post': True, 'allow_put': True,
#                      'convert_to': convert_none_to_empty_list,
#                      'validate': {'type:clusters_list': None},
#                      'default': None, 'is_visible': True},
#     }
# }
# class Ovsvapp_cluster(extensions.ExtensionDescriptor):
# class OVSvAppClusterPluginBase(object):
# 
# Path: networking_vsphere/extensions/ovsvapp_mitigated_cluster.py
# RESOURCE_ATTRIBUTE_MAP = {
#     'ovsvapp_mitigated_clusters': {
#         'tenant_id': {'allow_post': True, 'allow_put': False,
#                       'validate': {'type:string': None},
#                       'required_by_policy': True,
#                       'is_visible': False},
#         'vcenter_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'cluster_id': {'allow_post': True, 'allow_put': True,
#                        'is_visible': True, 'default': ''},
#         'being_mitigated': {'allow_post': True, 'allow_put': True,
#                             'is_visible': True, 'default': False,
#                             'convert_to': attr.convert_to_boolean},
#         'threshold_reached': {'allow_post': True, 'allow_put': True,
#                               'is_visible': True, 'default': False,
#                               'convert_to': attr.convert_to_boolean},
#     }
# }
# class Ovsvapp_mitigated_cluster(extensions.ExtensionDescriptor):
# class OVSvAppMitigatedClusterPluginBase(object):
#     def get_name(cls):
#     def get_alias(cls):
#     def get_description(cls):
#     def get_namespace(cls):
#     def get_updated(cls):
#     def get_resources(cls):
#     def get_extended_resources(self, version):
#     def get_ovsvapp_mitigated_cluster(self, context, vcenter_id, fields=None):
#     def update_ovsvapp_mitigated_cluster(self, context, id,
#                                          ovsvapp_mitigated_cluster):
#     def get_ovsvapp_mitigated_clusters(self, context, filters=None,
#                                        fields=None):
#     def delete_ovsvapp_mitigated_cluster(self, context, id, filters=None):


# Path: networking_vsphere/db/ovsvapp_db.py
from oslo_log import log
from neutron.common import exceptions as exc
from neutron.db import api as db_api
from neutron.db import common_db_mixin
from networking_vsphere._i18n import _, _LE, _LI, _LW
from networking_vsphere.db import ovsvapp_models as models
from networking_vsphere.extensions import ovsvapp_cluster
from networking_vsphere.extensions import ovsvapp_mitigated_cluster as vapp_mc
import sqlalchemy.orm.exc as sa_exc

        if assign:
            count = allocation.network_port_count + 1
            allocation.update({'network_port_count': count})
            LOG.debug("Incremented the allocated port count for network "
                      "%s.", res)
    except sa_exc.NoResultFound:
        if not assign:
            raise Exception()
        try:
            allocation = session.query(models.ClusterVNIAllocations).filter(
                models.ClusterVNIAllocations.vcenter_id == res['vcenter_id'],
                models.ClusterVNIAllocations.cluster_id == res['cluster_id'],
                models.ClusterVNIAllocations.allocated == 0
            ).first()
            if allocation:
                lvid = allocation.lvid
                allocation.update({'network_id': res['network_id'],
                                   'allocated': True,
                                   'network_port_count': 1})
                LOG.info(_LI("Assigned local vlan %(lvid)s for the network "
                             "%(network)s on the cluster %(cluster)s."),
                         {'network': port_info['network_id'],
                          'cluster': port_info['cluster_id'],
                          'lvid': lvid})
            else:
                LOG.error(_LE("All available VLANs are used up in the cluster "
                              "%(cluster)s of vCenter %(vcenter)s."),
                          {'cluster': res['cluster_id'],
                           'vcenter': res['vcenter_id']})
        except Exception as e:

            LOG.exception(_LE("Unable to obtain local vlan id %s."), e)