I’m sorry if this is a simple question, but I am just starting out with qemu and can’t find a easy way to do this.
I am trying to somewhat automate my KVM deployment. I am currently running into the issue that I can’t find a way to automatically set parameters for a filterref.
This is what my network option for virt-install currently looks like and that is working fine for now.
--network type=bridge,network=default,bridge=bridge0,model=e1000e,mac=$mac,filterref=clean-traffic
However I can’t find anything to set a parameter to define the IP address it’s supposed to be locked down to. This is the result that I want in the xml:
<filterref filter='clean-traffic'>
<parameter name='IP' value='XXX.XXX.XXX.XXX'/>
</filterref>
I am looking for a way to automatically add that parameter, preferably directly with virt-install
or to an extent were I can just run a script, enter the few variables I want to set. And at this point the VM would already be running and waiting for the setup to be completed, with the filter loaded. Basically I want the parameter to be loaded before the first startup, so that there is no chance of anyone trying to mess with the ip address.
Is this possible?
This is the whole "script" I just copy into the console at the moment.
name=WindowsTest
mac=00:50:56:00:05:C5
size=70
ram=6000
vcpus=6
let cores=vcpus/2
virt-install
--name=$name
--ram=$ram
--cpu=host
--vcpus=$vcpus,maxvcpus=$vcpus,sockets=1,cores=$cores,threads=2
--os-type=windows
--os-variant=win10
--disk path=/var/lib/libvirt/clutchImages/$name.qcow2,size=$size,format=qcow2,bus=virtio
--cdrom /var/isos/Windows_20H2_English.iso
--disk /var/isos/virtio-win-0.1.185.iso,device=cdrom
--network type=bridge,network=default,bridge=bridge0,model=e1000e,mac=$mac,filterref=clean-traffic
--graphics spice,listen=157.90.2.208
--graphics vnc
virsh version output:
virsh version
Compiled against library: libvirt 6.0.0
Using library: libvirt 6.0.0
Using API: QEMU 6.0.0
Running hypervisor: QEMU 4.2.0
I am on CentOS Linux release 8.3.2011.
2
Answers
Quick & dirty
Make arbitrary edits to virt-install’s xml output
According to the man page you can make direct edits to the XML using XPath
syntax.
e.g.
virt-install man page excerpt:
XML result
virsh version
output: