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

[Xen-changelog] Move the randomMAC method from xm.create into server.netif. This way, it can



# 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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.