InsufficientServerCapacityException,
InsufficientCapacityException,
StorageUnavailableException,
ResourceUnavailableException {
ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
// Router is the network element, we don't know the hypervisor type yet.
// Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
List<HypervisorType> hypervisors = getHypervisors(dest, plan, supportedHypervisors);
int allocateRetry = 0;
int startRetry = 0;
DomainRouterVO router = null;
for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
HypervisorType hType = iter.next();
try {
long id = _routerDao.getNextInSequence(Long.class, "id");
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating the VR i="+ id + " in datacenter " + dest.getDataCenter() + "with the hypervisor type " + hType);
}
String templateName = null;
switch (hType) {
case XenServer:
templateName = RouterTemplateXen.valueIn(dest.getDataCenter().getId());
break;
case KVM:
templateName = RouterTemplateKvm.valueIn(dest.getDataCenter().getId());
break;
case VMware:
templateName = RouterTemplateVmware.valueIn(dest.getDataCenter().getId());
break;
case Hyperv:
templateName = RouterTemplateHyperV.valueIn(dest.getDataCenter().getId());
break;
case LXC:
templateName = RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
break;
default: break;
}
VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
if (template == null) {
s_logger.debug(hType + " won't support system vm, skip it");
continue;
}
boolean offerHA = routerOffering.getOfferHA();
/* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */
if (isRedundant) {
offerHA = false;
}
router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
RedundantState.UNKNOWN, offerHA, false, vpcId);
router.setDynamicallyScalable(template.isDynamicallyScalable());
router.setRole(Role.VIRTUAL_ROUTER);