From 566be7bd258a741311d7d3ebcf31ca06bf7ce0b2 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 10 Feb 2015 16:15:59 -0500 Subject: [PATCH] Scope state reporting rpc api using a messaging namespace This patch does a couple of things. First it adds docstrings to the client/server pair of the rpc interface used by an agent to report state back to the plugin. The docs tell you where the other side of the interface is found in the code, and where docs are that give more info on the rules for changing them. The second thing done in this patch is to scope this interface using a messaging namespace. Right now some plugins expose several interfaces via the default namespace. This effectively means they are a single API and should be managed with a single version stream. It's much more managable to just treat these as separate interfaces and this change makes that explicit and functionally true. Now when a method is invoked, the only classes considered for handling that request will be ones marked with the right namespace. Part of blueprint rpc-docs-and-namespaces. Change-Id: I832db5c81780d98157a68d4abaf9787ba00adbeb --- neutron/agent/rpc.py | 10 +++++++++- neutron/common/constants.py | 2 ++ neutron/db/agents_db.py | 11 +++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/neutron/agent/rpc.py b/neutron/agent/rpc.py index 9909856e0f3..297b88c2c5a 100644 --- a/neutron/agent/rpc.py +++ b/neutron/agent/rpc.py @@ -17,6 +17,7 @@ import itertools import oslo_messaging from oslo_utils import timeutils +from neutron.common import constants from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.i18n import _LW @@ -57,8 +58,15 @@ def create_consumers(endpoints, prefix, topic_details, start_listening=True): class PluginReportStateAPI(object): + """RPC client used to report state back to plugin. + + This class implements the client side of an rpc interface. The server side + can be found in neutron.db.agents_db.AgentExtRpcCallback. For more + information on changing rpc interfaces, see doc/source/devref/rpc_api.rst. + """ def __init__(self, topic): - target = oslo_messaging.Target(topic=topic, version='1.0') + target = oslo_messaging.Target(topic=topic, version='1.0', + namespace=constants.RPC_NAMESPACE_STATE) self.client = n_rpc.get_client(target) def report_state(self, context, agent_state, use_call=False): diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 26d6724bd78..4b16165a074 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -153,3 +153,5 @@ RPC_NAMESPACE_METADATA = 'metadata' RPC_NAMESPACE_SECGROUP = 'secgroup' # RPC interface for agent to plugin DVR api RPC_NAMESPACE_DVR = 'dvr' +# RPC interface for reporting state back to the plugin +RPC_NAMESPACE_STATE = 'report_state' diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index 545039ef224..6cae2084be1 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -25,6 +25,7 @@ from sqlalchemy.orm import exc from sqlalchemy import sql from neutron.api.v2 import attributes +from neutron.common import constants from neutron.db import model_base from neutron.db import models_v2 from neutron.extensions import agent as ext_agent @@ -220,9 +221,15 @@ class AgentDbMixin(ext_agent.AgentPluginBase): class AgentExtRpcCallback(object): - """Processes the rpc report in plugin implementations.""" + """Processes the rpc report in plugin implementations. - target = oslo_messaging.Target(version='1.0') + This class implements the server side of an rpc interface. The client side + can be found in neutron.agent.rpc.PluginReportStateAPI. For more + information on changing rpc interfaces, see doc/source/devref/rpc_api.rst. + """ + + target = oslo_messaging.Target(version='1.0', + namespace=constants.RPC_NAMESPACE_STATE) START_TIME = timeutils.utcnow() def __init__(self, plugin=None):