1
From 62765031f81a3c489283a6be07d09f76d0e96845 Mon Sep 17 00:00:00 2001
2
From: Guido Guenther <agx@sigxcpu.org>
3
Date: Fri, 15 Aug 2008 13:52:58 +0200
4
Subject: [PATCH] fix mac address on virt-clone
6
Adresses parts of #495013
8
virtinst/CloneManager.py | 3 ++-
9
virtinst/util.py | 35 ++++++++++++++++++++++++++++++-----
10
2 files changed, 32 insertions(+), 6 deletions(-)
12
diff --git a/virtinst/CloneManager.py b/virtinst/CloneManager.py
13
index d42e2f0..c8f606e 100644
14
--- a/virtinst/CloneManager.py
15
+++ b/virtinst/CloneManager.py
16
@@ -243,6 +243,7 @@ class CloneDesign(object):
18
doc = libxml2.parseDoc(self._clone_xml)
19
ctx = doc.xpathNewContext()
20
+ type = ctx.xpathEval("/domain")[0].prop("type")
23
node = ctx.xpathEval("/domain/name")
24
@@ -282,7 +283,7 @@ class CloneDesign(object):
25
node[0].setContent(self._clone_mac[i-1])
28
- mac = util.randomMAC()
29
+ mac = util.randomMAC(type)
30
ret, msg = self._check_mac(mac)
33
diff --git a/virtinst/util.py b/virtinst/util.py
34
index cc31064..5f8b55f 100644
35
--- a/virtinst/util.py
36
+++ b/virtinst/util.py
37
@@ -142,19 +142,36 @@ def get_default_arch():
38
# available under the LGPL,
39
# Copyright 2004, 2005 Mike Wray <mike.wray@hp.com>
40
# Copyright 2005 XenSource Ltd
42
+def randomMAC(type = "xen"):
43
"""Generate a random MAC address.
45
- Uses OUI (Organizationally Unique Identifier) 00-16-3E, allocated to
46
- Xensource, Inc. The OUI list is available at
47
- http://standards.ieee.org/regauth/oui/oui.txt.
48
+ 00-16-3E allocated to xensource
49
+ 54-52-00 used by qemu/kvm
51
+ The OUI list is available at http://standards.ieee.org/regauth/oui/oui.txt.
53
The remaining 3 fields are random, with the first bit of the first
56
+ >>> randomMAC().startswith("00:16:36")
58
+ >>> randomMAC("foobar").startswith("00:16:36")
60
+ >>> randomMAC("xen").startswith("00:16:36")
62
+ >>> randomMAC("qemu").startswith("54:52:00")
65
@return: MAC address string
67
- mac = [ 0x00, 0x16, 0x3e,
68
+ ouis = { 'xen': [ 0x00, 0x16, 0x36 ], 'qemu': [ 0x54, 0x52, 0x00 ] }
76
random.randint(0x00, 0x7f),
77
random.randint(0x00, 0xff),
78
random.randint(0x00, 0xff) ]
79
@@ -222,3 +239,11 @@ def xml_escape(str):
80
str = str.replace("<", "<")
81
str = str.replace(">", ">")
88
+if __name__ == "__main__":