
We install libvirt in a AlmaLinux 9 Kickstart file. The version of libvirt we are using is 10.0.0. What we'd like to do is to statically define a network in the kickstart file without having to run `virsh net-define`. In other words, we had hoped that by installing a <network>.xml file in /usr/share/libvirt/networks, that that network would be recognized by libvirt the first time the system is booted. This does not appear to be the case. Is there a way to statically define libvirt networks without needing to run 'virsh net-define'? Thanks

On Tue, Jun 11, 2024 at 04:23:33PM GMT, richard.schmitt--- via Users wrote:
We install libvirt in a AlmaLinux 9 Kickstart file. The version of libvirt we are using is 10.0.0.
What we'd like to do is to statically define a network in the kickstart file without having to run `virsh net-define`. In other words, we had hoped that by installing a <network>.xml file in /usr/share/libvirt/networks, that that network would be recognized by libvirt the first time the system is booted. This does not appear to be the case.
Is there a way to statically define libvirt networks without needing to run 'virsh net-define'?
You need to install the file in /etc/libvirt/qemu/networks instead. If you want the network to be autostarted, you also need to create a symlink in /etc/libvirt/qemu/networks/autostart that points to the network XML and has a matching name. -- Andrea Bolognani / Red Hat / Virtualization

On 6/12/24 6:42 AM, Andrea Bolognani wrote:
On Tue, Jun 11, 2024 at 04:23:33PM GMT, richard.schmitt--- via Users wrote:
We install libvirt in a AlmaLinux 9 Kickstart file. The version of libvirt we are using is 10.0.0.
What we'd like to do is to statically define a network in the kickstart file without having to run `virsh net-define`. In other words, we had hoped that by installing a <network>.xml file in /usr/share/libvirt/networks, that that network would be recognized by libvirt the first time the system is booted. This does not appear to be the case.
Is there a way to statically define libvirt networks without needing to run 'virsh net-define'? You need to install the file in /etc/libvirt/qemu/networks instead. If you want the network to be autostarted, you also need to create a symlink in /etc/libvirt/qemu/networks/autostart that points to the network XML and has a matching name.
Note that if you do this, you'll need to "preprocess" the .xml file by net-define'ing it on some system so that all the necessary elements are there, and then using the resulting xml rather than your original - for example, each network must have a <uuid> element, but that is usually filled in automatically when the network is net-defined. Also, if you do this keep in mind that the fact that these files are currently in /etc/libvirt/qemu/networks is not a part of libvirt's public API - it could be changed at any time by an update (although this has never happened). The same is true for all other .xml files in /etc/libvirt; only the .conf files are public.

On Thu, Jun 13, 2024 at 09:28:08AM GMT, Laine Stump wrote:
On 6/12/24 6:42 AM, Andrea Bolognani wrote:
On Tue, Jun 11, 2024 at 04:23:33PM GMT, richard.schmitt--- via Users wrote:
Is there a way to statically define libvirt networks without needing to run 'virsh net-define'?
You need to install the file in /etc/libvirt/qemu/networks instead. If you want the network to be autostarted, you also need to create a symlink in /etc/libvirt/qemu/networks/autostart that points to the network XML and has a matching name.
Note that if you do this, you'll need to "preprocess" the .xml file by net-define'ing it on some system so that all the necessary elements are there, and then using the resulting xml rather than your original - for example, each network must have a <uuid> element, but that is usually filled in automatically when the network is net-defined.
That used to be true, but after [1] that's no longer the case. As long as the XML file you drop into the directory is roughly equivalent to src/network/default.xml.in everything is going to work just the way you'd expect it to.
Also, if you do this keep in mind that the fact that these files are currently in /etc/libvirt/qemu/networks is not a part of libvirt's public API - it could be changed at any time by an update (although this has never happened). The same is true for all other .xml files in /etc/libvirt; only the .conf files are public.
Fair disclaimer. [1] https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/EZNHY... -- Andrea Bolognani / Red Hat / Virtualization
participants (3)
-
Andrea Bolognani
-
Laine Stump
-
richard.schmitt@starlab.io