<commit_before># Copyright 2015 Alcatel-Lucent USA Inc.
#
#    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.
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_log import helpers as log_helpers
from oslo_log import log as logging

from neutron._i18n import _
from neutron_lib.plugins import constants as lib_constants

from nuage_neutron.plugins.common import constants
from nuage_neutron.plugins.common import exceptions as nuage_exc
from nuage_neutron.plugins.common import nuagedb
from nuage_neutron.plugins.common import utils

from nuage_neutron.vsdclient.common.helper import get_l2_and_l3_sub_id

LOG = logging.getLogger(__name__)


class NuagegatewayMixin(utils.SubnetUtilsBase):

    def __init__(self, *args, **kwargs):
        super(NuagegatewayMixin, self).__init__(*args, **kwargs)
        self._l2_plugin = None
        self._l3plugin = None

    @property
    def core_plugin(self):
        if self._l2_plugin is None:
            self._l2_plugin = directory.get_plugin()
        return self._l2_plugin

    @property
    def l3_plugin(self):
        if self._l3plugin is None:
            self._l3plugin = directory.get_plugin(lib_constants.L3)
        return self._l3plugin

    @log_helpers.log_method_call
    def _make_gw_port_dict(self, port, fields=None, context=None):
        res = {
            'id': port['gw_port_id'],
            'name': port['gw_port_name'],
            'vlan': port['gw_port_vlan'],
            'status': port['gw_port_status'],
            'usermnemonic': port['gw_port_mnemonic'],
            'physicalname': port['gw_port_phy_name']
        }

        if context:
            res['tenant_id'] = context.tenant_id
        return self._fields(res, fields)

    @log_helpers.log_method_call
    def _make_gateway_dict(self, gateway, fields=None, context=None):
        res = {
            'id': gateway['gw_id'],
            'name': gateway['gw_name'],
            'type': gateway['gw_type'],
            'status': gateway['gw_status'],
            'template': gateway['gw_template'],
            'systemid': gateway['gw_system_id'],
            'redundant': gateway['gw_redundancy_type']
        }

        if context:
            res['tenant_id'] = context.tenant_id
        return self._fields(res, fields)

    @log_helpers.log_method_call
    def _make_vlan_dict(self, vlan, fields=None, context=None):
        res = {
            'id': vlan['gw_vlan_id'],
            'value': vlan['gw_vlan_value'],
            'gateway': vlan['gw_vlan_gw_id'],
            'vport': vlan['gw_vlan_vport_id'],
            'gatewayport': vlan['gw_vlan_port_id'],<commit_msg>Change redundant gateway api attribute to True/False<commit_after># Copyright 2015 Alcatel-Lucent USA Inc.
#
#    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.
from neutron_lib.plugins import directory
from oslo_config import cfg
from oslo_log import helpers as log_helpers
from oslo_log import log as logging

from neutron._i18n import _
from neutron_lib.plugins import constants as lib_constants

from nuage_neutron.plugins.common import constants
from nuage_neutron.plugins.common import exceptions as nuage_exc
from nuage_neutron.plugins.common import nuagedb
from nuage_neutron.plugins.common import utils
from nuage_neutron.vsdclient.common import constants as vsd_constants

from nuage_neutron.vsdclient.common.helper import get_l2_and_l3_sub_id

LOG = logging.getLogger(__name__)


class NuagegatewayMixin(utils.SubnetUtilsBase):

    def __init__(self, *args, **kwargs):
        super(NuagegatewayMixin, self).__init__(*args, **kwargs)
        self._l2_plugin = None
        self._l3plugin = None

    @property
    def core_plugin(self):
        if self._l2_plugin is None:
            self._l2_plugin = directory.get_plugin()
        return self._l2_plugin

    @property
    def l3_plugin(self):
        if self._l3plugin is None:
            self._l3plugin = directory.get_plugin(lib_constants.L3)
        return self._l3plugin

    @log_helpers.log_method_call
    def _make_gw_port_dict(self, port, fields=None, context=None):
        res = {
            'id': port['gw_port_id'],
            'name': port['gw_port_name'],
            'vlan': port['gw_port_vlan'],
            'status': port['gw_port_status'],
            'usermnemonic': port['gw_port_mnemonic'],
            'physicalname': port['gw_port_phy_name']
        }

        if context:
            res['tenant_id'] = context.tenant_id
        return self._fields(res, fields)

    @log_helpers.log_method_call
    def _make_gateway_dict(self, gateway, fields=None, context=None):
        res = {
            'id': gateway['gw_id'],
            'name': gateway['gw_name'],
            'type': gateway['gw_type'],
            'status': gateway['gw_status'],
            'template': gateway['gw_template'],
            'systemid': gateway['gw_system_id'],
            'redundant': (gateway['gw_redundancy_type'] !=
                          vsd_constants.SINGLE_GW)
        }

        if context:
            res['tenant_id'] = context.tenant_id
        return self._fields(res, fields)

    @log_helpers.log_method_call
    def _make_vlan_dict(self, vlan, fields=None, context=None):
        res = {
            'id': vlan['gw_vlan_id'],
            'value': vlan['gw_vlan_value'],
            'gateway': vlan['gw_vlan_gw_id'],
            'vport': vlan['gw_vlan_vport_id'],
            'gatewayport': vlan['gw_vlan_port_id'],
{'fraction_non_alphanumeric': 0.09780931811169392, 'fraction_numerical': 0.006788028386300524, 'mean_word_length': 2.936247723132969, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6874157', 'n_tokens_mistral': 2037, 'n_tokens_neox': 2012, 'n_words': 498}