Defining networks in parallel result in the same bridge name being generated
Defining two networks in parallel results in both assigning the same bridge device.
1.xml
<network>
<name>k8s-net</name>
<uuid>46dc65a6-7f05-4926-82f1-8f11f2c8ac39</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<mac address='52:54:00:09:46:76'/>
<dns enable='yes'/>
<ip family='ipv4' address='10.0.1.1' prefix='24'>
<dhcp>
<range start='10.0.1.2' end='10.0.1.254'/>
</dhcp>
</ip>
</network>
2.xml
<network>
<name>ext-net</name>
<uuid>c71c9f89-733e-4d5c-8ea8-8fd9d45c9cbe</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<mac address='52:54:00:5b:c5:58'/>
<dns enable='yes'/>
<ip family='ipv4' address='10.10.1.1' prefix='24'>
<dhcp>
<range start='10.10.1.2' end='10.10.1.254'/>
</dhcp>
</ip>
</network>
create.sh
#!/bin/bash
virsh -c qemu:///system net-define 1.xml &
virsh -c qemu:///system net-define 2.xml &
wait
virsh -c qemu:///system net-dumpxml k8s-net
virsh -c qemu:///system net-dumpxml ext-net
Results in both networks having the same bridge.
<network>
<name>k8s-net</name>
<uuid>46dc65a6-7f05-4926-82f1-8f11f2c8ac39</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr6' stp='on' delay='0'/>
<mac address='52:54:00:09:46:76'/>
<dns enable='yes'/>
<ip family='ipv4' address='10.0.1.1' prefix='24'>
<dhcp>
<range start='10.0.1.2' end='10.0.1.254'/>
</dhcp>
</ip>
</network>
<network>
<name>ext-net</name>
<uuid>c71c9f89-733e-4d5c-8ea8-8fd9d45c9cbe</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr6' stp='on' delay='0'/>
<mac address='52:54:00:5b:c5:58'/>
<dns enable='yes'/>
<ip family='ipv4' address='10.10.1.1' prefix='24'>
<dhcp>
<range start='10.10.1.2' end='10.10.1.254'/>
</dhcp>
</ip>
</network>
We found out this as part of https://github.com/dmacvicar/terraform-provider-libvirt/pull/740, where terraform creates resources in parallel. Both networks were defined with the same bridge. Starting them fail.
Error: Error creating libvirt network: virError(Code=38, Domain=0, Message='error creating bridge interface virbr6: File exists')
I was able to reproduce this on libvirt-6.7.0 (openSUSE Tumbleweed).
We will like introduce a workaround in the terraform provider (creating one network at the same time).