cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cloudstack] DaanHoogland commented on a change in pull request #3704: utils: use iproute to get default network interface
Date Fri, 22 Nov 2019 15:25:57 GMT
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_r349648997
 
 

 ##########
 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("ip route | grep default | head -1 | grep -Po '(?<=dev
)(\\S+)'");
 
 Review comment:
   ```ip route show default``` does not work with ip from brew on mac (which is not a big
issue but would be nice.
   my hope of unifying mac with other OSses just broke again:
   ```
   baloujak:var dahn$ ip route list | grep default
   default via 192.168.144.99 dev en0
   baloujak:var dahn$ ip route show | grep default
   default via 192.168.144.99 dev en0
   baloujak:var dahn$ ip route | grep default
   default via 192.168.144.99 dev en0
   baloujak:var dahn$ ip route | grep default | awk '{print $3}'
   192.168.144.99
   baloujak:var dahn$ ip route | grep default | awk '{print $5}'
   en0
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message