~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to debian/patches/0005-fix-mac-address-on-virt-clone.patch

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-08-23 12:57:30 UTC
  • mfrom: (1.1.4 lenny)
  • Revision ID: james.westby@ubuntu.com-20080823125730-u1othafetd50dbd8
Tags: 0.300.3-5ubuntu1
* Merge from debian unstable, remaining changes:
  - Rename binary to python-virtinst
  - Version dependency on libvirt (to make sure we can handle the virtio
    stuff).
  - 9001_virtio_virt-install.patch: Add support for virtio and enable
    virtio-net for hardy guests. (LP: #254097)
  - Use python-central instead of python-support

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
6
Adresses parts of #495013
 
7
---
 
8
 virtinst/CloneManager.py |    3 ++-
 
9
 virtinst/util.py         |   35 ++++++++++++++++++++++++++++++-----
 
10
 2 files changed, 32 insertions(+), 6 deletions(-)
 
11
 
 
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):
 
17
 
 
18
         doc = libxml2.parseDoc(self._clone_xml)
 
19
         ctx = doc.xpathNewContext()
 
20
+        type = ctx.xpathEval("/domain")[0].prop("type")
 
21
 
 
22
         # changing name
 
23
         node = ctx.xpathEval("/domain/name")
 
24
@@ -282,7 +283,7 @@ class CloneDesign(object):
 
25
                 node[0].setContent(self._clone_mac[i-1])
 
26
             except Exception, e:
 
27
                 while 1:
 
28
-                    mac = util.randomMAC()
 
29
+                    mac = util.randomMAC(type)
 
30
                     ret, msg = self._check_mac(mac)
 
31
                     if msg is not None:
 
32
                         continue
 
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
 
41
-def randomMAC():
 
42
+def randomMAC(type = "xen"):
 
43
     """Generate a random MAC address.
 
44
 
 
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
 
50
+
 
51
+    The OUI list is available at http://standards.ieee.org/regauth/oui/oui.txt.
 
52
 
 
53
     The remaining 3 fields are random, with the first bit of the first
 
54
     random field set 0.
 
55
 
 
56
+    >>> randomMAC().startswith("00:16:36")
 
57
+    True
 
58
+    >>> randomMAC("foobar").startswith("00:16:36")
 
59
+    True
 
60
+    >>> randomMAC("xen").startswith("00:16:36")
 
61
+    True
 
62
+    >>> randomMAC("qemu").startswith("54:52:00")
 
63
+    True
 
64
+
 
65
     @return: MAC address string
 
66
     """
 
67
-    mac = [ 0x00, 0x16, 0x3e,
 
68
+    ouis = { 'xen': [ 0x00, 0x16, 0x36 ], 'qemu': [ 0x54, 0x52, 0x00 ] }
 
69
+
 
70
+    try:
 
71
+         oui = ouis[type]
 
72
+    except KeyError:
 
73
+         oui = ouis['xen']
 
74
+
 
75
+    mac = oui + [ 
 
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("<", "&lt;")
 
81
     str = str.replace(">", "&gt;")
 
82
     return str
 
83
+
 
84
+def _test():
 
85
+    import doctest
 
86
+    doctest.testmod()
 
87
+
 
88
+if __name__ == "__main__":
 
89
+    _test()
 
90
+
 
91
-- 
 
92
1.5.6.3
 
93