use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class ExternalGuestNetworkGuru method reserve.
@Override
public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
DataCenter dc = _dcDao.findById(config.getDataCenterId());
if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId())) {
nic.setBroadcastUri(config.getBroadcastUri());
nic.setIsolationUri(config.getBroadcastUri());
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
nic.setIPv4Netmask(NetUtils.cidr2Netmask(config.getCidr()));
long cidrAddress = NetUtils.ip2Long(config.getCidr().split("/")[0]);
int cidrSize = getGloballyConfiguredCidrSize();
nic.setIPv4Gateway(config.getGateway());
if (nic.getIPv4Address() == null) {
String guestIp = _ipAddrMgr.acquireGuestIpAddress(config, null);
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire guest IP address for network " + config, DataCenter.class, dc.getId());
}
nic.setIPv4Address(guestIp);
} else {
long ipMask = NetUtils.ip2Long(nic.getIPv4Address()) & ~(0xffffffffffffffffl << (32 - cidrSize));
nic.setIPv4Address(NetUtils.long2Ip(cidrAddress | ipMask));
}
} else {
super.reserve(nic, config, vm, dest, context);
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method reserve.
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
super.reserve(nic, network, vm, dest, context);
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId());
}
OpenDaylightControllerVO controller = devices.get(0);
AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress());
AddHypervisorAnswer addAnswer = (AddHypervisorAnswer) agentManager.easySend(controller.getHostId(), addCmd);
if (addAnswer == null || !addAnswer.getResult()) {
s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller");
throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId());
}
ConfigurePortCommand cmd = new ConfigurePortCommand(UUID.fromString(nic.getUuid()), UUID.fromString(BroadcastDomainType.getValue(network.getBroadcastUri())), context.getAccount().getAccountName(), nic.getMacAddress());
ConfigurePortAnswer answer = (ConfigurePortAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ConfigureNetworkCommand failed");
throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId());
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class ContrailGuru method reserve.
/**
* Allocate the ip address (and mac) for the specified VM device.
*/
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
s_logger.debug("reserve NicProfile on network id: " + network.getId() + " " + network.getName());
s_logger.debug("deviceId: " + nic.getDeviceId());
NicVO nicVO = _nicDao.findById(nic.getId());
assert nicVO != null;
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
/* Network must have been implemented */
assert vnModel != null;
VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
if (vmModel == null) {
VMInstanceVO vmVo = (VMInstanceVO) vm.getVirtualMachine();
vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
vmModel.setProperties(_manager.getModelController(), vmVo);
}
VMInterfaceModel vmiModel = vmModel.getVMInterface(nicVO.getUuid());
if (vmiModel == null) {
vmiModel = new VMInterfaceModel(nicVO.getUuid());
vmiModel.addToVirtualMachine(vmModel);
vmiModel.addToVirtualNetwork(vnModel);
}
try {
vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nicVO);
vmiModel.setActive();
} catch (IOException ex) {
s_logger.error("virtual-machine-interface set", ex);
return;
}
InstanceIpModel ipModel = vmiModel.getInstanceIp();
if (ipModel == null) {
ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
ipModel.addToVMInterface(vmiModel);
} else {
s_logger.debug("Reuse existing instance-ip object on " + ipModel.getName());
}
if (nic.getIPv4Address() != null) {
s_logger.debug("Nic using existing IP address " + nic.getIPv4Address());
ipModel.setAddress(nic.getIPv4Address());
}
try {
vmModel.update(_manager.getModelController());
} catch (Exception ex) {
s_logger.warn("virtual-machine update", ex);
return;
}
_manager.getDatabase().getVirtualMachines().add(vmModel);
VirtualMachineInterface vmi = vmiModel.getVMInterface();
// allocate mac address
if (nic.getMacAddress() == null) {
MacAddressesType macs = vmi.getMacAddresses();
if (macs == null) {
s_logger.debug("no mac address is allocated for Nic " + nicVO.getUuid());
} else {
s_logger.info("VMI " + _manager.getVifNameByVmUuid(vm.getUuid(), nicVO.getDeviceId()) + " got mac address: " + macs.getMacAddress().get(0));
nic.setMacAddress(macs.getMacAddress().get(0));
}
}
if (nic.getIPv4Address() == null) {
s_logger.debug("Allocated IP address " + ipModel.getAddress());
nic.setIPv4Address(ipModel.getAddress());
if (network.getCidr() != null) {
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
}
nic.setIPv4Gateway(network.getGateway());
nic.setFormat(AddressFormat.Ip4);
}
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class NuageVspEntityBuilder method buildVspNetwork.
public VspNetwork buildVspNetwork(long domainId, Network network) {
VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder().id(network.getId()).uuid(network.getUuid()).name(network.getName()).cidr(network.getCidr()).gateway(network.getGateway());
DomainVO domain = _domainDao.findById(domainId);
VspDomain vspDomain = buildVspDomain(domain);
vspNetworkBuilder.domain(vspDomain);
AccountVO account = _accountDao.findById(network.getAccountId());
if (account != null) {
vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
}
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy()).publicAccess(networkOffering.getSupportsPublicAccess());
if (network.getVpcId() != null) {
VpcVO vpc = _vpcDao.findById(network.getVpcId());
vspNetworkBuilder.vpcUuid(vpc.getUuid()).vpcName(vpc.getName()).networkType(VspNetwork.NetworkType.Vpc);
} else {
if (networkOffering.getGuestType() == Network.GuestType.Shared) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkIdIncludingRemoved(network.getId());
List<VspAddressRange> vspAddressRanges = Lists.transform(vlans, new Function<VlanVO, VspAddressRange>() {
@Nullable
@Override
public VspAddressRange apply(VlanVO vlanVO) {
return new VspAddressRange.Builder().gateway(vlanVO.getVlanGateway()).netmask(vlanVO.getVlanNetmask()).build();
}
});
vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared).addressRanges(vspAddressRanges);
} else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat) || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
} else {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
}
}
boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
if (usesVirtualRouter(networkOffering.getId())) {
try {
List<Pair<String, String>> ipAddressRanges = networkOffering.getGuestType() == Network.GuestType.Shared ? getSharedIpAddressRanges(network.getId()) : getIpAddressRanges(network);
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
} catch (InsufficientVirtualNetworkCapacityException ex) {
s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
}
}
return vspNetworkBuilder.build();
}
use of com.cloud.exception.InsufficientVirtualNetworkCapacityException in project cloudstack by apache.
the class NuageVspEntityBuilder method getVirtualRouterIP.
private String getVirtualRouterIP(Network network, List<Pair<String, String>> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException {
if (network.getBroadcastUri() != null) {
return network.getBroadcastUri().getPath().substring(1);
}
Pair<String, String> lowestIpAddressRange = null;
long ipCount = 0;
if (ipAddressRanges.size() == 1) {
lowestIpAddressRange = Iterables.getOnlyElement(ipAddressRanges);
ipCount = NetUtils.ip2Long(lowestIpAddressRange.getRight()) - NetUtils.ip2Long(lowestIpAddressRange.getLeft()) + 1;
} else {
for (Pair<String, String> ipAddressRange : ipAddressRanges) {
if (lowestIpAddressRange == null || NetUtils.ip2Long(ipAddressRange.getLeft()) < NetUtils.ip2Long(lowestIpAddressRange.getLeft())) {
lowestIpAddressRange = ipAddressRange;
}
ipCount += NetUtils.ip2Long(ipAddressRange.getRight()) - NetUtils.ip2Long(ipAddressRange.getLeft()) + 1;
}
}
if (ipCount == 0) {
throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " But no ip address ranges are specified", Network.class, network.getId());
} else if (ipCount < 3) {
throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 3 hosts", Network.class, network.getId());
}
String virtualRouterIp = lowestIpAddressRange.getLeft();
long lowestIp = NetUtils.ip2Long(lowestIpAddressRange.getLeft());
lowestIp = lowestIp + 1;
lowestIpAddressRange.setLeft(NetUtils.long2Ip(lowestIp));
return virtualRouterIp;
}
Aggregations