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

  • 相关阅读:
    [转]《三国演义》人名英文翻译妙评 你也来评评!
    Effective C++:改善程序技术与设计思维的55个有效做法(第三版)(中文版)(预订)Effective C++ 3RD
    A Closer Look At Parallax Occlusion Mapping
    [转]收录全部作品,《寂静岭套装》发售开始
    [转]程序员版《桃花庵》
    Cg 1.5 Beta 2
    FilteredTextBox控件
    CollapsiblePanel控件
    DynamicPopulate控件
    HoverMenu控件的使用
  • 原文地址:https://www.cnblogs.com/allcloud/p/5488766.html
Copyright © 2011-2022 走看看