api.py 文件源码

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

项目:nav 作者: UNINETT 项目源码 文件源码
def usage(self, request, *args, **kwargs):
        "Return usage for Prefix.pk == pk"
        pk = kwargs.pop("pk", None)
        prefix = Prefix.objects.get(pk=pk)
        max_addr = IP(prefix.net_address).len()
        active_addr = prefix_collector.collect_active_ip(prefix)
        # calculate allocated ratio
        query = PrefixQuerysetBuilder().within(prefix.net_address)
        allocated = query.finalize().exclude(vlan__net_type="scope")
        total_allocated = sum(p.get_prefix_size() for p in allocated)
        payload = {
            "max_addr": max_addr,
            "active_addr": active_addr,
            "usage": 1.0 * active_addr / max_addr,
            "allocated": 1.0 * total_allocated / max_addr,
            "pk": pk
        }
        return Response(payload, status=status.HTTP_200_OK)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号