[NEW PATCH] BZ#716692 Report gateway when using dhcp (via gerrit-bot)

Federico Simoncelli fsimonce at redhat.com
Tue Jun 28 18:18:24 UTC 2011


New patch submitted by Federico Simoncelli (fsimonce at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/631

commit 59a68c0bf929db55058a3e4db78c8f86bbf6247d
Author: Federico Simoncelli <fsimonce at redhat.com>
Date:   Tue Jun 28 14:00:31 2011 +0000

    BZ#716692 Report gateway when using dhcp
    
    Change-Id: Ifcafa3617bcab3a720f229bfce45d49c9109b37d

diff --git a/vdsm/netinfo.py b/vdsm/netinfo.py
index d2d0795..3866add 100644
--- a/vdsm/netinfo.py
+++ b/vdsm/netinfo.py
@@ -131,6 +131,27 @@ def getVlanBondingNic(bridge):
             nics = [iface]
     return vlan, bonding, nics
 
+def getIfaceGateway(iface):
+    """Return the interface gateway or None if not found."""
+
+    with open("/proc/net/route") as route_file:
+        for route_line in route_file.xreadlines():
+            route_parm = route_line.rstrip().split('\t')
+
+            if route_parm[0] == iface and route_parm[2] != '00000000':
+                ip_num = int(route_parm[2], 16)
+                break
+        else:
+            return None
+
+    ip_address = []
+
+    for i in xrange(4):
+        ip_num, ip_val = divmod(ip_num, 256)
+        ip_address.append(str(ip_val))
+
+    return '.'.join(ip_address)
+
 def getIfaceCfg(iface):
     d = {}
     try:
@@ -144,6 +165,12 @@ def getIfaceCfg(iface):
                 pass
     except:
         pass
+
+    gateway = getIfaceGateway(iface)
+
+    if gateway:
+        d['GATEWAY'] = gateway
+
     return d
 
 def permAddr():




More information about the vdsm-patches mailing list