[Kimchi-devel] [RFC]: help, how to get the mac after create a VM interface.

Aline Manera alinefm at linux.vnet.ibm.com
Mon Jan 20 17:17:39 UTC 2014


On 01/20/2014 11:34 AM, Sheldon wrote:
> when I create a interface, There is no mac attribute in the xml.
> After create successfully, libvirt will allocate a mac.
> The problem is that, How can I get the mac.
>
> Should the CREATE method always needs to return an interface info?
>
> Here is some of create code.
>
> def vmifaces_create(self, vm, params):
> dom = self._get_vm(vm)
> xml = """
> <interface type='network'>
> <source network='default'/>
> </interface>
> """
>
> dom.attachDeviceFlags(xml,
> libvirt.VIR_DOMAIN_AFFECT_CURRENT)
>
> # here I need to return the mac
> return ????
>
>
>
> The libvirt will create a xml like the follow? The problem is that the 
> a vm may have several interfaces.
> xml = """
> <interface type='network'>
> <mac address='52:54:00:2a:53:8f'/>
> <source network='default'/>
> <model type='rtl8139'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
> function='0x0'/>
> </interface>
> """
>
>

We can generate the mac and pass it to libvirt:

 >>> import virtinst.util
 >>> print virtinst.util.randomMAC()
00:16:3e:fd:b4:3a

I don't if libvirt requires a mac starting with "52:52:00"
Maybe it is used to avoid generating duplicated mac addresses.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20140120/75c69449/attachment.html>


More information about the Kimchi-devel mailing list