aa07ab62af
This patch fix the issue by changing the call to find the plugin which handles the l3 which is now the l3_router service plugin instead of the old mixin. Also change the unit tests to use the l3 service plugin instead of the l3 mixin and refactor the rpc callbacks part. Co-Authored-By: Ala Rezmerita <ala.rezmerita@cloudwatt.com> Closes-bug: #1257354 Change-Id: Ide26f825005fa63cd3fcc75fa91fffb947e0be7a
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
|
#
|
|
# Author: Sylvain Afchain <sylvain.afchain@enovance.com>
|
|
#
|
|
# 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.common import constants as consts
|
|
from neutron.common import rpc as p_rpc
|
|
from neutron.common import utils
|
|
from neutron import manager
|
|
from neutron.openstack.common import log as logging
|
|
from neutron.plugins.common import constants as service_constants
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class MeteringRpcCallbacks(object):
|
|
|
|
RPC_API_VERSION = '1.0'
|
|
|
|
def __init__(self, meter_plugin):
|
|
self.meter_plugin = meter_plugin
|
|
|
|
def create_rpc_dispatcher(self):
|
|
return p_rpc.PluginRpcDispatcher([self])
|
|
|
|
def get_sync_data_metering(self, context, **kwargs):
|
|
l3_plugin = manager.NeutronManager.get_service_plugins().get(
|
|
service_constants.L3_ROUTER_NAT)
|
|
if not l3_plugin:
|
|
return
|
|
|
|
host = kwargs.get('host')
|
|
if not utils.is_extension_supported(
|
|
l3_plugin, consts.L3_AGENT_SCHEDULER_EXT_ALIAS) or not host:
|
|
return self.meter_plugin.get_sync_data_metering(context)
|
|
else:
|
|
agents = l3_plugin.get_l3_agents(context, filters={'host': [host]})
|
|
if not agents:
|
|
LOG.error(_('Unable to find agent %s.'), host)
|
|
return
|
|
|
|
routers = l3_plugin.list_routers_on_l3_agent(context, agents[0].id)
|
|
router_ids = [router['id'] for router in routers['routers']]
|
|
if not router_ids:
|
|
return
|
|
|
|
return self.meter_plugin.get_sync_data_metering(context,
|
|
router_ids=router_ids)
|