ia64/xen-unstable

changeset 5350:59e72b0399ac

bitkeeper revision 1.1662.1.12 (42a4a819BMGTxn8p4rsFdp44pCQ_Og)

netif.py:
Use macFromString, macToString.
mac.py:
new file
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Mon Jun 06 19:46:33 2005 +0000 (2005-06-06)
parents c768bf758ce1
children 6ffbb7f12940
files .rootkeys tools/python/xen/util/mac.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/.rootkeys	Mon Jun 06 19:22:19 2005 +0000
     1.2 +++ b/.rootkeys	Mon Jun 06 19:46:33 2005 +0000
     1.3 @@ -812,6 +812,7 @@ 40dfd40aGqGkiopOOgJxSF4iCbHM0Q tools/pyt
     1.4  4270e4efFg3wHCCxXpA0h6yoMTkeSQ tools/python/xen/util/blkif.py
     1.5  4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
     1.6  40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
     1.7 +42a4a80aiq_AT5whiSw-fKhNhRKITw tools/python/xen/util/mac.py
     1.8  41dde8b0yuJX-S79w4xJKxBQ-Mhp1A tools/python/xen/util/memmap.py
     1.9  4288c6fcB1kUAqX0gzU85GGxmamS4Q tools/python/xen/util/process.py
    1.10  4059c6a0pnxhG8hwSOivXybbGOwuXw tools/python/xen/util/tempfile.py
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/python/xen/util/mac.py	Mon Jun 06 19:46:33 2005 +0000
     2.3 @@ -0,0 +1,11 @@
     2.4 +
     2.5 +from string import join, split
     2.6 +
     2.7 +def macToString(mac):
     2.8 +    return ':'.join(map(lambda x: "%02x" % x, mac))
     2.9 +
    2.10 +def macFromString(str):
    2.11 +    mac = [ int(x, 16) for x in str.split(':') ]
    2.12 +    if len(mac) != 6:
    2.13 +        raise ValueError("invalid mac: %s" % str)
    2.14 +    return mac
     3.1 --- a/tools/python/xen/xend/server/netif.py	Mon Jun 06 19:22:19 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/netif.py	Mon Jun 06 19:46:33 2005 +0000
     3.3 @@ -4,6 +4,8 @@
     3.4  
     3.5  import random
     3.6  
     3.7 +from xen.util.mac import macFromString, macToString
     3.8 +
     3.9  from xen.xend import sxp
    3.10  from xen.xend import Vifctl
    3.11  from xen.xend.XendError import XendError, VmError
    3.12 @@ -49,15 +51,19 @@ class NetDev(Dev):
    3.13      def _get_config_mac(self, config):
    3.14          vmac = sxp.child_value(config, 'mac')
    3.15          if not vmac: return None
    3.16 -        mac = [ int(x, 16) for x in vmac.split(':') ]
    3.17 -        if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
    3.18 +        try:
    3.19 +            mac = macFromString(vmac)
    3.20 +        except:
    3.21 +            raise XendError("invalid mac: %s" % vmac)
    3.22          return mac
    3.23  
    3.24      def _get_config_be_mac(self, config):
    3.25          vmac = sxp.child_value(config, 'be_mac')
    3.26          if not vmac: return None
    3.27 -        mac = [ int(x, 16) for x in vmac.split(':') ]
    3.28 -        if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
    3.29 +        try:
    3.30 +            mac = macFromString(vmac)
    3.31 +        except:
    3.32 +            raise XendError("invalid backend mac: %s" % vmac)
    3.33          return mac
    3.34  
    3.35      def _get_config_ipaddr(self, config):
    3.36 @@ -212,12 +218,12 @@ class NetDev(Dev):
    3.37      def get_mac(self):
    3.38          """Get the MAC address as a string.
    3.39          """
    3.40 -        return ':'.join(map(lambda x: "%02x" % x, self.mac))
    3.41 +        return macToString(self.mac)
    3.42  
    3.43      def get_be_mac(self):
    3.44          """Get the backend MAC address as a string.
    3.45          """
    3.46 -        return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
    3.47 +        return macToString(self.be_mac)
    3.48  
    3.49      def vifctl_params(self, vmname=None):
    3.50          """Get the parameters to pass to vifctl.