neutron metering agent在dvr模式下无法采集流量

提问于 2018-12-03 01:25:44 -0500

suzj 图像

以pike版本为例: neutron\services\metering\drivers\iptables\iptables_driver.py:238

def _process_ns_specific_metering_label(self, router, ext_dev, im):
    '''Process metering label based on the associated namespaces.'''
    rm = self.routers.get(router['id'])
    with IptablesManagerTransaction(im):
        labels = router.get(constants.METERING_LABEL_KEY, [])
        for label in labels:
            label_id = label['id']

            label_chain = iptables_manager.get_chain_name(
                WRAP_NAME + LABEL + label_id, wrap=False)

            rules_chain = iptables_manager.get_chain_name(
                WRAP_NAME + RULE + label_id, wrap=False)

            exists = rm.metering_labels.get(label_id)
            if not exists:
                self._create_metering_label_chain(rm,
                                                  label_chain,
                                                  rules_chain)
                rm.metering_labels[label_id] = label

            rules = label.get('rules')
            if rules:
                self._process_metering_label_rules(
                    rules, label_chain, rules_chain, ext_dev, im)

def _process_associate_metering_label(self, router):
    self._update_router(router)
    rm = self.routers.get(router['id'])

    ext_dev, ext_snat_dev = self.get_external_device_names(rm)
    for (im, dev) in [(rm.iptables_manager, ext_dev),
                      (rm.snat_iptables_manager, ext_snat_dev)]:
        if im:
            self._process_ns_specific_metering_label(router, dev, im)

metering始终先处理qrouter-xxx的iptables,再处理snat-xxx的iptables. 当处理qrouter-xxx的时候238行的exists为False,这样会处理qrouter的metering。但是下次循环处理到这里的时候exists为True, snat-xxx不再增加neutron-mtering-l-xxx neutron-metering-r-xxx链,这样snat-xxx就不能采集流量了。

另外,这段代码:

def get_external_device_names(self, rm):
        gw_port_id = rm.router.get('gw_port_id')
        if not gw_port_id:
            return None, None

        # NOTE (Swami): External device 'qg' should be used on the
        # Router namespace if the router is legacy and should be used on
        # SNAT namespace if the router is distributed.
        ext_dev = (EXTERNAL_DEV_PREFIX +
                   gw_port_id)[:self.driver.DEV_NAME_LEN]
        ext_snat_dev = (ROUTER_2_FIP_DEV_PREFIX +
                        rm.id)[:self.driver.DEV_NAME_LEN]
        return ext_dev, ext_snat_dev

ext_dev在snat-xxx命名空间, ext_snat_dev在qrouter-xxx命名空间, for (im, dev) in [(rm.iptables_manager, ext_dev),(rm.snat_iptables_manager, ext_snat_dev)] 这样的循环不是有问题吗? 求助,有谁能告诉我dvr模式下metering agent怎么配置才是对的?

edit retag flag offensive close merge delete