mirror of https://github.com/apache/cloudstack.git
Perform and alert management.network.cidr configuration on management server startup
This commit is contained in:
parent
d0320896f3
commit
b264866d2e
|
|
@ -102,6 +102,6 @@
|
|||
<dao name="DataCenterDao" class="com.cloud.dc.dao.DataCenterDaoImpl" singleton="false"/>
|
||||
<dao name="NetworkDao" class="com.cloud.network.dao.NetworkDaoImpl" singleton="false"/>
|
||||
<dao name="IpAddressDao" class="com.cloud.network.dao.IPAddressDaoImpl" singleton="false"/>
|
||||
<dao name="VlanDao" class="com.cloud.dc.dao.VlanDaoImpl" singleton="false"/>
|
||||
<dao name="VlanDao" class="com.cloud.dc.dao.VlanDaoImpl" singleton="false"/>
|
||||
</configuration-server>
|
||||
</components.xml>
|
||||
|
|
|
|||
|
|
@ -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<SecurityChecker> _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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,26 @@ public class NetUtils {
|
|||
return addrs;
|
||||
}
|
||||
|
||||
public static String[] getLocalCidrs() {
|
||||
List<String> cidrList = new ArrayList<String>();
|
||||
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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue