DaanHoogland commented on a change in pull request #3704: utils: use iproute to 
get default network interface
URL: https://github.com/apache/cloudstack/pull/3704#discussion_r350715334
 
 

 ##########
 File path: utils/src/main/java/com/cloud/utils/net/NetUtils.java
 ##########
 @@ -268,19 +268,7 @@ public static String getDefaultEthDevice() {
             final String defDev = Script.runSimpleBashScript("/sbin/route -n 
get default 2> /dev/null | grep interface | awk '{print $2}'");
             return defDev;
         }
-        final String defaultRoute = Script.runSimpleBashScript("/sbin/route | 
grep default");
-
-        if (defaultRoute == null) {
-            return null;
-        }
-
-        final String[] defaultRouteList = defaultRoute.split("\\s+");
-
-        if (defaultRouteList.length != 8) {
-            return null;
-        }
-
-        return defaultRouteList[7];
+        return Script.runSimpleBashScript("awk '$2 == 00000000 { print $1 }' 
/proc/net/route");
 
 Review comment:
   in @wido 's style i'd prefer: (whatever happened to "suggest change"?)
   ```ip route show default 0.0.0.0/0|head -1|awk '{print $5}'```
   note that we do need the fifth field, i.e. return the device not an address.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to