mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
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>
This commit is contained in:
1 parent
1d2beac171
commit
a801b2ab6b
3 files changed
+24
-6
No files matched your search
@@ -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
|
||||
@@ -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 @@ class NetDev(Dev):
|
||||
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 @@ class NetDev(Dev):
|
||||
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.
|
||||
|
||||