virtManager/interface: detect whether IP address comes from DHCP server

When the network interface is up the active XML contains only IP address
even in case that the inactive XML was configured to get the IP address
from DHCP server.  To propagate this information back to UI we need to
get both XMLs to figure out current IP addresses and the configuration.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1410722

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2017-01-19 18:00:36 +01:00
parent 741ad25bfe
commit 2df8dc39e8
1 changed files with 18 additions and 7 deletions

View File

@ -117,24 +117,35 @@ class vmmInterface(vmmLibvirtObject):
return [x[0] for x in self.get_slaves()]
def _get_ip(self, iptype):
obj = self.get_xmlobj()
found = None
for protocol in obj.protocols:
# Get list of IP addresses from active XML and protocol configuration
# from inactive XML to figure out whether the IP address is static or
# from DHCP server.
activeObj = self.get_xmlobj()
inactiveObj = self.get_xmlobj(inactive=True)
activeProto = None
inactiveProto = None
for protocol in activeObj.protocols:
if protocol.family == iptype:
found = protocol
activeProto = protocol
break
if not found:
for protocol in inactiveObj.protocols:
if protocol.family == iptype:
inactiveProto = protocol
break
if not activeProto and not inactiveProto:
return None, []
ret = []
for ip in found.ips:
for ip in activeProto.ips:
ipstr = ip.address
if not ipstr:
continue
if ip.prefix:
ipstr += "/%s" % ip.prefix
ret.append(ipstr)
return found, ret
return inactiveProto or activeProto, ret
def get_ipv4(self):
proto, ips = self._get_ip("ipv4")