use of com.cloud.model.enumeration.AdvertMethod in project cosmic by MissionCriticalCloud.
the class VirtualNetworkApplianceManagerImpl method createRedundantRouterArgs.
protected StringBuilder createRedundantRouterArgs(final NicProfile nic, final DomainRouterVO router) {
final StringBuilder buf = new StringBuilder();
final long networkId = nic.getNetworkId();
_networkDao.findById(networkId);
final List<DomainRouterVO> routers;
final Long vpcId = router.getVpcId();
if (vpcId != null) {
final Vpc vpc = _vpcDao.findById(vpcId);
routers = _routerDao.listByVpcId(vpcId);
if (vpc.isRedundant()) {
buf.append(" redundant_router=1");
}
long advertInt = vpc.getAdvertInterval();
if (advertInt <= 0) {
advertInt = NumbersUtil.parseLong(_configDao.getValue(Config.RedundantRouterVrrpInterval.key()), 1);
}
buf.append(" advert_int=").append(advertInt);
String unicastSubnet = vpc.getUnicastSubnet();
if (unicastSubnet == null || unicastSubnet.isEmpty() || !NetUtils.isValidIp4Cidr(unicastSubnet)) {
unicastSubnet = _configDao.getValue(Config.RedundantRouterUnicastSubnet.key());
if (unicastSubnet == null || unicastSubnet.isEmpty() || !NetUtils.isValidIp4Cidr(unicastSubnet)) {
unicastSubnet = "100.100.0.0/24";
}
}
buf.append(" unicast_subnet=").append(unicastSubnet);
AdvertMethod advertMethod = vpc.getAdvertMethod();
if (advertMethod == null) {
try {
String advertMethodConfigValue = _configDao.getValue(Config.RedundantRouterAdvertMethod.key());
advertMethod = AdvertMethod.valueOf(advertMethodConfigValue);
} catch (final IllegalArgumentException ex) {
advertMethod = AdvertMethod.MULTICAST;
}
}
buf.append(" advert_method=").append(advertMethod);
buf.append(" router_id=").append(vpcId);
buf.append(" unicast_id=").append(router.getRouterUnicastId());
try {
final MessageDigest digest = MessageDigest.getInstance("SHA-512");
final byte[] rawDigest = vpc.getUuid().getBytes(Charset.defaultCharset());
digest.update(rawDigest);
final BigInteger password = new BigInteger(1, digest.digest());
buf.append(" router_password=").append(password);
} catch (final NoSuchAlgorithmException e) {
s_logger.error("Failed to pssword! Will use the plan B instead.");
buf.append(" router_password=").append(vpc.getUuid());
}
} else {
routers = _routerDao.listByNetworkAndRole(nic.getNetworkId(), Role.VIRTUAL_ROUTER);
}
String redundantState = RedundantState.BACKUP.toString();
router.setRedundantState(RedundantState.BACKUP);
if (routers.size() == 0) {
redundantState = RedundantState.MASTER.toString();
router.setRedundantState(RedundantState.MASTER);
} else {
final DomainRouterVO router0 = routers.get(0);
if (router.getId() == router0.getId()) {
redundantState = RedundantState.MASTER.toString();
router.setRedundantState(RedundantState.MASTER);
}
}
// @TODO Remove this
buf.append(" redundant_state=").append(redundantState);
return buf;
}
Aggregations