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

Re: [libvirt] [question]Is there a good way to get the mac of guest interface after I attached it to a guest



----- Original Message -----
> Now I working on a new KVM management tool base on html5 and libvirt
> 
> we will support a REST API for detach and attach guest interface.
> 
> we want to use mac as the identifier of the network interface.
> 
> That meas we should get the mac after the user create a interface.
> also other people may be doing the exact same thing at the exact same
> time to create a interface.
> 
> 
> Here are the demo codes:
> 
> dom = self._get_vm(vm)
> xml = """
> <interface type='network'>
> <source network='default'/>
> </interface>
> """

This interface xml is partial, and it is not recommended according to 'man virsh':
"
Note: using of partial device definition XML files may lead to
unexpected results as some fields may be autogenerated and thus
match devices other than expected.
"

And there is a way to find out the mac address specified by libvirt,
we can check /var/lib/libvirt/dnsmasq/default.leases, newer one is on top
# cat /var/lib/libvirt/dnsmasq/default.leases
1390549166 52:54:00:ea:9f:58 192.168.122.106 * *
1390547957 52:54:00:9d:43:38 192.168.122.134 * *
1390547828 52:54:00:0b:2f:ec 192.168.122.76 localhost *

But seems there is some latency, :(


> dom.attachDeviceFlags(xml, libvirt.VIR_DOMAIN_AFFECT_CURRENT)
> # now I want to get the mac, how to get it?
> 
> 
> I have check libvirt use this code to generate a mac address.
> does libvirt can gurantee that the MAC address generated is unique?

yes, I also have this question.

> 
> 
> void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
> virMacAddrPtr addr)
> {
> addr->addr[0] = prefix[0];
> addr->addr[1] = prefix[1];
> addr->addr[2] = prefix[2];
> addr->addr[3] = virRandomBits(8);
> addr->addr[4] = virRandomBits(8);
> addr->addr[5] = virRandomBits(8);
> }
> libvirt also use the KVM prefix as default as it's in the privately
> administered range:
> 52:54:00:XX:XX:XX
> 
> 
> 
> --
> Thanks and best regards!
> 
> Sheldon Feng(冯少合)<shaohef linux vnet ibm com>
> IBM Linux Technology Center
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list


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