use of com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method orchestrateStorageMigration.
private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
if (destPool == null) {
throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
}
try {
stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
} catch (final NoTransitionException e) {
s_logger.debug("Unable to migrate vm: " + e.toString());
throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
}
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
boolean migrationResult = false;
try {
migrationResult = volumeMgr.storageMigration(profile, destPool);
if (migrationResult) {
if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
_networkMgr.reallocate(vmProfile, plan);
}
// when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
vm.setLastHostId(null);
vm.setPodIdToDeployIn(destPool.getPodId());
} else {
s_logger.debug("Storage migration failed");
}
} catch (final ConcurrentOperationException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientVirtualNetworkCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientAddressCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final InsufficientCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (final StorageUnavailableException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} finally {
try {
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
} catch (final NoTransitionException e) {
s_logger.debug("Failed to change vm state: " + e.toString());
throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
}
}
}
use of com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException in project cosmic by MissionCriticalCloud.
the class GuestNetworkGuru method assignGuestOrGatewayIp.
private String assignGuestOrGatewayIp(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final Zone zone) throws InsufficientVirtualNetworkCapacityException {
String guestIp;
// Default assign new ip
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
// Is our user VM supposed to be a remote gateway?
final long templateId = vm.getTemplateId();
final VMTemplateVO vmTemplateVO = _templateDao.findById(templateId);
final Boolean isRemoteGatewayTemplate = vmTemplateVO.getRemoteGatewayTemplate();
s_logger.debug("isRemoteGatewayTemplate has value " + isRemoteGatewayTemplate.toString());
final long networkOfferingId = network.getNetworkOfferingId();
NetworkOffering networkOffering = _networkOfferingDao.findById(networkOfferingId);
s_logger.debug("Check if the gateway ip is requested");
// Check if we can assign the gateway
if (nic.getIPv4Gateway() != null && nic.getIPv4Gateway().equals(nic.getRequestedIPv4())) {
s_logger.debug("VM requests gateway ip address for network " + network.getName() + " with offering " + networkOffering.getName() + " . Check service offering");
final boolean networkOfferingSupportsGatewayService = _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Gateway);
s_logger.debug("networkOfferingSupportsGatewayService has value " + networkOfferingSupportsGatewayService);
// The VM we start is based on a template that is a RemoteGateway AND the network itself does not have the Gateway service (so the vm can be the gateway)
if (isRemoteGatewayTemplate && !networkOfferingSupportsGatewayService) {
// Assign gateway
guestIp = nic.getIPv4Gateway();
s_logger.debug("VM requests gateway ip address for network " + network.getName() + " with offering " + networkOffering.getName() + ". " + "Allowed! IP address " + guestIp + " (aka gateway) will be assigned.");
} else {
s_logger.debug("Requested network ip is gateway but either template is not RemoteGateway enabled or network VPC router has Gateway service.");
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Gateway IP address. Template needs to be RemoteGateway enabled" + " or network VPC router already has Gateway service. Network: " + network, DataCenter.class, zone.getId());
}
}
s_logger.debug("Acquired guest ip is " + guestIp);
return guestIp;
}
use of com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException in project cosmic by MissionCriticalCloud.
the class GuestNetworkGuru method allocate.
@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Guest : "Look at my name! Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
final Zone zone = zoneRepository.findById(network.getDataCenterId()).orElse(null);
if (nic.getIPv4Address() == null && !GuestType.Sync.equals(network.getGuestType())) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setIPv4Gateway(network.getGateway());
String guestIp;
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, zone, vm, network, nic.getRequestedIPv4(), null);
} else {
final VirtualMachineType vmtype = vm.getVirtualMachine().getType();
switch(vmtype) {
case User:
guestIp = assignGuestOrGatewayIp(network, nic, vm, zone);
break;
case DomainRouter:
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter)) {
// Networks that support the Gateway service acquire the gateway ip on their nic
guestIp = network.getGateway();
} else {
// In other cases, acquire an ip address from the DHCP range (take lowest possible)
guestIp = _ipAddrMgr.acquireGuestIpAddressForRouter(network, nic.getRequestedIPv4());
}
break;
default:
// Backwards compatibility
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
break;
}
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, zone.getId());
}
nic.setIPv4Address(guestIp);
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
if (network.getDns1() != null && network.getDns1().equals("")) {
nic.setIPv4Dns1(null);
} else {
nic.setIPv4Dns1(network.getDns1());
}
if (network.getDns2() != null && network.getDns2().equals("")) {
nic.setIPv4Dns2(null);
} else {
nic.setIPv4Dns2(network.getDns2());
}
nic.setFormat(IpAddressFormat.Ip4);
}
}
nic.setReservationStrategy(ReservationStrategy.Start);
if (nic.getMacAddress() == null) {
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
if (nic.getMacAddress() == null) {
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
}
}
return nic;
}
Aggregations