[libvirt-users] generate interface MAC addresses in a particular order

Michal Privoznik mprivozn at redhat.com
Sun Jan 31 08:56:45 UTC 2016


On 29.01.2016 11:24, Andrei Perietanu wrote:
> Hi all,
> 
>  I am using libvirt to manage VM on my system; after creating a VM (default
> no NICs are present in the configuration) you can add any number of
> interfaces to it (as long as they exist on the host).
> To do that, I edit the configuration xlm:
> 
>       vmXml = self.domain.XMLDesc()
>         root = ET.fromstring(vmXml)
>         devices = root.find('./devices')
> 
>         intf = ET.SubElement(devices,'interface')
>         intf.set('type', 'bridge')
>         src = ET.SubElement(intf,'source')
>         src.set('bridge', bIntf)
>         model = ET.SubElement(intf,'model')
>         model.set('type', 'e1000')
> 
>         xml = ET.tostring(root)
>         self.conn.defineXML(xml)
> 
> Now the problem I have is that the MAC addresses are auto-generated and
> because of this there is no way to predict which interface number the newly
> added interface will map to, on the VM. Ideally, the first added interface
> is mapped to eth0/0, the second one eth0/1...etc.  Since the mappings
> depend on the MAC addresses I figured that is the part I need to have
> control over.
> 
> Any ideas?
> 

You can provide mac address too. Only if none was given in the XML
libvirt makes up one.

Michal




More information about the libvirt-users mailing list