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

Andrei Perietanu andrei.perietanu at klastelecom.com
Mon Feb 1 09:14:32 UTC 2016

On Sun, Jan 31, 2016 at 8:56 AM, Michal Privoznik <mprivozn at redhat.com>

> 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

Does libvirt offer a way to generate MAC addresses before adding them to
the XML? I may have to generate tens of them and I would not want to
reinvent the wheel writing my own MAC address generator.



The information transmitted is intended only for the person or entity to 
which it is addressed and may contain confidential and/or privileged 
material. Any review, retransmission, dissemination or other use of or 
taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you receive 
this in error please contact the sender and delete the material from any 
computer immediately. It is the policy of Klas  Limited to disavow the 
sending of offensive material and should you consider that the material 
contained in the message is offensive you should contact the sender 
immediately and also your I.T. Manager.

Klas Telecom Inc., a Virginia Corporation with offices at 1101 30th St. NW, 
Washington, DC 20007.

Klas Limited (Company Number 163303) trading as Klas Telecom, an Irish 
Limited Liability Company, with its registered office at Fourth Floor, One 
Kilmainham Square, Inchicore Road, Kilmainham, Dublin 8, Ireland.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20160201/44e72e56/attachment.htm>

More information about the libvirt-users mailing list