virtinst: nic: Don't check MAC collision with host

It was:

- Slow
- Not that useful
- Only worked in the local case

If anyone cares, the proper thing to do is implement it with the iface APIs.
This commit is contained in:
Cole Robinson 2013-04-11 11:24:37 -04:00
parent e0e3c212e4
commit 69d3f21da6
3 changed files with 0 additions and 38 deletions

View File

@ -459,15 +459,6 @@ class TestValidation(unittest.TestCase):
network = virtinst.VirtualNetworkInterface(conn=testconn)
self._testArgs(network, virtinst.VirtualNetworkInterface, 'network')
# Test MAC Address collision
hostmac = virtinst.util.get_host_network_devices()
if len(hostmac) is not 0:
hostmac = hostmac[0][4]
for params in ({'macaddr' : hostmac},):
network = virtinst.VirtualNetworkInterface(*(), **params)
self.assertRaises(RuntimeError, network.setup, \
testconn)
# Test dynamic MAC/Bridge success
try:
network = virtinst.VirtualNetworkInterface()

View File

@ -334,22 +334,11 @@ class VirtualNetworkInterface(VirtualDevice.VirtualDevice):
vms, inactive_vm = util.fetch_all_guests(conn)
# get the Host's NIC MAC address
hostdevs = []
if not self.is_remote():
hostdevs = util.get_host_network_devices()
if (_countMACaddr(vms, mac) > 0 or
_countMACaddr(inactive_vm, mac) > 0):
return (True, _("The MAC address you entered is already in use "
"by another virtual machine."))
for dev in hostdevs:
host_macaddr = dev[4]
if mac.upper() == host_macaddr.upper():
return (True, _("The MAC address you entered conflicts with "
"a device on the physical host."))
return (False, None)
def setup_dev(self, conn=None, meter=None):

View File

@ -606,24 +606,6 @@ def uuidToString(u, conn=None):
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
"%02x" * 6]) % tuple(u)
def get_host_network_devices():
device = []
for dirname in ['', '/sbin/', '/usr/sbin']:
executable = os.path.join(dirname, "ifconfig")
if not os.path.exists(executable):
continue
try:
cmd = 'LC_ALL=C %s -a 2>/dev/null' % (executable)
pipe = os.popen(cmd)
except IOError:
continue
for line in pipe:
if line.find("encap:Ethernet") > 0:
words = line.lower().split()
for i in range(len(words)):
if words[i] == "hwaddr":
device.append(words)
return device
def get_max_vcpus(conn, type=None):
"""@param conn: libvirt connection to poll for max possible vcpus