This is an automated email from the ASF dual-hosted git repository. rohit pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push: new 0470033 utils: reverse ip addresses of a nic returned by java to get the first ip address (#3449) 0470033 is described below commit 047003315be799e6b12a8c3eeaf7f21da13f767e Author: Wei Zhou <ustcweiz...@gmail.com> AuthorDate: Tue Jul 2 09:46:18 2019 +0200 utils: reverse ip addresses of a nic returned by java to get the first ip address (#3449) Java methods getInterfaceAddresses() returns ip addresses in reverse order as "ip addr show" If there are multiple IPs assigned to a management interface, the last ip will be used as management ip in cloudstack. We need to reverse the ip addresses to get the first ip that makes more sense. Fixes #3311 --- utils/src/main/java/com/cloud/utils/net/NetUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/src/main/java/com/cloud/utils/net/NetUtils.java b/utils/src/main/java/com/cloud/utils/net/NetUtils.java index dce6c25..baddad2 100644 --- a/utils/src/main/java/com/cloud/utils/net/NetUtils.java +++ b/utils/src/main/java/com/cloud/utils/net/NetUtils.java @@ -34,6 +34,7 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Formatter; import java.util.List; +import java.util.Collections; import java.util.Random; import java.util.Set; import java.util.SortedSet; @@ -410,10 +411,11 @@ public class NetUtils { } public static String[] getNetworkParams(final NetworkInterface nic) { - final List<InterfaceAddress> addrs = nic.getInterfaceAddresses(); + List<InterfaceAddress> addrs = nic.getInterfaceAddresses(); if (addrs == null || addrs.size() == 0) { return null; } + Collections.reverse(addrs); // reverse addresses because it has reverse order as "ip addr show" InterfaceAddress addr = null; for (final InterfaceAddress iaddr : addrs) { final InetAddress inet = iaddr.getAddress();