ChangeSet 1.1662.1.12, 2005/06/06 20:46:33+01:00, cl349@xxxxxxxxxxxxxxxxxxxx
netif.py:
Use macFromString, macToString.
mac.py:
new file
Signed-off-by: Mike Wray <mike.wray@xxxxxx>
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
util/mac.py | 11 +++++++++++
xend/server/netif.py | 18 ++++++++++++------
2 files changed, 23 insertions(+), 6 deletions(-)
diff -Nru a/tools/python/xen/util/mac.py b/tools/python/xen/util/mac.py
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/tools/python/xen/util/mac.py 2005-06-09 13:08:18 -04:00
@@ -0,0 +1,11 @@
+
+from string import join, split
+
+def macToString(mac):
+ return ':'.join(map(lambda x: "%02x" % x, mac))
+
+def macFromString(str):
+ mac = [ int(x, 16) for x in str.split(':') ]
+ if len(mac) != 6:
+ raise ValueError("invalid mac: %s" % str)
+ return mac
diff -Nru a/tools/python/xen/xend/server/netif.py
b/tools/python/xen/xend/server/netif.py
--- a/tools/python/xen/xend/server/netif.py 2005-06-09 13:08:18 -04:00
+++ b/tools/python/xen/xend/server/netif.py 2005-06-09 13:08:18 -04:00
@@ -4,6 +4,8 @@
import random
+from xen.util.mac import macFromString, macToString
+
from xen.xend import sxp
from xen.xend import Vifctl
from xen.xend.XendError import XendError, VmError
@@ -49,15 +51,19 @@
def _get_config_mac(self, config):
vmac = sxp.child_value(config, 'mac')
if not vmac: return None
- mac = [ int(x, 16) for x in vmac.split(':') ]
- if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
+ try:
+ mac = macFromString(vmac)
+ except:
+ raise XendError("invalid mac: %s" % vmac)
return mac
def _get_config_be_mac(self, config):
vmac = sxp.child_value(config, 'be_mac')
if not vmac: return None
- mac = [ int(x, 16) for x in vmac.split(':') ]
- if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
+ try:
+ mac = macFromString(vmac)
+ except:
+ raise XendError("invalid backend mac: %s" % vmac)
return mac
def _get_config_ipaddr(self, config):
@@ -212,12 +218,12 @@
def get_mac(self):
"""Get the MAC address as a string.
"""
- return ':'.join(map(lambda x: "%02x" % x, self.mac))
+ return macToString(self.mac)
def get_be_mac(self):
"""Get the backend MAC address as a string.
"""
- return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
+ return macToString(self.be_mac)
def vifctl_params(self, vmname=None):
"""Get the parameters to pass to vifctl.
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|