neutron dhcp agent流程分析

1、main函数入口

/neutron/agent/dhcp_agent.py

def main():
    register_options(cfg.CONF)
    common_config.init(sys.argv[1:])
    config.setup_logging()
    server = neutron_service.Service.create(
        binary='neutron-dhcp-agent',
        topic=topics.DHCP_AGENT,
        report_interval=cfg.CONF.AGENT.report_interval,
        manager='neutron.agent.dhcp.agent.DhcpAgentWithStateReport')
    service.launch(cfg.CONF, server).wait()

调用Service类的create方法创建一个Service对象,通过launch方法来启动DHCP agent服务。

create()方法位于/neutron/service.py,准备各种参数,包含主机名、服务名、主题、间隔时间。

launch()方法位于oslo_service,根据服务数创建进程数,launch()方法会调用到/neutron/service.py中的start()方法,launcher对象的wait()方法启动创建的线程。

 

2、DHCP agent服务的Manager类DhcpAgentWithStateReport

/neutron/agent/dhcp/agent.py

DhcpAgentWithStateReport类继承DhcpAgent类,定义了一个定时任务,报告DHCP agent服务的状态。

DhcpAgent类初始化方法主要获取配置文件dhcp_agent.ini中的配置项,调用了核心方法_populate_network_cache()方法,查询和缓存所有启用DHCP功能的网络。

def _populate_networks_cache(self):
        """Populate the networks cache when the DHCP-agent starts."""
        try:
            existing_networks = self.dhcp_driver_cls.existing_dhcp_networks(
                self.conf
            )
            for net_id in existing_networks:
                net =dhcp.NetModel({"id": net_id, "subnets": [],
                                     "non_local_subnets": [], "ports": []})
                self.cache.put(net)
        except NotImplementedError:
            # just go ahead with an empty networks cache
            LOG.debug("The '%s' DHCP-driver does not support retrieving of a "
                      "list of existing networks",
                      self.conf.dhcp_driver)

existing_dhcp_networks()方法位于/neutron/agent/linux/dhcp.py,获取存储dhcp

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值