After attaching a bridged network to a guest, if you close the dialog
and open it again, the network field was displayed in blank. So fix it.
This patch also fix the KeyError issue reported in #849
Signed-off-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
---
mockmodel.py | 3 +--
model/vmifaces.py | 28 ++++++++++++----------------
2 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/mockmodel.py b/mockmodel.py
index a765770..cbeeb5d 100644
--- a/mockmodel.py
+++ b/mockmodel.py
@@ -34,7 +34,6 @@ from wok.xmlutils.utils import xml_item_update
from wok.plugins.kimchi import imageinfo
from wok.plugins.kimchi import osinfo
from wok.plugins.kimchi.model import cpuinfo
-from wok.plugins.kimchi.model import vmifaces
from wok.plugins.kimchi.model.groups import PAMGroupsModel
from wok.plugins.kimchi.model.host import DeviceModel
from wok.plugins.kimchi.model.host import DevicesModel
@@ -86,7 +85,7 @@ class MockModel(Model):
self._mock_storagevolumes = MockStorageVolumes()
cpuinfo.get_topo_capabilities = MockModel.get_topo_capabilities
- vmifaces.getDHCPLeases = MockModel.getDHCPLeases
+ libvirt.virNetwork.DHCPLeases = MockModel.getDHCPLeases
libvirt.virDomain.XMLDesc = MockModel.domainXMLDesc
libvirt.virDomain.undefine = MockModel.undefineDomain
libvirt.virDomain.attachDeviceFlags = MockModel.attachDeviceFlags
diff --git a/model/vmifaces.py b/model/vmifaces.py
index 72f717b..0ec89b6 100644
--- a/model/vmifaces.py
+++ b/model/vmifaces.py
@@ -29,14 +29,6 @@ from wok.plugins.kimchi.model.vms import DOM_STATE_MAP, VMModel
from wok.plugins.kimchi.xmlutils.interface import get_iface_xml
-def getDHCPLeases(net, mac):
- try:
- leases = net.DHCPLeases(mac)
- return leases
- except libvirt.libvirtError:
- return []
-
-
class VMIfacesModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
@@ -134,10 +126,9 @@ class VMIfaceModel(object):
info['type'] = iface.attrib['type']
info['mac'] = iface.mac.get('address')
+ info['network'] = iface.source.get('network')
if iface.find("model") is not None:
info['model'] = iface.model.get('type')
- if info['type'] == 'network':
- info['network'] = iface.source.get('network')
if info['type'] == 'bridge':
info['bridge'] = iface.source.get('bridge')
info['ips'] = self._get_ips(vm, info['mac'],
info['network'])
@@ -159,14 +150,19 @@ class VMIfaceModel(object):
# First check the ARP cache.
with open('/proc/net/arp') as f:
ips = [line.split()[0] for line in f.xreadlines() if mac in line]
+
# Some ifaces may be inactive, so if the ARP cache didn't have them,
# and they happen to be assigned via DHCP, we can check there too.
- net = conn.networkLookupByName(network)
- leases = getDHCPLeases(net, mac)
- for lease in leases:
- ip = lease.get('ipaddr')
- if ip not in ips:
- ips.append(ip)
+ try:
+ # Some type of interfaces may not have a network associated with
+ net = conn.networkLookupByName(network)
+ leases = net.DHCPLeases(mac)
+ for lease in leases:
+ ip = lease.get('ipaddr')
+ if ip not in ips:
+ ips.append(ip)
+ except libvirt.libvirtError:
+ pass
return ips
--
2.5.0