mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
devices: interface: Simplify is_conflict_net calls
We don't return a non-fatal error these days, so adjust all callers to only handle failure
This commit is contained in:
parent
c27cdc67de
commit
ebd6091cc8
@ -692,10 +692,7 @@ class vmmCloneVM(vmmGObjectUI):
|
||||
row = self.net_list[orig]
|
||||
|
||||
try:
|
||||
ignore, msg = DeviceInterface.is_conflict_net(
|
||||
self.conn.get_backend(), new)
|
||||
if msg:
|
||||
raise RuntimeError(msg)
|
||||
DeviceInterface.is_conflict_net(self.conn.get_backend(), new)
|
||||
row[NETWORK_INFO_NEW_MAC] = new
|
||||
except Exception as e:
|
||||
self.err.show_err(_("Error changing MAC address: %s") % str(e))
|
||||
|
@ -373,17 +373,6 @@ class vmmNetworkList(vmmGObjectUI):
|
||||
net.validate()
|
||||
except Exception as e:
|
||||
return self.err.val_err(_("Error with network parameters."), e)
|
||||
|
||||
# Make sure there is no mac address collision
|
||||
isfatal, errmsg = net.is_conflict_net(net.conn, net.macaddr)
|
||||
if isfatal:
|
||||
return self.err.val_err(_("Mac address collision."), errmsg)
|
||||
elif errmsg is not None:
|
||||
retv = self.err.yes_no(_("Mac address collision."),
|
||||
_("%s Are you sure you want to use this address?") % errmsg)
|
||||
if not retv:
|
||||
return False
|
||||
|
||||
return net
|
||||
|
||||
def reset_state(self):
|
||||
|
@ -149,10 +149,7 @@ class Cloner(object):
|
||||
def set_clone_macs(self, mac):
|
||||
maclist = util.listify(mac)
|
||||
for m in maclist:
|
||||
msg = DeviceInterface.is_conflict_net(self.conn, m)[1]
|
||||
if msg:
|
||||
raise RuntimeError(msg)
|
||||
|
||||
DeviceInterface.is_conflict_net(self.conn, m)
|
||||
self._clone_macs = maclist
|
||||
def get_clone_macs(self):
|
||||
return self._clone_macs
|
||||
|
@ -170,9 +170,11 @@ class DeviceInterface(Device):
|
||||
|
||||
for ignore in range(256):
|
||||
mac = _random_mac(conn)
|
||||
ret = DeviceInterface.is_conflict_net(conn, mac)
|
||||
if ret[1] is None:
|
||||
try:
|
||||
DeviceInterface.is_conflict_net(conn, mac)
|
||||
return mac
|
||||
except RuntimeError:
|
||||
continue
|
||||
|
||||
logging.debug("Failed to generate non-conflicting MAC")
|
||||
return None
|
||||
@ -180,24 +182,16 @@ class DeviceInterface(Device):
|
||||
@staticmethod
|
||||
def is_conflict_net(conn, searchmac):
|
||||
"""
|
||||
:returns: a two element tuple:
|
||||
first element is True if fatal collision occurred
|
||||
second element is a string description of the collision.
|
||||
|
||||
Non fatal collisions (mac addr collides with inactive guest) will
|
||||
return (False, "description of collision")
|
||||
Raise RuntimeError if the passed mac conflicts with a defined VM
|
||||
"""
|
||||
if searchmac is None:
|
||||
return (False, None)
|
||||
|
||||
vms = conn.fetch_all_domains()
|
||||
for vm in vms:
|
||||
for nic in vm.devices.interface:
|
||||
nicmac = nic.macaddr or ""
|
||||
if nicmac.lower() == searchmac.lower():
|
||||
return (True, _("The MAC address '%s' is in use "
|
||||
"by another virtual machine.") % searchmac)
|
||||
return (False, None)
|
||||
raise RuntimeError(
|
||||
_("The MAC address '%s' is in use "
|
||||
"by another virtual machine.") % searchmac)
|
||||
|
||||
|
||||
###############
|
||||
@ -282,13 +276,7 @@ class DeviceInterface(Device):
|
||||
return
|
||||
|
||||
util.validate_macaddr(self.macaddr)
|
||||
ret, msg = self.is_conflict_net(self.conn, self.macaddr)
|
||||
if msg is None:
|
||||
return
|
||||
if ret is False:
|
||||
logging.warning(msg)
|
||||
else:
|
||||
raise RuntimeError(msg)
|
||||
self.is_conflict_net(self.conn, self.macaddr)
|
||||
|
||||
def set_default_source(self):
|
||||
if (self.conn.is_qemu_session() or self.conn.is_test()):
|
||||
|
Loading…
Reference in New Issue
Block a user