That is, the nvram file is copied from a global template to an instance-specific file -- it's that file under /var/lib/libvirt/qemu/nvram that VIR_DOMAIN_UNDEFINE_NVRAM removes. It should arguably be using template=AAVMF_VARS.fd rather than AAVMF_CODE.fd, but that's unrelated to this and doesn't really matter.
The most annoying part of this change is feature detection. I think delete_configuration might have to know to try unsetting flags until the method works, as older libvirts don't support VIR_DOMAIN_UNDEFINE_NVRAM and I can't see a way to test at runtime. But in our environment we know the libvirt version, so we just pass the flag in unconditionally.
Yes, it is still possible to create an instance after changing only the delete method. The generated libvirt domain XML looks like this:
<os> 'virt'> hvm</type> >/usr/share/ AAVMF/AAVMF_ CODE.fd< /loader> '/usr/share/ AAVMF/AAVMF_ CODE.fd' >/var/lib/ libvirt/ qemu/nvram/ instance- 00000005_ VARS.fd< /nvram>
<type arch='aarch64' machine=
<loader readonly='yes' type='pflash'
<nvram template=
<boot dev='hd'/>
</os>
That is, the nvram file is copied from a global template to an instance-specific file -- it's that file under /var/lib/ libvirt/ qemu/nvram that VIR_DOMAIN_ UNDEFINE_ NVRAM removes. It should arguably be using template= AAVMF_VARS. fd rather than AAVMF_CODE.fd, but that's unrelated to this and doesn't really matter.
The most annoying part of this change is feature detection. I think delete_ configuration might have to know to try unsetting flags until the method works, as older libvirts don't support VIR_DOMAIN_ UNDEFINE_ NVRAM and I can't see a way to test at runtime. But in our environment we know the libvirt version, so we just pass the flag in unconditionally.