nebula_ip_pool.py 文件源码

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

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
def get_free_ip_list(self, net):
        # type: (oca.VirtualNetworkPool) -> list[str]
        """
        Returns the set of free IP addresses in the given network

        :param net: oca.VirtualNetworkPool
        :return: a set of IPv4 addresses
        """
        ip_list, used_ip_list = set(), set()

        for r in net.address_ranges:
            start_ip = int(IPv4Address(unicode(r.ip)))
            end_ip = start_ip + r.size

            for ip in range(start_ip, end_ip):
                ip_list.add(str(IPv4Address(ip)))
            for lease in r.leases:
                used_ip_list.add(lease.ip)

        free_ips = list(ip_list - used_ip_list)
        random.shuffle(free_ips)
        return free_ips
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号