WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Move the randomMAC method from xm.create into server.net

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Move the randomMAC method from xm.create into server.netif. This way, it can
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 07 Nov 2005 13:08:11 +0000
Delivery-date: Mon, 07 Nov 2005 13:08:57 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID b47b795857727e0489812cdaf7881f0c94bf0d70
# Parent  f392a8fc74944976e574508a28c72b5b36063fe6
Move the randomMAC method from xm.create into server.netif.  This way, it can
be shared with other command line tools, and the xm network-attach command.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r f392a8fc7494 -r b47b79585772 tools/python/xen/xend/server/netif.py
--- a/tools/python/xen/xend/server/netif.py     Mon Nov  7 11:36:44 2005
+++ b/tools/python/xen/xend/server/netif.py     Mon Nov  7 11:36:53 2005
@@ -21,6 +21,7 @@
 """
 
 import os
+import random
 
 from xen.xend import sxp
 from xen.xend import XendRoot
@@ -29,6 +30,25 @@
 
 
 xroot = XendRoot.instance()
+
+
+def randomMAC():
+    """Generate a random MAC address.
+
+    Uses OUI (Organizationally Unique Identifier) AA:00:00, an
+    unassigned one that used to belong to DEC. The OUI list is
+    available at 'standards.ieee.org'.
+
+    The remaining 3 fields are random, with the first bit of the first
+    random field set 0.
+
+    @return: MAC address string
+    """
+    mac = [ 0xaa, 0x00, 0x00,
+            random.randint(0x00, 0x7f),
+            random.randint(0x00, 0xff),
+            random.randint(0x00, 0xff) ]
+    return ':'.join(map(lambda x: "%02x" % x, mac))
 
 
 class NetifController(DevController):
@@ -56,6 +76,9 @@
         ipaddr = _get_config_ipaddr(config)
 
         devid = self.allocateDeviceID()
+
+        if not mac:
+            mac = randomMAC()
 
         back = { 'script' : script,
                  'mac'    : mac,
diff -r f392a8fc7494 -r b47b79585772 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Mon Nov  7 11:36:44 2005
+++ b/tools/python/xen/xm/create.py     Mon Nov  7 11:36:53 2005
@@ -19,7 +19,6 @@
 
 """Domain creation.
 """
-import random
 import os
 import os.path
 import string
@@ -497,24 +496,6 @@
             config_devs.append(['device', config_tpmif])
 
 
-def randomMAC():
-    """Generate a random MAC address.
-
-    Uses OUI (Organizationally Unique Identifier) AA:00:00, an
-    unassigned one that used to belong to DEC. The OUI list is
-    available at 'standards.ieee.org'.
-
-    The remaining 3 fields are random, with the first bit of the first
-    random field set 0.
-
-    @return: MAC address string
-    """
-    mac = [ 0xaa, 0x00, 0x00,
-            random.randint(0x00, 0x7f),
-            random.randint(0x00, 0xff),
-            random.randint(0x00, 0xff) ]
-    return ':'.join(map(lambda x: "%02x" % x, mac))
-
 def configure_vifs(config_devs, vals):
     """Create the config for virtual network interfaces.
     """
@@ -525,8 +506,6 @@
         if idx < len(vifs):
             d = vifs[idx]
             mac = d.get('mac')
-            if not mac:
-                mac = randomMAC()
             be_mac = d.get('be_mac')
             bridge = d.get('bridge')
             script = d.get('script')
@@ -534,8 +513,7 @@
             ip = d.get('ip')
             vifname = d.get('vifname')
         else:
-            
-            mac = randomMAC()
+            mac = None
             be_mac = None
             bridge = None
             script = None
@@ -543,7 +521,8 @@
             ip = None
             vifname = None
         config_vif = ['vif']
-        config_vif.append(['mac', mac])
+        if mac:
+            config_vif.append(['mac', mac])
         if vifname:
             config_vif.append(['vifname', vifname])
         if be_mac:
@@ -925,8 +904,6 @@
 
 
 def main(argv):
-    random.seed()
-
     (opts, config) = parseCommandLine(argv)
 
     if not opts:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Move the randomMAC method from xm.create into server.netif. This way, it can, Xen patchbot -unstable <=