Creating unique interfaceid in KVM (RHEL)
Consider the KVM VM has the below definition:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<interface type='bridge'> | |
<mac address='52:54:00:8c:30:e1'/> | |
<source bridge='breth0'/> | |
<virtualport type='openvswitch'> | |
<parameters interfaceid='63bc2fbc-cfca-4917-9ae5-2d3a02b2504c'/> | |
</virtualport> | |
<model type='virtio'/> | |
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> | |
</interface> | |
<interface type='bridge'> | |
<mac address='52:54:00:e6:70:f8'/> | |
<source bridge='nsx-managed'/> | |
<virtualport type='openvswitch'> | |
<parameters interfaceid='df55d7eb-5f25-43db-8bf8-f67b259bf51b'/> | |
</virtualport> | |
<model type='virtio'/> | |
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> | |
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<interface type='bridge'> | |
<mac address='52:54:00:8c:30:e1'/> | |
<source bridge='breth0'/> | |
<virtualport type='openvswitch'> | |
<parameters interfaceid='63bc2fbc-cfca-4917-9ae5-2d3a02b2504c'/> | |
</virtualport> | |
<model type='virtio'/> | |
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> | |
</interface> | |
<interface type='bridge'> | |
<mac address='52:54:00:e6:70:f8'/> | |
<source bridge='nsx-managed'/> | |
<virtualport type='openvswitch'> | |
<parameters interfaceid='df55d7eb-5f25-43db-8bf8-f67b259bf51b'/> | |
</virtualport> | |
<model type='virtio'/> | |
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> | |
</interface> |
If you clone this VM using virt-clone utility, then the new VM will have the same interface id
If you need new interfaceid for every clone, then some libvirt py files will need change:
1) /usr/share/virt-manager/virtinst/deviceinterface.py
class VirtualPort(XMLBuilder):
_XML_ROOT_NAME = "virtualport"
type = XMLProperty("./@type")
managerid = XMLProperty("./parameters/@managerid", is_int
typeid = XMLProperty("./parameters/@typeid", is_int=True)
typeidversion = XMLProperty("./parameters/@typeidversion"
instanceid = XMLProperty("./parameters/@instanceid")
interfaceid = XMLProperty("./parameters/@interfaceid") <--- added="" div="" newly="">
2) /usr/share/virt-manager/virtinst/cloner.py
import uuid
and following line:
for iface in self._guest.get_devices("interface"):
iface.target_dev = None
if clone_macs:
mac = clone_macs.pop()
else:
mac = VirtualNetworkInterface.generate_mac(self.conn)
iface.macaddr = mac
if iface.virtualport.type:
if iface.virtualport.type:
iface.virtualport.interfaceid = uuid.uuid4() <--- added="" div="" newly="">