mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-10-27 10:25:25 +03:00
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:
parent
741ad25bfe
commit
2df8dc39e8
@ -117,24 +117,35 @@ class vmmInterface(vmmLibvirtObject):
|
|||||||
return [x[0] for x in self.get_slaves()]
|
return [x[0] for x in self.get_slaves()]
|
||||||
|
|
||||||
def _get_ip(self, iptype):
|
def _get_ip(self, iptype):
|
||||||
obj = self.get_xmlobj()
|
# Get list of IP addresses from active XML and protocol configuration
|
||||||
found = None
|
# from inactive XML to figure out whether the IP address is static or
|
||||||
for protocol in obj.protocols:
|
# 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:
|
if protocol.family == iptype:
|
||||||
found = protocol
|
activeProto = protocol
|
||||||
break
|
break
|
||||||
if not found:
|
for protocol in inactiveObj.protocols:
|
||||||
|
if protocol.family == iptype:
|
||||||
|
inactiveProto = protocol
|
||||||
|
break
|
||||||
|
|
||||||
|
if not activeProto and not inactiveProto:
|
||||||
return None, []
|
return None, []
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for ip in found.ips:
|
for ip in activeProto.ips:
|
||||||
ipstr = ip.address
|
ipstr = ip.address
|
||||||
if not ipstr:
|
if not ipstr:
|
||||||
continue
|
continue
|
||||||
if ip.prefix:
|
if ip.prefix:
|
||||||
ipstr += "/%s" % ip.prefix
|
ipstr += "/%s" % ip.prefix
|
||||||
ret.append(ipstr)
|
ret.append(ipstr)
|
||||||
return found, ret
|
return inactiveProto or activeProto, ret
|
||||||
|
|
||||||
def get_ipv4(self):
|
def get_ipv4(self):
|
||||||
proto, ips = self._get_ip("ipv4")
|
proto, ips = self._get_ip("ipv4")
|
||||||
|
Loading…
Reference in New Issue
Block a user