On 01/20/2014 10:43 PM, Shu Ming wrote:
ÓÚ 2014/1/21 1:17, Aline Manera дµÀ:
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

Let libvirt to generate the MAC addresses are better.   randomMAC() does not gurantee that the MAC address generated is unique,  so you need to handle that in your code. If libvirt doesn't gurantee that either,  we can file a bug against libvirt.


Ok. But if we let libvirt generates the MAC we come back to the original problem mentioned by Sheldon.
How do we get the MAC to return to kimchi API?


I don't if libvirt requires a mac starting with
"52:52:00"
Maybe it is used to avoid generating duplicated mac addresses.


_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel