From 2d38c742e84aebccd367eb7312ddaaeb0d02bc01 Mon Sep 17 00:00:00 2001 From: Moshe Levi Date: Tue, 30 Jun 2015 22:23:26 +0300 Subject: [PATCH] Generic Resources RPC This patch adds Generic Resource RPC from agent to server. Change-Id: I0ac8a009e781b6edb283d8634b1a2f047db092dc --- neutron/api/rpc/handlers/resources_rpc.py | 71 +++++++++++++++++++++++ neutron/common/constants.py | 2 + neutron/common/topics.py | 1 + neutron/plugins/ml2/plugin.py | 4 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 neutron/api/rpc/handlers/resources_rpc.py diff --git a/neutron/api/rpc/handlers/resources_rpc.py b/neutron/api/rpc/handlers/resources_rpc.py new file mode 100755 index 000000000..68ebc6580 --- /dev/null +++ b/neutron/api/rpc/handlers/resources_rpc.py @@ -0,0 +1,71 @@ +# Copyright (c) 2015 Mellanox Technologies, Ltd +# 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. + +from oslo_log import helpers as log_helpers +from oslo_log import log as logging +import oslo_messaging + +from neutron.api.rpc.callbacks import registry +from neutron.common import constants +from neutron.common import rpc as n_rpc +from neutron.common import topics + + +LOG = logging.getLogger(__name__) + + +class ResourcesServerRpcApi(object): + """Agent-side RPC (stub) for agent-to-plugin interaction. + + This class implements the client side of an rpc interface. The server side + can be found below: ResourcesServerRpcCallback. For more information on + changing rpc interfaces, see doc/source/devref/rpc_api.rst. + """ + + def __init__(self): + target = oslo_messaging.Target( + topic=topics.PLUGIN, version='1.0', + namespace=constants.RPC_NAMESPACE_RESOURCES) + self.client = n_rpc.get_client(target) + + @log_helpers.log_method_call + def get_info(self, context, resource_type, resource_id): + cctxt = self.client.prepare() + #TODO(Qos): add deserialize version object + return cctxt.call(context, 'get_info', + resource_type=resource_type, resource_id=resource_id) + + +class ResourcesServerRpcCallback(object): + """Plugin-side RPC (implementation) for agent-to-plugin interaction. + + This class implements the server side of an rpc interface. The client side + can be found above: ResourcesServerRpcApi. For more information on + changing rpc interfaces, see doc/source/devref/rpc_api.rst. + """ + + # History + # 1.0 Initial version + + target = oslo_messaging.Target( + version='1.0', namespace=constants.RPC_NAMESPACE_RESOURCES) + + def get_info(self, context, resource_type, resource_id): + kwargs = {'context': context} + #TODO(Qos): add serialize version object + return registry.get_info( + resource_type, + resource_id, + **kwargs) diff --git a/neutron/common/constants.py b/neutron/common/constants.py index d935273e5..408aaf8c3 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -174,6 +174,8 @@ RPC_NAMESPACE_SECGROUP = None RPC_NAMESPACE_DVR = None # RPC interface for reporting state back to the plugin RPC_NAMESPACE_STATE = None +# RPC interface for agent to plugin resources API +RPC_NAMESPACE_RESOURCES = None # Default network MTU value when not configured DEFAULT_NETWORK_MTU = 0 diff --git a/neutron/common/topics.py b/neutron/common/topics.py index 9bb1956e7..18acbcb7b 100644 --- a/neutron/common/topics.py +++ b/neutron/common/topics.py @@ -19,6 +19,7 @@ PORT = 'port' SECURITY_GROUP = 'security_group' L2POPULATION = 'l2population' DVR = 'dvr' +RESOURCES = 'resources' CREATE = 'create' DELETE = 'delete' diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index a56039d45..8a1d089d7 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -31,6 +31,7 @@ from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api from neutron.api.rpc.handlers import dhcp_rpc from neutron.api.rpc.handlers import dvr_rpc from neutron.api.rpc.handlers import metadata_rpc +from neutron.api.rpc.handlers import resources_rpc from neutron.api.rpc.handlers import securitygroups_rpc from neutron.api.v2 import attributes from neutron.callbacks import events @@ -150,7 +151,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, dvr_rpc.DVRServerRpcCallback(), dhcp_rpc.DhcpRpcCallback(), agents_db.AgentExtRpcCallback(), - metadata_rpc.MetadataRpcCallback() + metadata_rpc.MetadataRpcCallback(), + resources_rpc.ResourcesServerRpcCallback() ] def _setup_dhcp(self): -- 2.45.2