<commit_before># Copyright 2015 Brocade Communications System, Inc.
# All Rights Reserved.
#
#    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.

import netaddr
from oslo.utils import excutils
from sqlalchemy.orm import exc

from neutron.api.rpc.handlers import l3_rpc
from neutron.api.v2 import attributes
from neutron.common import constants as l3_constants
from neutron.common import exceptions as q_exc
from neutron.db import common_db_mixin
from neutron.db import extraroute_db
from neutron.db import l3_agentschedulers_db
from neutron.db import l3_db
from neutron.db import l3_dvr_db
from neutron.db import l3_gwmode_db
from neutron.db import models_v2
from neutron.extensions import l3
from neutron.i18n import _LE
from neutron.openstack.common import log as logging

from vyatta.common import config
from vyatta.common import exceptions as v_exc
from vyatta.common import utils as vyatta_utils


LOG = logging.getLogger(__name__)


class VyattaVRouterMixin(common_db_mixin.CommonDbMixin,
                         extraroute_db.ExtraRoute_db_mixin,
                         l3_dvr_db.L3_NAT_with_dvr_db_mixin,
                         l3_gwmode_db.L3_NAT_db_mixin,
                         l3_agentschedulers_db.L3AgentSchedulerDbMixin):
    """Brocade Neutron L3 Plugin for Vyatta vRouter.

    Supports CRUD operations on vRouter, add/remove interfaces from vRouter
    and floating IPs for VMs.It performs vRouter VM lifecyle management by
    calling Nova APIs during the Create and Delete Router calls.
    Once the vRouter VM is up, L3 plugin uses REST API to perform the
    configurations. L3 plugin supports add/remove router interfaces by
    attaching the neutron ports to vRouter VM using Nova API.
    RPC notifications will be used by the firewall agent that is coupled
    with l3-agent. This is needed for our firewall plugin.
    """

    ATTACH_PORT_RETRY_LIMIT = 5
    ATTACH_PORT_RETRY_DELAY = 5

    def create_router(self, context, router):<commit_msg>Move code from shim L3 vyatta plugin<commit_after># Copyright 2015 Brocade Communications System, Inc.
# All Rights Reserved.
#
#    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.

import netaddr
from oslo.utils import excutils
from oslo.utils import importutils
from sqlalchemy.orm import exc

from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api
from neutron.api.rpc.handlers import l3_rpc
from neutron.api.v2 import attributes
from neutron.common import constants as l3_constants
from neutron.common import exceptions as q_exc
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.db import common_db_mixin
from neutron.db import extraroute_db
from neutron.db import l3_agentschedulers_db
from neutron.db import l3_db
from neutron.db import l3_dvr_db
from neutron.db import l3_gwmode_db
from neutron.db import models_v2
from neutron.extensions import l3
from neutron.i18n import _LE
from neutron.openstack.common import log as logging
from neutron.plugins.common import constants

from vyatta.common import config
from vyatta.common import exceptions as v_exc
from vyatta.common import utils as vyatta_utils
from vyatta.vrouter import driver as vrouter_driver


LOG = logging.getLogger(__name__)


class VyattaVRouterMixin(common_db_mixin.CommonDbMixin,
                         extraroute_db.ExtraRoute_db_mixin,
                         l3_dvr_db.L3_NAT_with_dvr_db_mixin,
                         l3_gwmode_db.L3_NAT_db_mixin,
                         l3_agentschedulers_db.L3AgentSchedulerDbMixin):
    """Brocade Neutron L3 Plugin for Vyatta vRouter.

    Supports CRUD operations on vRouter, add/remove interfaces from vRouter
    and floating IPs for VMs.It performs vRouter VM lifecyle management by
    calling Nova APIs during the Create and Delete Router calls.
    Once the vRouter VM is up, L3 plugin uses REST API to perform the
    configurations. L3 plugin supports add/remove router interfaces by
    attaching the neutron ports to vRouter VM using Nova API.
    RPC notifications will be used by the firewall agent that is coupled
    with l3-agent. This is needed for our firewall plugin.
    """

    ATTACH_PORT_RETRY_LIMIT = 5
    ATTACH_PORT_RETRY_DELAY = 5

    supported_extension_aliases = [
        "router", "ext-gw-mode", "extraroute",
        l3_constants.L3_AGENT_SCHEDULER_EXT_ALIAS]

    def __init__(self):
        self.setup_rpc()
        self.driver = vrouter_driver.VyattaVRouterDriver()
        self.router_scheduler = importutils.import_object(
            config.CONF.router_scheduler_driver)
        self.start_periodic_agent_status_check()

    def setup_rpc(self):
        # RPC support
        self.topic = topics.L3PLUGIN
        self.conn = n_rpc.create_connection(new=True)
        self.agent_notifiers.update(
            {l3_constants.AGENT_TYPE_L3: l3_rpc_agent_api.L3AgentNotifyAPI()})
        self.endpoints = [_VyattaL3RPCEndpoint()]
        self.conn.create_consumer(self.topic, self.endpoints,
                                  fanout=False)
        self.conn.consume_in_threads()

    def get_plugin_type(self):
        return constants.L3_ROUTER_NAT

    def get_plugin_description(self):
        """Returns string description of the plugin."""
        return ("Brocade Vyatta Router Service Plugin for basic L3 forwarding "
                "between (L2) Neutron networks and access to external "
                "networks via a NAT gateway.")

    def create_router(self, context, router):
{'fraction_non_alphanumeric': 0.0505298725234219, 'fraction_numerical': 0.011518967900476117, 'mean_word_length': 3.3940620782726048, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469592', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1852, 'n_words': 663}