[PATCH 1/2] Add method to grab the first non-localhost IP

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


This is mostly code that was in vnc.py as well as anaconda itself.
---
 pyanaconda/network.py |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 2b8ca7d..103816e 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -566,6 +566,27 @@ class Network:
 
         return ip
 
+    # Return a list of IP addresses for all active devices.
+    def getIPs(self):
+        ips = []
+        for dev in getActiveNetDevs():
+            devname = self.netdevices[dev].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 ip addr "
+                            "of %s: %s" % (devname, e))
+
+        return ips
+
+    # Return the first real non-local IP we find
+    def getFirstRealIP(self):
+        for ip in self.getIPs():
+            if ip not in ("127.0.0.1", "::1"):
+                return ip
+        return None
+
     # Note that the file is written-out only if there is a value
     # that has changed.
     def writeIfcfgFiles(self):
-- 
1.7.10.2



More information about the anaconda-patches mailing list