mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56:48 +00:00
feat(instances): Add PCIe slots for a VM that has none free
An existing q35 VM whose PCIe root ports are all used takes no new virtio disk or network device while it runs, and the only way to give it more was editing its XML. The Disks tab of a PCIe machine now counts its slots, "PCIe slots: 0 free of 7", in red when none is free, with what its next start will have when that differs, and Add PCIe slots adds four root ports to its persistent definition: libvirt numbers and places them, and a running VM gets them at its next start. The no-slot advice of Add disk and Add network device points at it.
This commit is contained in:
parent
34d9e778ce
commit
95562544eb
7 changed files with 168 additions and 4 deletions
|
|
@ -706,6 +706,26 @@ class wvmInstance(wvmConnect):
|
|||
def get_machine_type(self):
|
||||
return util.get_xml_path(self._XMLDesc(0), "/domain/os/type/@machine")
|
||||
|
||||
def get_pcie_slots(self, config=False):
|
||||
"""(PCIe root ports, free ones) of the running or the persistent
|
||||
definition, None when it has none (not a PCIe machine): each PCIe
|
||||
device takes a port, the one whose index is its address's bus."""
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML if config else 0))
|
||||
ports = tree.xpath("./devices/controller[@type='pci'][@model='pcie-root-port']/@index")
|
||||
if not ports:
|
||||
return None
|
||||
used = {int(bus, 16) for bus in tree.xpath("./devices/*/address[@type='pci']/@bus")}
|
||||
return len(ports), sum(int(index) not in used for index in ports)
|
||||
|
||||
def add_pcie_slots(self, count):
|
||||
"""Add count PCIe root ports to the persistent definition, which libvirt
|
||||
numbers and places; a running VM gets them at its next start."""
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
|
||||
devices = tree.find("devices")
|
||||
for _ in range(count):
|
||||
etree.SubElement(devices, "controller", type="pci", model="pcie-root-port")
|
||||
self._defineXML(etree.tostring(tree).decode())
|
||||
|
||||
def get_dom_emulator(self):
|
||||
return util.get_xml_path(self._XMLDesc(0), "/domain/devices/emulator")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue