[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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

On 01.02.2016 10:14, Andrei Perietanu wrote:
> On Sun, Jan 31, 2016 at 8:56 AM, Michal Privoznik <mprivozn redhat com>
> wrote:
>> 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.

Unfortunately no, but the generator is really simple:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]