🪐
OpenStack 源码分析之 Neutron
  • 前言
  • 整体结构
  • bin
  • doc
  • etc
    • init.d/
    • neutron/
    • api-paste.ini
    • dhcp_agent.ini
    • fwaas_driver.ini
    • l3_agent.ini
    • lbaas_agent.ini
    • metadata_agent.ini
    • metering_agent.ini
    • vpn_agent.ini
    • neutron.conf
    • policy.json
    • rootwrap.conf
    • services.conf
  • neutron
    • agent
      • common/
      • linux/
      • metadata/
      • dhcp_agent.py
      • firewall.py
      • l2population_rpc.py
      • l3_agent.py
      • l3_ha_agent.py
      • netns_cleanup_util.py
      • ovs_cleanup_util.py
      • rpc.py
      • securitygroups_rpc.py
    • api
      • rpc
      • v2
      • views
      • api_common.py
      • extensions.py
      • versions.py
    • cmd
    • common
      • config.py
      • constants.py
      • exceptions.py
      • ipv6_utils.py
      • log.py
      • rpc.py
      • test_lib.py
      • topics.py
      • utils.py
    • db
      • agents_db.py
      • agentschedulers_db.py
      • api.py
      • common_db_mixin.py
      • db_base_plugin_v2.py
      • migration
      • model_base.py
      • models_v2.py
      • securitygroups_rpc_base.py
      • sqlalchemyutils.py
      • 扩展资源和操作类
        • allowedaddresspairs_db.py
        • dvr_mac_db.py
        • external_net_db.py
        • extradhcpopt_db.py
        • extraroute_db.py
        • firewall
        • l3_agentschedulers_db.py
        • l3_attrs_db.py
        • l3_db.py
        • l3_dvr_db.py
        • l3_dvrscheduler_db.py
        • l3_gwmode_db.py
        • l3_hamode_db.py
        • l3_hascheduler_db.py
        • loadbalancer
        • metering
        • portbindings_base.py
        • portbindings_db.py
        • portsecurity_db.py
        • quota_db.py
        • routedserviceinsertion_db.py
        • routerservicetype_db.py
        • securitygroups_db.py
        • servicetype_db.py
        • vpn
    • debug
      • commands.py
      • debug_agent.py
      • shell.py
    • extensions
      • agent.py
      • allowedaddresspairs.py
      • dhcpagentscheduler.py
      • dvr.py
      • external_net.py
      • extraroute.py
      • extra_dhcp_opt.py
      • firewall.py
      • flavor.py
      • l3.py
      • l3agentscheduler.py
      • l3_ext_gw_mode.py
      • l3_ext_ha_mode.py
      • lbaas_agentscheduler.py
      • loadbalancer.py
      • metering.py
      • multiprovidernet.py
      • portbindings.py
      • portsecurity.py
      • providernet.py
      • quotasv2.py
      • routedserviceinsertion.py
      • routerservicetype.py
      • securitygroup.py
      • servicetype.py
      • vpnaas.py
      • init.py
    • hacking
      • checks.py
      • init.py
    • locale
    • notifiers
      • nova.py
      • init.py
    • openstack
      • common
        • cache
        • context.py
        • eventlet_backdoor.py
        • fileutils.py
        • fixture
        • local.py
        • lockutils.py
        • log.py
        • loopingcall.py
        • middleware
        • periodic_task.py
        • policy.py
        • processutils.py
        • service.py
        • systemd.py
        • threadgroup.py
        • uuidutils.py
        • versionutils.py
        • _i18n.py
    • plugins
      • bigswitch
        • agent
        • config.py
        • db
        • extensions
        • l3_router_plugin.py
        • plugin.py
        • routerrule_db.py
        • servermanager.py
        • tests
        • vcsversion.py
        • version.py
        • init.py
      • brocade
        • db
        • NeutronPlugin.py
        • nos
        • tests
        • vlanbm.py
        • init.py
      • cisco
        • cfg_agent
        • common
        • db
        • extensions
        • l2device_plugin_base.py
        • l3
        • models
        • n1kv
        • network_plugin.py
        • service_plugins
        • init.py
      • common
        • constants.py
        • utils.py
        • init.py
      • embrane
        • agent
        • base_plugin.py
        • common
        • l2base
        • plugins
        • init.py
      • hyperv
        • agent
        • agent_notifier_api.py
        • common
        • db.py
        • hyperv_neutron_plugin.py
        • model.py
        • rpc_callbacks.py
        • init.py
      • ibm
        • agent
        • common
        • sdnve_api.py
        • sdnve_api_fake.py
        • sdnve_neutron_plugin.py
      • linuxbridge
        • agent
        • common
        • db
        • init.py
      • metaplugin
        • common
        • meta_db_v2.py
        • meta_models_v2.py
        • meta_neutron_plugin.py
        • proxy_neutron_plugin.py
        • init.py
      • midonet
        • agent
        • common
        • midonet_lib.py
        • plugin.py
        • init.py
      • ml2
        • common
        • config.py
        • db.py
        • drivers
        • driver_api.py
        • driver_context.py
        • managers.py
        • models.py
        • plugin.py
        • rpc.py
      • mlnx
        • agent
        • agent_notify_api.py
        • common
        • db
        • mlnx_plugin.py
        • rpc_callbacks.py
        • init.py
      • nec
        • agent
        • common
        • db
        • drivers
        • extensions
        • nec_plugin.py
        • nec_router.py
        • ofc_driver_base.py
        • ofc_manager.py
        • packet_filter.py
        • router_drivers.py
        • init.py
      • nuage
        • common
        • extensions
        • nuagedb.py
        • nuage_models.py
        • plugin.py
        • syncmanager.py
        • init.py
      • ofagent
        • agent
        • common
      • oneconvergence
        • agent
        • lib
        • plugin.py
        • init.py
      • opencontrail
        • common
        • contrail_plugin.py
        • init.py
      • openvswitch
        • agent
        • common
        • ovs_models_v2.py
        • init.py
      • plumgrid
        • common
        • drivers
        • plumgrid_plugin
        • init.py
      • sriovnicagent
        • common
        • eswitch_manager.py
        • pci_lib.py
        • sriov_nic_agent.py
        • init.py
      • vmware
        • api_client
        • check_nsx_config.py
        • common
        • dbexts
        • dhcpmeta_modes.py
        • dhcp_meta
        • extensions
        • nsxlib
        • nsx_cluster.py
        • plugin.py
        • plugins
        • shell
        • vshield
        • init.py
    • scheduler
      • dhcp_agent_scheduler.py
      • l3_agent_scheduler.py
    • server
    • service.py
    • services
      • firewall
        • agents
        • drivers
        • fwaas_plugin.py
      • l3_router
        • brocade
        • l3_apic.py
        • l3_arista.py
        • l3_router_plugin.py
        • init.py
      • loadbalancer
        • agent
        • agent_scheduler.py
        • constants.py
        • drivers
        • plugin.py
      • metering
        • agents
        • drivers
        • metering_plugin.py
      • provider_configuration.py
      • service_base.py
      • vpn
        • agent.py
        • common
        • device_drivers
        • plugin.py
        • service_drivers
        • init.py
      • init.py
    • tests
      • base.py
      • common
        • agents
        • init.py
      • etc
        • rootwrap.d
      • fake_notifier.py
      • functional
        • agent
        • base.py
        • contrib
        • db
        • sanity
        • init.py
      • post_mortem_debug.py
      • tools.py
      • unit
      • var
      • init.py
    • auth.py
    • context.py
    • hooks.py
    • i18n.py
    • manager.py
    • neutron_plugin_base_v2.py
    • policy.py
    • quota.py
    • service.py
    • version.py
    • wsgi.py
  • rally-jobs
    • extra
      • README.rst
    • plugins
      • README.rst
      • init.py
    • neutron-neutron.yaml
    • README.rst
  • tools
    • check_bash.sh
    • check_i18n.py
    • check_i18n_test_case.txt
    • clean.sh
    • i18n_cfg.py
    • install_venv.py
    • install_venv_common.py
    • pretty_tox.sh
    • with_venv.sh
  • 理解代码
    • 调用逻辑
    • REST API 专题
    • RPC 专题
      • agent RPC
      • plugin RPC
      • neutron-server RPC
    • Plugin 专题
    • Extension 专题
    • Agent 专题
    • Driver 专题
Powered by GitBook
On this page
  • agentnotifiers
  • handler

Was this helpful?

  1. neutron
  2. api

rpc

agentnotifiers

主要负责发出一些rpc的通知给agent,包括三个文件:dhcp_rpc_agent_api.py、l3_rpc_agent_api.py、metering_rpc_agent_api.py。 分别实现向dhcp、l3或者metering的agent发出通知消息。

以dhcp_rpc_agent_api.py为例,定义了DhcpAgentNotifyAPI类,该类继承自neutron.common.rpc.RpcProxy。

首先定义允许对agent操作的资源和方法。

VALID_RESOURCES = ['network', 'subnet', 'port']
    VALID_METHOD_NAMES = ['network.create.end',
                          'network.update.end',
                          'network.delete.end',
                          'subnet.create.end',
                          'subnet.update.end',
                          'subnet.delete.end',
                          'port.create.end',
                          'port.update.end',
                          'port.delete.end']

实现的方法包括agent_updated()、network_added_to_agent()、network_removed_from_agent(),分别cast一条rpc消息到dhcp agent,调用对应方法。

 def _cast_message(self, context, method, payload, host,
                      topic=topics.DHCP_AGENT):
        """Cast the payload to the dhcp agent running on the host."""
        self.cast(
            context, self.make_msg(method, payload=payload),topic='%s.%s' % (topic, host))

def network_removed_from_agent(self, context, network_id, host):
        self._cast_message(context, 'network_delete_end',
                           {'network_id': network_id}, host)

def network_added_to_agent(self, context, network_id, host):
        self._cast_message(context, 'network_create_end',
                           {'network': {'id': network_id}}, host)

def agent_updated(self, context, admin_state_up, host):
        self._cast_message(context, 'agent_updated',
                           {'admin_state_up': admin_state_up}, host)

另外,实现notify()方法,可以调用所允许的方法。 neutron的api中会直接调用notify()方法。

def notify(self, context, data, method_name):
        # data is {'key' : 'value'} with only one key
        if method_name not in self.VALID_METHOD_NAMES:
            return
        obj_type = data.keys()[0]
        if obj_type not in self.VALID_RESOURCES:
            return
        obj_value = data[obj_type]
        network_id = None
        if obj_type == 'network' and 'id' in obj_value:
            network_id = obj_value['id']
        elif obj_type in ['port', 'subnet'] and 'network_id' in obj_value:
            network_id = obj_value['network_id']
        if not network_id:
            return
        method_name = method_name.replace(".", "_")
        if method_name.endswith("_delete_end"):
            if 'id' in obj_value:
                self._notify_agents(context, method_name,
                                    {obj_type + '_id': obj_value['id']},
                                    network_id)
        else:
            self._notify_agents(context, method_name, data, network_id)

整体API的agent 通知调用的主要调用结构如下图所示。

handler

包括dvr_rpc.py文件。 其中定义了对dvr服务两端的rpc的api和callback类,包括DVRServerRpcApiMixin、DVRServerRpcCallbackMixin、DVRAgentRpcApiMixin、DVRAgentRpcCallbackMixin。

PreviousapiNextv2

Last updated 5 years ago

Was this helpful?