Skip to content

Instantly share code, notes, and snippets.

@electrofelix
Last active May 15, 2022 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electrofelix/6f66714c14a0d6e3b1078037aadae398 to your computer and use it in GitHub Desktop.
Save electrofelix/6f66714c14a0d6e3b1078037aadae398 to your computer and use it in GitHub Desktop.
Sample files for libvirt define behaviour
initial definition
Domain 'vagrant-libvirt_default' defined from test.xml
display vcpus
<vcpu placement='static'>2</vcpu>
update with nvram XML tag
Domain 'vagrant-libvirt_default' defined from test_with_nvram.xml
check if apply worked
<vcpu placement='static'>4</vcpu>
update with both nvram and loader XML tags
Domain 'vagrant-libvirt_default' defined from test_with_nvram_and_loader.xml
check if apply worked (should also revert the vcpu)
<nvram>/usr/share/edk2-ovmf/OVMF_VARS.fd</nvram>
<vcpu placement='static'>2</vcpu>
#!/bin/bash
echo "initial definition"
virsh -c qemu:///system define test.xml
echo "display vcpus"
virsh -c qemu:///system dumpxml vagrant-libvirt_default | grep vcpu
echo
echo "update with nvram XML tag"
virsh -c qemu:///system define test_with_nvram.xml
echo "check if apply worked"
virsh -c qemu:///system dumpxml vagrant-libvirt_default | grep nvram
virsh -c qemu:///system dumpxml vagrant-libvirt_default | grep vcpu
echo
echo "update with both nvram and loader XML tags"
virsh -c qemu:///system define test_with_nvram_and_loader.xml
echo "check if apply worked (should also revert the vcpu)"
virsh -c qemu:///system dumpxml vagrant-libvirt_default | grep nvram
virsh -c qemu:///system dumpxml vagrant-libvirt_default | grep vcpu
<domain type='kvm'>
<name>vagrant-libvirt_default</name>
<uuid>b12bdd34-9c8d-4bd5-b2c7-ea1e2359bd64</uuid>
<description>Source: /home/test/git/github.com/vagrant-libvirt/vagrant-libvirt/Vagrantfile</description>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-7.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='host-model' check='partial'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
<target dev='vda' bus='virtio'/>
<alias name='ua-box-volume-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='network'>
<mac address='52:54:00:a9:7e:c5'/>
<source network='vagrant-libvirt'/>
<model type='virtio'/>
<alias name='ua-net-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' 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>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<audio id='1' type='none'/>
<video>
<model type='cirrus' vram='256' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
<domain type='kvm'>
<name>vagrant-libvirt_default</name>
<uuid>b12bdd34-9c8d-4bd5-b2c7-ea1e2359bd64</uuid>
<description>Source: /home/test/git/github.com/vagrant-libvirt/vagrant-libvirt/Vagrantfile</description>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-7.0'>hvm</type>
<boot dev='hd'/>
<nvram>/usr/share/edk2-ovmf/OVMF_VARS.fd</nvram>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='host-model' check='partial'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
<target dev='vda' bus='virtio'/>
<alias name='ua-box-volume-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='network'>
<mac address='52:54:00:a9:7e:c5'/>
<source network='vagrant-libvirt'/>
<model type='virtio'/>
<alias name='ua-net-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' 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>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<audio id='1' type='none'/>
<video>
<model type='cirrus' vram='256' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
<domain type='kvm'>
<name>vagrant-libvirt_default</name>
<uuid>b12bdd34-9c8d-4bd5-b2c7-ea1e2359bd64</uuid>
<description>Source: /home/test/git/github.com/vagrant-libvirt/vagrant-libvirt/Vagrantfile</description>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-7.0'>hvm</type>
<boot dev='hd'/>
<loader type='rom'>/usr/share/edk2-ovmf/OVMF_CODE.secboot.fd</loader>
<nvram>/usr/share/edk2-ovmf/OVMF_VARS.fd</nvram>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='host-model' check='partial'/>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
<target dev='vda' bus='virtio'/>
<alias name='ua-box-volume-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='network'>
<mac address='52:54:00:a9:7e:c5'/>
<source network='vagrant-libvirt'/>
<model type='virtio'/>
<alias name='ua-net-0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' 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>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<audio id='1' type='none'/>
<video>
<model type='cirrus' vram='256' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
@electrofelix
Copy link
Author

Shows an issue where XML that has an nvram tag without a loader tag and an update to the vcpu tag will result in only the vcpu number being modified while the nvram tag is ignored. Expectation is this should result in an error and both changes should be ignored.

Once the loader tag is present as well, the definition applies as expected.

Output of virsh -c qemu:///system version:

Compiled against library: libvirt 8.2.0
Using library: libvirt 8.2.0
Using API: QEMU 8.2.0
Running hypervisor: QEMU 7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment