[PATCH rhel7-branch] network: show ip of device with default route for vnc and ssh (#1083305)

Radek Vykydal rvykydal at redhat.com
Wed Apr 9 07:38:39 UTC 2014


Resolves: rhbz#1083305

I keep falling back to use previous method of getting ip addresses for IPv6
only case.

The functions used should be refactored but at this stage I am choosing
safer approach of using new function and fallback to original one.
For master I'll post refactored version.

---
 anaconda              |  2 +-
 pyanaconda/network.py | 11 +++++++++++
 pyanaconda/vnc.py     |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/anaconda b/anaconda
index 42af682..2a802a3 100755
--- a/anaconda
+++ b/anaconda
@@ -630,7 +630,7 @@ def prompt_for_ssh():
     import gettext
     _ = lambda x: gettext.ldgettext("anaconda", x)
 
-    ip = network.getFirstRealIP()
+    ip = network.get_default_device_ip() or network.getFirstRealIP()
 
     if not ip:
         stdoutLog.error("No IP addresses found, cannot continue installation.")
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 63f2ef7..75d2711 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -145,6 +145,17 @@ def getFirstRealIP():
             return ip
     return None
 
+def get_default_device_ip():
+    ip = None
+    devname = default_route_device()
+    if devname:
+        try:
+            ip = nm.nm_device_ip_addresses(devname, version=4)[0]
+        except Exception as e:
+            log.warning("Got an exception trying to get the ip addr "
+                        "of %s: %s" % (devname, e))
+    return ip
+
 def netmask2prefix(netmask):
     prefix = 0
 
diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index 3422cc8..67e4d8f 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -100,7 +100,7 @@ class VncServer:
         # Network may be slow. Try for 5 seconds
         tries = 5
         while tries:
-            self.ip = network.getFirstRealIP()
+            self.ip = network.get_default_device_ip() or network.getFirstRealIP()
             if self.ip:
                 break
             time.sleep(1)
-- 
1.7.11.7



More information about the anaconda-patches mailing list