Hi,
attached is a patch that sets the correct mac address type when using
virt-clone. It continues to use the Xen prefix for unknown hypervisors
but uses the correct one for kvm/qemu. I also added some doctest.
virt-image/virt-inst still need to be fixed up at a later point.
Cheers,
-- Guido
# HG changeset patch
# User Guido Guenther <[EMAIL PROTECTED]>
# Date 1218701378 -7200
# Node ID 5d1b967f81cb670834d72669cde92cf2dc3a17fc
# Parent 65c75cb37a4a77536cb338d13b53382173ca38f6
allow to set vendor prefix for mac addresses
use this in CloneManager to set the correct prefix when cloning
diff -r 65c75cb37a4a -r 5d1b967f81cb virtinst/CloneManager.py
--- a/virtinst/CloneManager.py Wed Aug 13 20:01:52 2008 -0400
+++ b/virtinst/CloneManager.py Thu Aug 14 10:09:38 2008 +0200
@@ -244,6 +244,7 @@
doc = libxml2.parseDoc(self._clone_xml)
ctx = doc.xpathNewContext()
+ type = ctx.xpathEval("/domain")[0].prop("type")
# changing name
node = ctx.xpathEval("/domain/name")
@@ -283,7 +284,7 @@
node[0].setContent(self._clone_mac[i-1])
except Exception, e:
while 1:
- mac = util.randomMAC()
+ mac = util.randomMAC(type)
ret, msg = self._check_mac(mac)
if msg is not None:
continue
diff -r 65c75cb37a4a -r 5d1b967f81cb virtinst/util.py
--- a/virtinst/util.py Wed Aug 13 20:01:52 2008 -0400
+++ b/virtinst/util.py Thu Aug 14 10:09:38 2008 +0200
@@ -150,19 +150,36 @@
# available under the LGPL,
# Copyright 2004, 2005 Mike Wray <[EMAIL PROTECTED]>
# Copyright 2005 XenSource Ltd
-def randomMAC():
+def randomMAC(type = "xen"):
"""Generate a random MAC address.
- Uses OUI (Organizationally Unique Identifier) 00-16-3E, allocated to
- Xensource, Inc. The OUI list is available at
- http://standards.ieee.org/regauth/oui/oui.txt.
+ 00-16-3E allocated to xensource
+ 54-52-00 used by qemu/kvm
+
+ The OUI list is available at http://standards.ieee.org/regauth/oui/oui.txt.
The remaining 3 fields are random, with the first bit of the first
random field set 0.
+ >>> randomMAC().startswith("00:16:36")
+ True
+ >>> randomMAC("foobar").startswith("00:16:36")
+ True
+ >>> randomMAC("xen").startswith("00:16:36")
+ True
+ >>> randomMAC("qemu").startswith("54:52:00")
+ True
+
@return: MAC address string
"""
- mac = [ 0x00, 0x16, 0x3e,
+ ouis = { 'xen': [ 0x00, 0x16, 0x36 ], 'qemu': [ 0x54, 0x52, 0x00 ] }
+
+ try:
+ oui = ouis[type]
+ except KeyError:
+ oui = ouis['xen']
+
+ mac = oui + [
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
@@ -416,3 +433,9 @@
ctx.xpathFreeContext()
return result
+def _test():
+ import doctest
+ doctest.testmod()
+
+if __name__ == "__main__":
+ _test()
_______________________________________________
et-mgmt-tools mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/et-mgmt-tools