<commit_before>#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2014 Metaswitch Networks.
# 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.
#
#
# Performs per host Calico configuration for Neutron.
# Based on the structure of the Linux Bridge agent in the
# Linux Bridge ML2 Plugin.
# @author: Metaswitch Networks

import os
import sys
import time

import eventlet
from oslo.config import cfg

from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import constants
from neutron.common import topics
from neutron.common import utils as q_utils
from neutron import context
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
from neutron.openstack.common.rpc import common as rpc_common
from neutron.openstack.common.rpc import dispatcher
from neutron.plugins.linuxbridge.common import config  # noqa
from neutron.plugins.linuxbridge.common import constants as lconst
from calico import common as calico_common

LOG = logging.getLogger(__name__)

TAP_INTERFACE_PREFIX = "tap"
TAP_FS = "/sys/devices/virtual/net/"


class CalicoManager(object):
    def __init__(self, interface_mappings, root_helper):
        LOG.debug('CalicoManager::__init__')
        self.interface_mappings = interface_mappings
        self.root_helper = root_helper
        self.ip = ip_lib.IPWrapper(self.root_helper)

    def get_tap_device_name(self, interface_id):
        LOG.debug('CalicoManager::get_tap_device_name')
        if not interface_id:
            LOG.warning(_("Invalid Interface ID, will lead to incorrect "
                          "tap device name"))
        tap_device_name = TAP_INTERFACE_PREFIX + interface_id[0:11]
        return tap_device_name

    def add_static_route(self, tap_device_name, fixed_ips, mac_address):
        LOG.warning('CalicoManager::add_static_route')
        result = True
        for ip_data in fixed_ips:
            ip_address = ip_data["ip_address"]
            LOG.info(_("Adding static route for %s via %s"),
                     ip_address, tap_device_name)
            route_out, route_err = utils.execute(
                ['ip', 'route', 'add', ip_address,
                 'dev', tap_device_name,
                 'proto', 'static'],<commit_msg>Drop the severity of function entry log to DEBUG.<commit_after>#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2014 Metaswitch Networks.
# 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.
#
#
# Performs per host Calico configuration for Neutron.
# Based on the structure of the Linux Bridge agent in the
# Linux Bridge ML2 Plugin.
# @author: Metaswitch Networks

import os
import sys
import time

import eventlet
from oslo.config import cfg

from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import constants
from neutron.common import topics
from neutron.common import utils as q_utils
from neutron import context
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
from neutron.openstack.common.rpc import common as rpc_common
from neutron.openstack.common.rpc import dispatcher
from neutron.plugins.linuxbridge.common import config  # noqa
from neutron.plugins.linuxbridge.common import constants as lconst
from calico import common as calico_common

LOG = logging.getLogger(__name__)

TAP_INTERFACE_PREFIX = "tap"
TAP_FS = "/sys/devices/virtual/net/"


class CalicoManager(object):
    def __init__(self, interface_mappings, root_helper):
        LOG.debug('CalicoManager::__init__')
        self.interface_mappings = interface_mappings
        self.root_helper = root_helper
        self.ip = ip_lib.IPWrapper(self.root_helper)

    def get_tap_device_name(self, interface_id):
        LOG.debug('CalicoManager::get_tap_device_name')
        if not interface_id:
            LOG.warning(_("Invalid Interface ID, will lead to incorrect "
                          "tap device name"))
        tap_device_name = TAP_INTERFACE_PREFIX + interface_id[0:11]
        return tap_device_name

    def add_static_route(self, tap_device_name, fixed_ips, mac_address):
        LOG.debug('CalicoManager::add_static_route')
        result = True
        for ip_data in fixed_ips:
            ip_address = ip_data["ip_address"]
            LOG.info(_("Adding static route for %s via %s"),
                     ip_address, tap_device_name)
            route_out, route_err = utils.execute(
                ['ip', 'route', 'add', ip_address,
                 'dev', tap_device_name,
                 'proto', 'static'],
{'fraction_non_alphanumeric': 0.0718552937271822, 'fraction_numerical': 0.004978426817125788, 'mean_word_length': 3.4777117384843983, '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': '4874634', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1650, 'n_words': 575}