Neutron RPC API Layer
Client Side
Here is an example of an rpc client definition:
import oslo_messaging from neutron.common import rpc as n_rpc class ClientAPI(object):
"""Client side RPC interface definition. API version history:
1.0 - Initial version
1.1 - Added my_remote_method_2
""" def __init__(self, topic):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target) def my_remote_method(self, context, arg1, arg2):
cctxt = self.client.prepare()
return cctxt.call(context, 'my_remote_method', arg1=arg1, arg2=arg2) def my_remote_method_2(self, context, arg1):
cctxt = self.client.prepare(version='1.1')
return cctxt.call(context, 'my_remote_method_2', arg1=arg1)
my_remote_method 在v1中,
my_remote_method_2 v1.1中,当调用这个api是,其指定了server端至少实现了v1.1
Server Side
The server side of an rpc interface looks like this:
import oslo_messaging class ServerAPI(object): target = oslo_messaging.Target(version='1.1') def my_remote_method(self, context, arg1, arg2):
return 'foo' def my_remote_method_2(self, context, arg1):
return 'bar'
server端说明了支持v1.1
Versioning
rpc interfaces change必须向后兼容。server必须在同一大版本下支持旧的client。
Example Change
比如说my_remote_method_2里增加一个参数,该参数必须有个default值向后兼容,升级小版本
server side code would look like this:
import oslo_messaging class ServerAPI(object): target = oslo_messaging.Target(version='1.2') def my_remote_method(self, context, arg1, arg2):
return 'foo' def my_remote_method_2(self, context, arg1, arg2=None):
if not arg2:
# Deal with the fact that arg2 was not specified if needed.
return 'bar'
The client must also specify that version ‘1.2’ is required for this method call to be successful.
import oslo_messaging from neutron.common import rpc as n_rpc class ClientAPI(object):
"""Client side RPC interface definition. API version history:
1.0 - Initial version
1.1 - Added my_remote_method_2
1.2 - Added arg2 to my_remote_method_2
""" def __init__(self, topic):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target) def my_remote_method(self, context, arg1, arg2):
cctxt = self.client.prepare()
return cctxt.call(context, 'my_remote_method', arg1=arg1, arg2=arg2) def my_remote_method_2(self, context, arg1, arg2):
cctxt = self.client.prepare(version='1.2')
return cctxt.call(context, 'my_remote_method_2',
arg1=arg1, arg2=arg2)
Example: DHCP
The DHCP agent includes a client API, neutron.agent.dhcp.agent.DhcpPluginAPI.
The server side is defined in neutron.api.rpc.handlers.dhcp_rpc.DhcpRpcCallback.
Similarly, there is an RPC interface defined that allows the Neutron plugin to remotely invoke methods in the DHCP agent.
The client side is defined in neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.DhcpAgentNotifyApi.
The server side of this interface that runs in the DHCP agent is neutron.agent.dhcp.agent.DhcpAgent.
http://docs.openstack.org/developer/neutron/devref/rpc_api.html
最新文章
- 转:Delphi的类与继承(VB与delphi比较)
- spring简单介绍
- Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量
- mldn android
- 【不积跬步,无以致千里】mysql 多行合并函数
- [js高手之路]Node.js模板引擎教程-jade速学与实战4-模板引用,继承,插件使用
- wireshark_帧信息
- HTTP协议初步解析
- 关于使用format()方法格式化字符串,读这一篇就够了!
- Font Awesome 供更精准的图标搜索
- Count the string kmp
- windows下如何批量修改文件名
- Django 之Redis配置
- angular的启动原理
- superset----缓存之redis
- [UOJ#276][清华集训2016]汽水[分数规划+点分治]
- ubuntu14.04-64位机配置android开发环境,ADT,sdk,eclipsea
- 求组合数 C++程序
- R语言学习——欧拉计划(3)Largest prime factor 求最大质因数
- php imagecreatetruecolor()方法报未定义错误解决方法