mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 9605: use CIDR from default interface
This commit is contained in:
parent
a728f5b071
commit
3b93d353d6
@ -182,7 +182,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
s_logger.debug("ConfigurationServer could not detect mount.parent.");
|
||||
}
|
||||
|
||||
String hostIpAdr = getHost();
|
||||
String hostIpAdr = NetUtils.getDefaultHostIp();
|
||||
if (hostIpAdr != null) {
|
||||
_configDao.update("host", hostIpAdr);
|
||||
s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host.");
|
||||
@ -243,23 +243,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getEthDevice() {
|
||||
String defaultRoute = Script.runSimpleBashScript("/sbin/route | grep default");
|
||||
|
||||
if (defaultRoute == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] defaultRouteList = defaultRoute.split("\\s+");
|
||||
|
||||
if (defaultRouteList.length != 8) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return defaultRouteList[7];
|
||||
}
|
||||
|
||||
private String getMountParent() {
|
||||
return getEnvironmentProperty("mount.parent");
|
||||
}
|
||||
@ -283,26 +266,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@DB
|
||||
protected String getHost() {
|
||||
NetworkInterface nic = null;
|
||||
String pubNic = getEthDevice();
|
||||
|
||||
if (pubNic == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
nic = NetworkInterface.getByName(pubNic);
|
||||
} catch (final SocketException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] info = NetUtils.getNetworkParams(nic);
|
||||
return info[0];
|
||||
}
|
||||
|
||||
@DB
|
||||
protected void saveUser() {
|
||||
// insert system account
|
||||
|
||||
@ -40,6 +40,7 @@ import org.apache.log4j.xml.DOMConfigurator;
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class NetUtils {
|
||||
protected final static Logger s_logger = Logger.getLogger(NetUtils.class);
|
||||
@ -113,6 +114,8 @@ public class NetUtils {
|
||||
}
|
||||
|
||||
public static String[] getLocalCidrs() {
|
||||
String defaultHostIp = getDefaultHostIp();
|
||||
|
||||
List<String> cidrList = new ArrayList<String>();
|
||||
try {
|
||||
for (NetworkInterface ifc : IteratorUtil.enumerationAsIterable(NetworkInterface.getNetworkInterfaces())) {
|
||||
@ -122,6 +125,7 @@ public class NetUtils {
|
||||
int prefixLength = address.getNetworkPrefixLength();
|
||||
if (prefixLength < 32 && prefixLength > 0) {
|
||||
String ip = ipFromInetAddress(addr);
|
||||
if(ip.equalsIgnoreCase(defaultHostIp))
|
||||
cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength)));
|
||||
}
|
||||
}
|
||||
@ -134,6 +138,40 @@ public class NetUtils {
|
||||
return cidrList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static String getDefaultHostIp() {
|
||||
NetworkInterface nic = null;
|
||||
String pubNic = getDefaultEthDevice();
|
||||
|
||||
if (pubNic == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
nic = NetworkInterface.getByName(pubNic);
|
||||
} catch (final SocketException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] info = NetUtils.getNetworkParams(nic);
|
||||
return info[0];
|
||||
}
|
||||
|
||||
public static String getDefaultEthDevice() {
|
||||
String defaultRoute = Script.runSimpleBashScript("/sbin/route | grep default");
|
||||
|
||||
if (defaultRoute == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] defaultRouteList = defaultRoute.split("\\s+");
|
||||
|
||||
if (defaultRouteList.length != 8) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return defaultRouteList[7];
|
||||
}
|
||||
|
||||
public static InetAddress getFirstNonLoopbackLocalInetAddress() {
|
||||
InetAddress[] addrs = getAllLocalInetAddresses();
|
||||
if (addrs != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user