def free_hosts_and_busy(self, as_int=None, page=None):
pods = PodIP.filter_by(network=self.network)
allocated_ips = {int(pod): pod.get_pod() for pod in pods}
blocked_ips = self.get_blocked_set(as_int=True)
hosts = self.hosts(as_int=True, page=page)
def get_ip_state(ip, pod):
if pod:
return 'busy'
if ip in blocked_ips:
return 'blocked'
return 'free'
def get_ip_info(ip):
pod = allocated_ips.get(ip)
state = get_ip_state(ip, pod)
return ip if as_int else str(ipaddress.ip_address(ip)), pod, state
return [get_ip_info(ip) for ip in hosts]
评论列表
文章目录