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

Neutron RPC API Layer的更多相关文章

  1. 人人都是 API 设计师:我对 RESTful API、GraphQL、RPC API 的思考

    原文地址:梁桂钊的博客 博客地址:http://blog.720ui.com 欢迎关注公众号:「服务端思维」.一群同频者,一起成长,一起精进,打破认知的局限性. 有一段时间没怎么写文章了,今天提笔写一 ...

  2. Omnicore RPC API中文文档

    2019独角兽企业重金招聘Python工程师标准>>> OmniCore是比特币核心的一个分支,它在比特币协议之上实现了一个新的Omni协议层,用于代币发行.众售等应用,USDT就是 ...

  3. supervisord支持扩展(xml RPC API & Third Party Applications and Libraries)

    XML-RPC API Documentation http://www.supervisord.org/api.html Third Party Applications and Libraries ...

  4. [转]BTC RPC API GetTransaction

    本文转自: GetTransaction GetTransaction gettransaction调用获取指定钱包内交易的详细信息.该调用需要节点 启用钱包功能. 参数 TXID:要查看详情的交易I ...

  5. nova event

    nova处理neutron发送过来的event事件.暂时追踪nova event部分代码 tail -f /var/log/nova/nova-api.log  下面就是一个事件  Creating ...

  6. 【转】Git代码提交最佳实践

      GIT Commit Good Practice The following document is based on experience doing code development, bug ...

  7. 以太坊RPC机制与API实例

    上一篇文章介绍了以太坊的基础知识,我们了解了web3.js的调用方式是通过以太坊RPC技术,本篇文章旨在研究如何开发.编译.运行与使用以太坊RPC接口. 关键字:以太坊,RPC,JSON-RPC,cl ...

  8. neutron 的 quota design

    发现, cinder, nova 制实现了, CountableResource. 只有nuetron实现了 TrackedResource 和 CountableResource. I read u ...

  9. neutron qos Quality of Service

    Quality of Service advanced service is designed as a service plugin. The service is decoupled from t ...

随机推荐

  1. Python内置函数之range()

    range(stop)range(start,stop[,step]) 返回一个range对象,第三个参数的含义为:间隔的个数. range对象同时也是可迭代对象. >>> isin ...

  2. Unity UGUI——提供可视功能的UI组件(Text)

    基本属性介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTXJfQUhhbw==/font/5a6L5L2T/fontsize/400/fill/I0J ...

  3. mac上搭建docker镜像私服

    1.创建私服容器 docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /opt/data/registry:/t ...

  4. python 求下个月的最后一天

    [1]根据当前月求上个月.下个月的最后一天 (1)求当前月最后一天 (2)求前一个月的最后一天 (3)求下一个月的最后一天 学习示例与应用实例,代码如下: #!/usr/bin/python3 #-* ...

  5. 走进Struts2(五)— 值栈和OGNL

    值栈 1.值栈是什么? 简单说:就是相应每个请求对象的轻量级的内存数据中心. Struts2引入值栈最大的优点就是:在大多数情况下,用户根本无须关心值栈,无论它在哪里,不用管它里面有什么,仅仅须要去获 ...

  6. Unity合并选中物体的Mesh

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; pu ...

  7. 自定义列表数据自动循环向下滚动view(类似于通知通报消息)

    首先申明,这个自定义View不是本人写的,大神写的,本人仅限学习一级研究使用 直接上代码吧!后面我再解释一遍 package com.egojit.android.gcoa.views; import ...

  8. phpcms的基础知识和配置

    一.设置界面 1.站点设置:相当于服务器上的站点 (1)站点修改:“关键词”和“描述”的修改,便于网络优化和搜索引擎对本网站的搜索. (2)点击站点后边的修改,模板的修改,引用自己模板 2.基本设置: ...

  9. 【BZOJ4542】[Hnoi2016]大数 莫队

    [BZOJ4542][Hnoi2016]大数 Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小B还有一个 ...

  10. java操作文件流对象

    所有流对象 InputStream 字节流         FileInputStream 字节流 专门读写非文本文件的         BufferedInputStream 高效流 OutPutS ...