1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/nodedevs/views.py
catborise ac8ff62e7e feat(instances): USB devices of the host given to a VM
- A Host devices tab on the VM page lists the VM's USB host devices, each
  once: how it is chosen (its address, or any device of its model), the
  device the running VM holds and whether its next start has it; its other
  host devices (PCI, SCSI, mediated) are listed for the XML editor.
- Superusers add a USB device of the host and take it back, on a running
  VM too. The add form is loaded when the tab opens, as its choices read
  every VM of the host; a hub, a device the host has its own disks or
  network interfaces on, or one another VM names is not offered, with the
  reason, and refused on the server under the compute's claim. A device is
  chosen by model when the host has one of it, else by its address.
- A VM without a USB controller is refused; a device is taken from each
  definition as that definition describes it.
- A clone gets none of the VM's host devices (the clone form says so), and
  a VM with host devices is not migrated. A snapshot revert is refused when
  it would give the VM a device another VM names or the host uses.
- A NIC that is a host device is no longer edited or removed from the
  Network tab: the XML editor changes it.
2026-10-29 13:33:23 +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.connection import wvmConnect
from vrtManager.nodedevs import node_devices
@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:
pci, usb = node_devices(wvmConnect(compute.hostname, compute.login, compute.password, compute.type))
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)