ia64/xen-unstable

changeset 7650:b47b79585772

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@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Nov 07 12:36:53 2005 +0100 (2005-11-07)
parents f392a8fc7494
children a4bd444c5424 12c3b4463cba
files tools/python/xen/xend/server/netif.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xend/server/netif.py	Mon Nov 07 12:36:44 2005 +0100
     1.2 +++ b/tools/python/xen/xend/server/netif.py	Mon Nov 07 12:36:53 2005 +0100
     1.3 @@ -21,6 +21,7 @@
     1.4  """
     1.5  
     1.6  import os
     1.7 +import random
     1.8  
     1.9  from xen.xend import sxp
    1.10  from xen.xend import XendRoot
    1.11 @@ -31,6 +32,25 @@ from xen.xend.server.DevController impor
    1.12  xroot = XendRoot.instance()
    1.13  
    1.14  
    1.15 +def randomMAC():
    1.16 +    """Generate a random MAC address.
    1.17 +
    1.18 +    Uses OUI (Organizationally Unique Identifier) AA:00:00, an
    1.19 +    unassigned one that used to belong to DEC. The OUI list is
    1.20 +    available at 'standards.ieee.org'.
    1.21 +
    1.22 +    The remaining 3 fields are random, with the first bit of the first
    1.23 +    random field set 0.
    1.24 +
    1.25 +    @return: MAC address string
    1.26 +    """
    1.27 +    mac = [ 0xaa, 0x00, 0x00,
    1.28 +            random.randint(0x00, 0x7f),
    1.29 +            random.randint(0x00, 0xff),
    1.30 +            random.randint(0x00, 0xff) ]
    1.31 +    return ':'.join(map(lambda x: "%02x" % x, mac))
    1.32 +
    1.33 +
    1.34  class NetifController(DevController):
    1.35      """Network interface controller. Handles all network devices for a domain.
    1.36      """
    1.37 @@ -57,6 +77,9 @@ class NetifController(DevController):
    1.38  
    1.39          devid = self.allocateDeviceID()
    1.40  
    1.41 +        if not mac:
    1.42 +            mac = randomMAC()
    1.43 +
    1.44          back = { 'script' : script,
    1.45                   'mac'    : mac,
    1.46                   'handle' : "%i" % devid }
     2.1 --- a/tools/python/xen/xm/create.py	Mon Nov 07 12:36:44 2005 +0100
     2.2 +++ b/tools/python/xen/xm/create.py	Mon Nov 07 12:36:53 2005 +0100
     2.3 @@ -19,7 +19,6 @@
     2.4  
     2.5  """Domain creation.
     2.6  """
     2.7 -import random
     2.8  import os
     2.9  import os.path
    2.10  import string
    2.11 @@ -497,24 +496,6 @@ def configure_tpmif(config_devs, vals):
    2.12              config_devs.append(['device', config_tpmif])
    2.13  
    2.14  
    2.15 -def randomMAC():
    2.16 -    """Generate a random MAC address.
    2.17 -
    2.18 -    Uses OUI (Organizationally Unique Identifier) AA:00:00, an
    2.19 -    unassigned one that used to belong to DEC. The OUI list is
    2.20 -    available at 'standards.ieee.org'.
    2.21 -
    2.22 -    The remaining 3 fields are random, with the first bit of the first
    2.23 -    random field set 0.
    2.24 -
    2.25 -    @return: MAC address string
    2.26 -    """
    2.27 -    mac = [ 0xaa, 0x00, 0x00,
    2.28 -            random.randint(0x00, 0x7f),
    2.29 -            random.randint(0x00, 0xff),
    2.30 -            random.randint(0x00, 0xff) ]
    2.31 -    return ':'.join(map(lambda x: "%02x" % x, mac))
    2.32 -
    2.33  def configure_vifs(config_devs, vals):
    2.34      """Create the config for virtual network interfaces.
    2.35      """
    2.36 @@ -525,8 +506,6 @@ def configure_vifs(config_devs, vals):
    2.37          if idx < len(vifs):
    2.38              d = vifs[idx]
    2.39              mac = d.get('mac')
    2.40 -            if not mac:
    2.41 -                mac = randomMAC()
    2.42              be_mac = d.get('be_mac')
    2.43              bridge = d.get('bridge')
    2.44              script = d.get('script')
    2.45 @@ -534,8 +513,7 @@ def configure_vifs(config_devs, vals):
    2.46              ip = d.get('ip')
    2.47              vifname = d.get('vifname')
    2.48          else:
    2.49 -            
    2.50 -            mac = randomMAC()
    2.51 +            mac = None
    2.52              be_mac = None
    2.53              bridge = None
    2.54              script = None
    2.55 @@ -543,7 +521,8 @@ def configure_vifs(config_devs, vals):
    2.56              ip = None
    2.57              vifname = None
    2.58          config_vif = ['vif']
    2.59 -        config_vif.append(['mac', mac])
    2.60 +        if mac:
    2.61 +            config_vif.append(['mac', mac])
    2.62          if vifname:
    2.63              config_vif.append(['vifname', vifname])
    2.64          if be_mac:
    2.65 @@ -925,8 +904,6 @@ def parseCommandLine(argv):
    2.66  
    2.67  
    2.68  def main(argv):
    2.69 -    random.seed()
    2.70 -
    2.71      (opts, config) = parseCommandLine(argv)
    2.72  
    2.73      if not opts: