Re: generate interface MAC addresses in a particular order

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

 



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

http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virmacaddr.c;h=612a409d0b531c53215de360c22178d496876d4b;hb=HEAD#l226

Michal

_______________________________________________
libvirt-users mailing list
libvirt-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvirt-users



[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux