Junos.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:assimilator 作者: videlanicolas 项目源码 文件源码
def get(self):
        if not self.dev.connected:
            logger.error("{0}: Firewall timed out or incorrect device credentials.".format(self.firewall_config['name']))
            return {'error' : 'Could not connect to device.'}, 504
        else:
            logger.info("{0}: Connected successfully.".format(self.firewall_config['name']))
        try:
            rpc = etree.tostring(str(jns.rpc.get_security_policies_hit_count()), encoding='unicode')
        except Exception as e:
            logger.error("Error parsing rpc: {0}".format(str(e)))
            return {'error' : 'Error parsing soup.'}, 500
        finally:
            self.dev.close()
        soup = BS(rpc,'xml')
        entries = list()
        for hitcount in soup.find('policy-hit-count').children:
            if type(hitcount) != Tag or hitcount.name != 'policy-hit-count-entry':
                continue
            aux = {
            'count' : int(hitcount.find('policy-hit-count-count').text),
            'from' : hitcount.find('policy-hit-count-from-zone').text,
            'to' : hitcount.find('policy-hit-count-to-zone').text,
            'policy' : hitcount.find('policy-hit-count-policy-name').text
            }
            entries.append(aux)
        return {'len' : len(entries), 'hitcount' : entries}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号