[PATCH 2/2] Make use of common code to fetch IP

Jesse Keating jkeating at redhat.com
Thu Jun 28 23:46:21 UTC 2012


---
 anaconda          |   20 ++++----------------
 pyanaconda/vnc.py |   28 ++++++++++------------------
 2 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/anaconda b/anaconda
index be8c7be..88335f8 100755
--- a/anaconda
+++ b/anaconda
@@ -611,23 +611,11 @@ def prompt_for_ssh():
     # see if we can sniff out network info
     netinfo = network.Network()
 
-    devices = netinfo.netdevices
-    active_devs = network.getActiveNetDevs()
+    ip = netinfo.getFirstRealIP()
 
-    ip = None
-    if active_devs != []:
-        devname = devices[active_devs[0]].iface
-        try:
-            ips = (isys.getIPAddresses(devname, version=4) +
-                   isys.getIPAddresses(devname, version=6))
-        except Exception as e:
-            stdoutLog.warning("Got an exception trying to get the ip addr "
-                        "of %s: %s" % (devname, e))
-        else:
-            if ips and ips[0] not in ("127.0.0.1", "::1"):
-                stdoutLog.debug("IPs (using first) of device %s: %s" % (devname,
-                                                                 ips))
-                ip = ips[0]
+    if not ip:
+        stdoutLog.error("No IP addresses found, cannot continue installation.")
+        sys.exit(1)
 
     ipstr = ip
 
diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index a7ccc76..2f87650 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -80,23 +80,11 @@ class VncServer:
         # see if we can sniff out network info
         netinfo = network.Network()
 
-        devices = netinfo.netdevices
-        active_devs = network.getActiveNetDevs()
-
-        self.ip = None
-        if active_devs != []:
-            devname = devices[active_devs[0]].iface
-            try:
-                ips = (isys.getIPAddresses(devname, version=4) +
-                       isys.getIPAddresses(devname, version=6))
-            except Exception as e:
-                log.warning("Got an exception trying to get the self.ip addr "
-                            "of %s: %s" % (devname, e))
-            else:
-                if ips and ips[0] not in ("127.0.0.1", "::1"):
-                    log.info("IPs (using first) of device %s: %s" % (devname,
-                                                                     ips))
-                    self.ip = ips[0]
+        self.ip = netinfo.getFirstRealIP()
+
+        if not self.ip:
+            # Raise this here which will be caught higher up
+            raise Exception("No IP addresses found.")
 
         ipstr = self.ip
 
@@ -187,7 +175,11 @@ class VncServer:
         self.log.info(_("Starting VNC..."))
 
         # Lets call it from here for now.
-        self.initialize()
+        try:
+            self.initialize()
+        except Exception, e:
+            stdoutLog.critical("Could not initialize the VNC server: %s" % e)
+            sys.exit(1)
 
         if self.password and len(self.password) < 6:
             self.changeVNCPasswdWindow()
-- 
1.7.10.2



More information about the anaconda-patches mailing list