diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 89f80d6b88d..22b18ba4e7d 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -102,6 +102,6 @@ - + diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 6a7f9805cb6..de1709d36f0 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -33,6 +33,7 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import com.cloud.acl.SecurityChecker; +import com.cloud.alert.AlertManager; import com.cloud.api.commands.CreateCfgCmd; import com.cloud.api.commands.CreateDiskOfferingCmd; import com.cloud.api.commands.CreateNetworkOfferingCmd; @@ -157,6 +158,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Inject AccountManager _accountMgr; @Inject NetworkManager _networkMgr; @Inject ClusterDao _clusterDao; + @Inject AlertManager _alertMgr; @Inject(adapter=SecurityChecker.class) Adapters _secChecker; @@ -209,6 +211,27 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Override public boolean start() { + + // TODO : this may not be a good place to do integrity check here, we put it here as we need _alertMgr to be properly configured + // before we can use it + + // As it is so common for people to forget about configuring management.network.cidr, + String mgtCidr = _configDao.getValue(Config.ManagementNetwork.key()); + if(mgtCidr == null || mgtCidr.trim().isEmpty()) { + String[] localCidrs = NetUtils.getLocalCidrs(); + if(localCidrs.length > 0) { + s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]); + + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), + "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], ""); + _configDao.update(Config.ManagementNetwork.key(), localCidrs[0]); + } else { + s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting"); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), + "Management network CIDR is not properly configured and we are not able to find a default setting", ""); + } + } + return true; } diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java index 4a975632b74..fae93b35d86 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -102,6 +102,26 @@ public class NetUtils { return addrs; } + public static String[] getLocalCidrs() { + List cidrList = new ArrayList(); + try { + for(NetworkInterface ifc : IteratorUtil.enumerationAsIterable(NetworkInterface.getNetworkInterfaces())) { + for (InterfaceAddress address : ifc.getInterfaceAddresses()) { + InetAddress addr = address.getAddress(); + int prefixLength = address.getNetworkPrefixLength(); + if(prefixLength < 32 && prefixLength > 0) { + String ip = ipFromInetAddress(addr); + cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength))); + } + } + } + } catch(SocketException e) { + s_logger.warn("UnknownHostException in getLocalCidrs().", e); + } + + return cidrList.toArray(new String[0]); + } + public static InetAddress getFirstNonLoopbackLocalInetAddress() { InetAddress[] addrs = getAllLocalInetAddresses(); if(addrs != null) { @@ -144,18 +164,24 @@ public class NetUtils { public static String getLocalIPString() { InetAddress addr = getLocalInetAddress(); if(addr != null) { - byte[] ipBytes = addr.getAddress(); - StringBuffer sb = new StringBuffer(); - sb.append(ipBytes[0] & 0xff).append("."); - sb.append(ipBytes[1] & 0xff).append("."); - sb.append(ipBytes[2] & 0xff).append("."); - sb.append(ipBytes[3] & 0xff); - - return sb.toString(); + return ipFromInetAddress(addr); } return new String("127.0.0.1"); } + + public static String ipFromInetAddress(InetAddress addr) { + assert(addr != null); + + byte[] ipBytes = addr.getAddress(); + StringBuffer sb = new StringBuffer(); + sb.append(ipBytes[0] & 0xff).append("."); + sb.append(ipBytes[1] & 0xff).append("."); + sb.append(ipBytes[2] & 0xff).append("."); + sb.append(ipBytes[3] & 0xff); + + return sb.toString(); + } public static boolean isLocalAddress(InetAddress addr) { InetAddress[] addrs = getAllLocalInetAddresses();