mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-08 07:03:02 -06:00
guest: add convert_to_q35
This function converts a PC/i400FX XML config to Q35. Mostly this is deleting any plain PCI addresses and controllers, adding pcie-root-ports, convert IDE -> SATA, and let libvirt fill in the rest. This the implementation piece. CLI additions come later Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
fe09e8f47e
commit
454aad78a4
84
tests/data/xmlparse/convert-to-q35-f39-in.xml
Normal file
84
tests/data/xmlparse/convert-to-q35-f39-in.xml
Normal file
@ -0,0 +1,84 @@
|
||||
<domain type='kvm'>
|
||||
<name>convert-me</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://fedoraproject.org/fedora/39"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit='KiB'>8388608</memory>
|
||||
<currentMemory unit='KiB'>8388608</currentMemory>
|
||||
<vcpu placement='static'>8</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-8.2'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' discard='unmap'/>
|
||||
<source file='/mnt/data/devel/images/f39-pc.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<controller type='virtio-serial' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:92:f9:7b'/>
|
||||
<source network='default'/>
|
||||
<model type='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</interface>
|
||||
<serial type='pty'>
|
||||
<target type='isa-serial' port='0'>
|
||||
<model name='isa-serial'/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type='pty'>
|
||||
<target type='serial' port='0'/>
|
||||
</console>
|
||||
<channel type='unix'>
|
||||
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='1'/>
|
||||
</channel>
|
||||
<channel type='spicevmc'>
|
||||
<target type='virtio' name='com.redhat.spice.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='2'/>
|
||||
</channel>
|
||||
<input type='tablet' bus='usb'>
|
||||
<address type='usb' bus='0' port='1'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<sound model='ich6'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</sound>
|
||||
<audio id='1' type='spice'/>
|
||||
<video>
|
||||
<model type='virtio' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='2'/>
|
||||
</redirdev>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='3'/>
|
||||
</redirdev>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
|
||||
</memballoon>
|
||||
<rng model='virtio'>
|
||||
<backend model='random'>/dev/urandom</backend>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
|
||||
</rng>
|
||||
</devices>
|
||||
</domain>
|
||||
|
76
tests/data/xmlparse/convert-to-q35-f39-out.xml
Normal file
76
tests/data/xmlparse/convert-to-q35-f39-out.xml
Normal file
@ -0,0 +1,76 @@
|
||||
<domain type="kvm">
|
||||
<name>convert-me</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://fedoraproject.org/fedora/39"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit="KiB">8388608</memory>
|
||||
<currentMemory unit="KiB">8388608</currentMemory>
|
||||
<vcpu placement="static">8</vcpu>
|
||||
<os>
|
||||
<type arch="x86_64" machine="q35">hvm</type>
|
||||
<boot dev="hd"/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu" type="qcow2" discard="unmap"/>
|
||||
<source file="/mnt/data/devel/images/f39-pc.qcow2"/>
|
||||
<target dev="vda" bus="virtio"/>
|
||||
</disk>
|
||||
<controller type="usb" index="0" model="qemu-xhci" ports="15"/>
|
||||
<controller type="virtio-serial" index="0"/>
|
||||
<interface type="network">
|
||||
<mac address="52:54:00:92:f9:7b"/>
|
||||
<source network="default"/>
|
||||
<model type="virtio"/>
|
||||
</interface>
|
||||
<serial type="pty">
|
||||
<target type="isa-serial" port="0">
|
||||
<model name="isa-serial"/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type="pty">
|
||||
<target type="serial" port="0"/>
|
||||
</console>
|
||||
<channel type="unix">
|
||||
<target type="virtio" name="org.qemu.guest_agent.0"/>
|
||||
<address type="virtio-serial" controller="0" bus="0" port="1"/>
|
||||
</channel>
|
||||
<channel type="spicevmc">
|
||||
<target type="virtio" name="com.redhat.spice.0"/>
|
||||
<address type="virtio-serial" controller="0" bus="0" port="2"/>
|
||||
</channel>
|
||||
<input type="tablet" bus="usb">
|
||||
<address type="usb" bus="0" port="1"/>
|
||||
</input>
|
||||
<input type="mouse" bus="ps2"/>
|
||||
<input type="keyboard" bus="ps2"/>
|
||||
<graphics type="spice" autoport="yes">
|
||||
<listen type="address"/>
|
||||
<image compression="off"/>
|
||||
</graphics>
|
||||
<sound model="ich9"/>
|
||||
<audio id="1" type="spice"/>
|
||||
<video>
|
||||
<model type="virtio" heads="1" primary="yes"/>
|
||||
</video>
|
||||
<redirdev bus="usb" type="spicevmc">
|
||||
<address type="usb" bus="0" port="2"/>
|
||||
</redirdev>
|
||||
<redirdev bus="usb" type="spicevmc">
|
||||
<address type="usb" bus="0" port="3"/>
|
||||
</redirdev>
|
||||
<memballoon model="virtio"/>
|
||||
<rng model="virtio">
|
||||
<backend model="random">/dev/urandom</backend>
|
||||
</rng>
|
||||
<controller type="pci" model="pcie-root"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
</devices>
|
||||
</domain>
|
79
tests/data/xmlparse/convert-to-q35-win10-in.xml
Normal file
79
tests/data/xmlparse/convert-to-q35-win10-in.xml
Normal file
@ -0,0 +1,79 @@
|
||||
<domain type='kvm'>
|
||||
<name>convert-me</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://microsoft.com/win/10"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit='KiB'>4194304</memory>
|
||||
<currentMemory unit='KiB'>4194304</currentMemory>
|
||||
<vcpu placement='static'>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-8.2'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/my/fake/disk'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<controller type='ide' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='virtio-serial' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:0f:b2:90'/>
|
||||
<source network='default'/>
|
||||
<model type='e1000'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</interface>
|
||||
<serial type='pty'>
|
||||
<target type='isa-serial' port='0'>
|
||||
<model name='isa-serial'/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type='pty'>
|
||||
<target type='serial' port='0'/>
|
||||
</console>
|
||||
<channel type='spicevmc'>
|
||||
<target type='virtio' name='com.redhat.spice.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='1'/>
|
||||
</channel>
|
||||
<input type='tablet' bus='usb'>
|
||||
<address type='usb' bus='0' port='1'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<sound model='ich6'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</sound>
|
||||
<audio id='1' type='spice'/>
|
||||
<video>
|
||||
<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</video>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='2'/>
|
||||
</redirdev>
|
||||
<redirdev bus='usb' type='spicevmc'>
|
||||
<address type='usb' bus='0' port='3'/>
|
||||
</redirdev>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
||||
|
78
tests/data/xmlparse/convert-to-q35-win10-out.xml
Normal file
78
tests/data/xmlparse/convert-to-q35-win10-out.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<domain type="kvm">
|
||||
<name>convert-me</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://microsoft.com/win/10"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit="KiB">4194304</memory>
|
||||
<currentMemory unit="KiB">4194304</currentMemory>
|
||||
<vcpu placement="static">2</vcpu>
|
||||
<os>
|
||||
<type arch="x86_64" machine="q35">hvm</type>
|
||||
<boot dev="hd"/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu" type="raw"/>
|
||||
<source file="/my/fake/disk"/>
|
||||
<target dev="sda" bus="sata"/>
|
||||
</disk>
|
||||
<controller type="usb" index="0" model="qemu-xhci" ports="15"/>
|
||||
<controller type="virtio-serial" index="0"/>
|
||||
<interface type="network">
|
||||
<mac address="52:54:00:0f:b2:90"/>
|
||||
<source network="default"/>
|
||||
<model type="e1000e"/>
|
||||
</interface>
|
||||
<serial type="pty">
|
||||
<target type="isa-serial" port="0">
|
||||
<model name="isa-serial"/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type="pty">
|
||||
<target type="serial" port="0"/>
|
||||
</console>
|
||||
<channel type="spicevmc">
|
||||
<target type="virtio" name="com.redhat.spice.0"/>
|
||||
<address type="virtio-serial" controller="0" bus="0" port="1"/>
|
||||
</channel>
|
||||
<input type="tablet" bus="usb">
|
||||
<address type="usb" bus="0" port="1"/>
|
||||
</input>
|
||||
<input type="mouse" bus="ps2"/>
|
||||
<input type="keyboard" bus="ps2"/>
|
||||
<graphics type="spice" autoport="yes">
|
||||
<listen type="address"/>
|
||||
<image compression="off"/>
|
||||
</graphics>
|
||||
<sound model="ich9"/>
|
||||
<audio id="1" type="spice"/>
|
||||
<video>
|
||||
<model type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"/>
|
||||
</video>
|
||||
<redirdev bus="usb" type="spicevmc">
|
||||
<address type="usb" bus="0" port="2"/>
|
||||
</redirdev>
|
||||
<redirdev bus="usb" type="spicevmc">
|
||||
<address type="usb" bus="0" port="3"/>
|
||||
</redirdev>
|
||||
<memballoon model="virtio"/>
|
||||
<controller type="pci" model="pcie-root"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
<controller type="pci" model="pcie-root-port"/>
|
||||
</devices>
|
||||
</domain>
|
@ -1203,3 +1203,15 @@ def testUnknownEmulatorDomcapsLookup(monkeypatch):
|
||||
assert guest.lookup_domcaps()
|
||||
assert guest.lookup_domcaps()
|
||||
assert seen
|
||||
|
||||
|
||||
def testConvertToQ35():
|
||||
conn = utils.URIs.openconn(utils.URIs.kvm_x86)
|
||||
|
||||
def _test(filename_base, **kwargs):
|
||||
guest, outfile = _get_test_content(conn, filename_base)
|
||||
guest.convert_to_q35(**kwargs)
|
||||
_alter_compare(conn, guest.get_xml(), outfile)
|
||||
|
||||
_test("convert-to-q35-win10")
|
||||
_test("convert-to-q35-f39", num_pcie_root_ports=5)
|
||||
|
@ -796,6 +796,38 @@ class Guest(XMLBuilder):
|
||||
else:
|
||||
self._remove_spice_devices(inst)
|
||||
|
||||
def convert_to_q35(self, num_pcie_root_ports=None):
|
||||
self.os.machine = "q35"
|
||||
|
||||
if num_pcie_root_ports is not None:
|
||||
self.num_pcie_root_ports = int(num_pcie_root_ports)
|
||||
|
||||
for dev in self.devices.get_all():
|
||||
if (dev.DEVICE_TYPE == "controller" and
|
||||
dev.type in ["pci", "ide"]):
|
||||
self.remove_device(dev)
|
||||
continue
|
||||
|
||||
if (dev.DEVICE_TYPE == "sound" and
|
||||
dev.model == "ich6"):
|
||||
dev.model = "ich9"
|
||||
|
||||
if (dev.DEVICE_TYPE == "interface" and
|
||||
dev.model == "e1000"):
|
||||
dev.model = "e1000e"
|
||||
|
||||
if (dev.DEVICE_TYPE == "disk" and
|
||||
dev.bus == "ide"):
|
||||
dev.bus = "sata"
|
||||
used_targets = [d.target for d in self.devices.disk if d.target]
|
||||
dev.generate_target(used_targets)
|
||||
dev.address.clear()
|
||||
|
||||
if dev.address.type == "pci":
|
||||
dev.address.clear()
|
||||
|
||||
self.add_q35_pcie_controllers()
|
||||
|
||||
def set_defaults(self, _guest):
|
||||
self.set_capabilities_defaults()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user