RPC在neutron中的应用

来源:互联网 发布:诲女知之乎的语气 编辑:程序博客网 时间:2024/06/04 20:12

neutron-plugin中的RPC

主要对ML2Plugin进行分析,包括两个类:RpcCallbacks和AgentNotifierApi。

  • RpcCallbacks:负责当agent往plugin发出rpc请求时候,plugin实现请求的相关动作,除了继承自父类(dhcp rpc、dvr rpc、sg_db rpc和tunnel rpc)中的方法,还包括get_port_from_device、get_device_details、get_devices_details_list、update_device_down、update_device_up、get_dvr_mac_address_by_host、get_compute_ports_on_host_by_subnet、get_subnet_for_dvr等方法。

  • AgentNotifierApi:负责当plugin往agent发出rpc请求(plugin通知agent)的时候,plugin端的方法。

    def start_rpc_listeners(self):         """RpcCallbacks中实现的方法:Start the RPC loop to let the plugin communicate with agents."""        self._setup_rpc()        self.topic = topics.PLUGIN        self.conn = n_rpc.create_connection(new=True)        self.conn.create_consumer(self.topic, self.endpoints, fanout=False)        return self.conn.consume_in_threads()

创建一个通知rpc的客户端,用于向OVS的agent发出通知。所有plugin都需要有这样一个发出通知消息的客户端,创建了一个OVS agent的通知rpc客户端。之后,创建两个跟service agent相关的consumer,分别监听topics.PLUGIN

ovs_neutron_agent也会创建RPC的consumer,用来监听topics.UPDATE、topics.DELETE等操作。

def setup_rpc(self):        self.agent_id = 'ovs-agent-%s' % self.conf.host        self.topic = topics.AGENT        self.plugin_rpc = OVSPluginApi(topics.PLUGIN)        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)        self.dvr_plugin_rpc = dvr_rpc.DVRServerRpcApi(topics.PLUGIN)        self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)        # RPC network init        self.context = context.get_admin_context_without_session()        # Handle updates from service        self.endpoints = [self]        # Define the listening consumers for the agent        consumers = [[topics.PORT, topics.UPDATE],                     [topics.PORT, topics.DELETE],                     [constants.TUNNEL, topics.UPDATE],                     [constants.TUNNEL, topics.DELETE],                     [topics.SECURITY_GROUP, topics.UPDATE],                     [topics.DVR, topics.UPDATE],                     [topics.NETWORK, topics.UPDATE]]
0 0
原创粉丝点击