zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    设计模式学习系列3 观察者模式
    设计模式学习系列2 面向对象的5大原则(转)
    设计模式学习系列1 单例模式
    又见到面试的毕业生
    猎头给我打电话
    DirectX基础学习系列8 渐进网格以及外接体
    directX基础学习系列7 网格(自己创建)
    DirectX 基础学习系列6 字体
    语艺杂谈1 – MAP赋值与插入
    DirectX基础学习系列5 融合技术
  • 原文地址:https://www.cnblogs.com/allcloud/p/5488766.html
Copyright © 2011-2022 走看看