1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/nodedevs/views.py
catborise 0977aef587 feat(nodedevs): the host's PCI and USB devices on a Devices page
- A Devices section of each host lists its PCI devices by IOMMU group and
  its USB devices: what each is (vendor, product, IDs, class, driver), what
  the host itself has on it (its network interfaces, disks and graphics
  card, anywhere below it) and the VMs whose definitions name it.
- A VM names a PCI device by its address, a USB device by its address or
  by its model only; a VM that names a model only is shown on every device
  of that model, which one it takes is known only when it starts.
- A host without IOMMU groups says that no PCI device can be given to a VM
  and how to turn the IOMMU on.
- One listing of the host's node devices, one XML read each (a device gone
  meanwhile is left out), and the VMs' definitions read once; nothing is
  shown when they cannot be read, as a device would look free.
- Read only: giving devices to VMs comes in the next layers.
2026-10-29 13:01:17 +03:00

29 lines
1.4 KiB
Python

from admin.decorators import superuser_only
from computes.models import Compute
from django.contrib import messages
from django.shortcuts import get_object_or_404, render
from instances.models import Instance
from libvirt import libvirtError
from vrtManager.nodedevs import wvmNodeDevices
@superuser_only
def nodedevs(request, compute_id):
"""The host's PCI and USB devices: what each is, what the host has on it
and the VMs that name it. Read only."""
compute = get_object_or_404(Compute, pk=compute_id)
context = {"compute": compute}
try:
conn = wvmNodeDevices(compute.hostname, compute.login, compute.password, compute.type)
pci, usb = conn.get_node_devices()
vm_ids = dict(Instance.objects.filter(compute=compute).values_list("name", "id"))
for device in pci + usb:
device["vms"] = [{"name": name, "id": vm_ids.get(name)} for name in device["vms"]]
groups = {}
for device in pci:
groups.setdefault(device["group"], []).append(device)
context.update(devices_read=True, groups=list(groups.items()), pci_count=len(pci), usb=usb,
iommu=any(group is not None for group in groups))
except libvirtError as err: # nothing is shown without the VMs: a device would look free
messages.error(request, err)
return render(request, "nodedevs.html", context)