def dc_subnet_ip_list(request, network, netmask, vlan_id):
context = collect_view_data(request, 'dc_network_list')
context['is_staff'] = request.user.is_staff
try:
context['ip_network'] = ip_network = Subnet.get_ip_network(network, netmask) # Invalid IPv4 network
context['vlan_id'] = int(vlan_id)
except ValueError:
raise Http404
network, netmask = ip_network.with_netmask.split('/')
context['netinfo'] = Subnet.get_ip_network_hostinfo(ip_network)
nets = Subnet.objects.filter(network=network, netmask=netmask, vlan_id=vlan_id)
context['num_networks'] = num_networks = nets.count()
if not num_networks:
raise Http404 # Invalid user input - made-up IPv4network
context['order_by'], order_by = get_order_by(request, api_view=NetworkIPPlanView)
ips = IPAddress.objects.select_related('vm', 'vm__dc', 'subnet')\
.prefetch_related('vms')\
.filter(subnet__in=nets)\
.order_by(*order_by).distinct()
context['ips'] = context['pager'] = pager = get_pager(request, ips, per_page=50)
context['total'] = pager.paginator.count
context['free'] = ips.filter(usage=IPAddress.VM, vm__isnull=True, vms=None).count()
return render(request, 'gui/dc/subnet_ip_list.html', context)
评论列表
文章目录