]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Generic Resources RPC
authorMoshe Levi <moshele@mellanox.com>
Tue, 30 Jun 2015 19:23:26 +0000 (22:23 +0300)
committerIhar Hrachyshka <ihrachys@redhat.com>
Thu, 2 Jul 2015 13:51:10 +0000 (13:51 +0000)
This patch adds Generic Resource RPC from agent to server.

Change-Id: I0ac8a009e781b6edb283d8634b1a2f047db092dc

neutron/api/rpc/handlers/resources_rpc.py [new file with mode: 0755]
neutron/common/constants.py
neutron/common/topics.py
neutron/plugins/ml2/plugin.py

diff --git a/neutron/api/rpc/handlers/resources_rpc.py b/neutron/api/rpc/handlers/resources_rpc.py
new file mode 100755 (executable)
index 0000000..68ebc65
--- /dev/null
@@ -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)
index d935273e52764b85a3f8bce656c37d7e50266652..408aaf8c375e2c7bf82a3146f79d4da665b1c7ec 100644 (file)
@@ -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
index 9bb1956e7e8f68e897d67daf9a21b4b425b81dd5..18acbcb7bacc1a3101eafec94b57c9ad6333ff56 100644 (file)
@@ -19,6 +19,7 @@ PORT = 'port'
 SECURITY_GROUP = 'security_group'
 L2POPULATION = 'l2population'
 DVR = 'dvr'
+RESOURCES = 'resources'
 
 CREATE = 'create'
 DELETE = 'delete'
index a56039d4548119039d8ad5b4538e902454baea61..8a1d089d72456da04b44281a2813c8100a1a49fc 100644 (file)
@@ -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):