[virt-tools-list] [virt-manager PATCH] virtManager/interface: detect whether IP address comes from DHCP server

Pavel Hrdina phrdina at redhat.com
Thu Jan 19 17:07:46 UTC 2017


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 at redhat.com>
---
 virtManager/interface.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/virtManager/interface.py b/virtManager/interface.py
index 3af59743..2fe61b2a 100644
--- a/virtManager/interface.py
+++ b/virtManager/interface.py
@@ -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")
-- 
2.11.0




More information about the virt-tools-list mailing list