mirror of https://github.com/apache/cloudstack.git
Cleanup imported VM from disk on failure due to volume allocation + prevent duplicate volume and primary storage increment on import
This commit is contained in:
parent
9c0c8da706
commit
88a12a801f
|
|
@ -120,7 +120,7 @@ public interface VolumeOrchestrationService {
|
|||
void destroyVolume(Volume volume);
|
||||
|
||||
DiskProfile allocateRawVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
|
||||
Account owner, Long deviceId);
|
||||
Account owner, Long deviceId, boolean incrementResourceCount);
|
||||
|
||||
VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ import javax.inject.Inject;
|
|||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.EntityExistsException;
|
||||
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
|
|
@ -307,7 +306,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO;
|
|||
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
||||
public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, VmWorkJobHandler, Listener, Configurable {
|
||||
|
||||
public static final String VM_WORK_JOB_HANDLER = VirtualMachineManagerImpl.class.getSimpleName();
|
||||
|
|
@ -539,7 +537,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
final Map<String, Map<Integer, String>> extraDhcpOptions, final Map<Long, DiskOffering> datadiskTemplateToDiskOfferingMap, Volume volume, Snapshot snapshot)
|
||||
throws InsufficientCapacityException {
|
||||
|
||||
logger.info("allocating virtual machine from template: {} with hostname: {} and {} networks", template, vmInstanceName, auxiliaryNetworks.size());
|
||||
logger.info("Allocating Instance from Template: {} with hostname: {} and {} networks", template, vmInstanceName, auxiliaryNetworks.size());
|
||||
VMInstanceVO persistedVm = null;
|
||||
try {
|
||||
final VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName);
|
||||
|
|
@ -562,7 +560,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
final Long rootDiskSizeFinal = rootDiskSize;
|
||||
|
||||
logger.debug("Allocating nics for {}", persistedVm);
|
||||
logger.debug("Allocating NICs for {}", persistedVm);
|
||||
|
||||
try {
|
||||
if (!vmProfile.getBootArgs().contains("ExternalLoadBalancerVm")) {
|
||||
|
|
@ -585,7 +583,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
Long deviceId = dataDiskDeviceIds.get(index++);
|
||||
String volumeName = deviceId == null ? "DATA-" + persistedVm.getId() : "DATA-" + persistedVm.getId() + "-" + String.valueOf(deviceId);
|
||||
volumeMgr.allocateRawVolume(Type.DATADISK, volumeName, dataDiskOfferingInfo.getDiskOffering(), dataDiskOfferingInfo.getSize(),
|
||||
dataDiskOfferingInfo.getMinIops(), dataDiskOfferingInfo.getMaxIops(), persistedVm, template, owner, deviceId);
|
||||
dataDiskOfferingInfo.getMinIops(), dataDiskOfferingInfo.getMaxIops(), persistedVm, template, owner, deviceId, true);
|
||||
}
|
||||
}
|
||||
if (datadiskTemplateToDiskOfferingMap != null && !datadiskTemplateToDiskOfferingMap.isEmpty()) {
|
||||
|
|
@ -595,7 +593,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
long diskOfferingSize = diskOffering.getDiskSize() / (1024 * 1024 * 1024);
|
||||
VMTemplateVO dataDiskTemplate = _templateDao.findById(dataDiskTemplateToDiskOfferingMap.getKey());
|
||||
volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + persistedVm.getId() + "-" + String.valueOf( diskNumber), diskOffering, diskOfferingSize, null, null,
|
||||
persistedVm, dataDiskTemplate, owner, diskNumber);
|
||||
persistedVm, dataDiskTemplate, owner, diskNumber, true);
|
||||
diskNumber++;
|
||||
}
|
||||
}
|
||||
|
|
@ -625,7 +623,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
String rootVolumeName = String.format("ROOT-%s", vm.getId());
|
||||
if (template.getFormat() == ImageFormat.ISO) {
|
||||
volumeMgr.allocateRawVolume(Type.ROOT, rootVolumeName, rootDiskOfferingInfo.getDiskOffering(), rootDiskOfferingInfo.getSize(),
|
||||
rootDiskOfferingInfo.getMinIops(), rootDiskOfferingInfo.getMaxIops(), vm, template, owner, null);
|
||||
rootDiskOfferingInfo.getMinIops(), rootDiskOfferingInfo.getMaxIops(), vm, template, owner, null, true);
|
||||
} else if (Arrays.asList(ImageFormat.BAREMETAL, ImageFormat.EXTERNAL).contains(template.getFormat())) {
|
||||
logger.debug("{} has format [{}]. Skipping ROOT volume [{}] allocation.", template, template.getFormat(), rootVolumeName);
|
||||
} else {
|
||||
|
|
@ -1023,7 +1021,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
final State state = instance.getState();
|
||||
if (state == State.Running) {
|
||||
logger.debug("VM is already started: " + vm);
|
||||
logger.debug("Instance is already started: " + vm);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -1384,14 +1382,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
int retry = StartRetry.value();
|
||||
while (retry-- != 0) {
|
||||
logger.debug("VM start attempt #{}", (StartRetry.value() - retry));
|
||||
logger.debug("Instance start attempt #{}", (StartRetry.value() - retry));
|
||||
|
||||
if (reuseVolume) {
|
||||
final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
|
||||
for (final VolumeVO vol : vols) {
|
||||
final Long volTemplateId = vol.getTemplateId();
|
||||
if (volTemplateId != null && volTemplateId != template.getId()) {
|
||||
logger.debug("{} of {} is READY, but template ids don't match, let the planner reassign a new pool", vol, vm);
|
||||
logger.debug("{} of {} is READY, but Template IDs don't match, let the planner reassign a new pool", vol, vm);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1651,8 +1649,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
}
|
||||
} catch (ExecutionException | NoTransitionException | ResourceAllocationException e) {
|
||||
logger.error("Failed to start instance {}", vm, e);
|
||||
throw new AgentUnavailableException("Unable to start instance due to " + e.getMessage(), destHostId, e);
|
||||
logger.error("Failed to start Instance {}", vm, e);
|
||||
throw new AgentUnavailableException("Unable to start Instance due to " + e.getMessage(), destHostId, e);
|
||||
} catch (final StorageAccessException e) {
|
||||
logger.warn("Unable to access storage on host", e);
|
||||
} finally {
|
||||
|
|
@ -2176,7 +2174,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
protected boolean sendStop(final VirtualMachineGuru guru, final VirtualMachineProfile profile, final boolean force, final boolean checkBeforeCleanup) {
|
||||
final VirtualMachine vm = profile.getVirtualMachine();
|
||||
Map<String, Boolean> vlanToPersistenceMap = getVlanToPersistenceMapForVM(vm.getId());
|
||||
|
||||
StopCommand stpCmd = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), checkBeforeCleanup);
|
||||
updateStopCommandForExternalHypervisorType(vm.getHypervisorType(), profile, stpCmd);
|
||||
if (MapUtils.isNotEmpty(vlanToPersistenceMap)) {
|
||||
|
|
@ -2528,7 +2525,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
stopped = answer.getResult();
|
||||
if (!stopped) {
|
||||
throw new CloudRuntimeException("Unable to stop the virtual machine due to " + answer.getDetails());
|
||||
throw new CloudRuntimeException("Unable to stop the Instance due to " + answer.getDetails());
|
||||
}
|
||||
vmGuru.finalizeStop(profile, answer);
|
||||
final GPUDeviceTO gpuDevice = stop.getGpuDevice();
|
||||
|
|
@ -2692,8 +2689,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
private void deleteVMSnapshots(VMInstanceVO vm, boolean expunge) {
|
||||
if (! vm.getHypervisorType().equals(HypervisorType.VMware)) {
|
||||
if (!_vmSnapshotMgr.deleteAllVMSnapshots(vm.getId(), null)) {
|
||||
logger.debug("Unable to delete all snapshots for {}", vm);
|
||||
throw new CloudRuntimeException("Unable to delete vm snapshots for " + vm);
|
||||
logger.debug("Unable to delete all Snapshots for {}", vm);
|
||||
throw new CloudRuntimeException("Unable to delete Instance Snapshots for " + vm);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -2722,7 +2719,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
if (command != null) {
|
||||
RestoreVMSnapshotAnswer restoreVMSnapshotAnswer = (RestoreVMSnapshotAnswer) _agentMgr.send(hostId, command);
|
||||
if (restoreVMSnapshotAnswer == null || !restoreVMSnapshotAnswer.getResult()) {
|
||||
logger.warn("Unable to restore the vm snapshot from image file after live migration of vm with vmsnapshots: {}", restoreVMSnapshotAnswer == null ? "null answer" : restoreVMSnapshotAnswer.getDetails());
|
||||
logger.warn("Unable to restore the Instance Snapshot from image file after live migration of Instance with vmsnapshots: {}", restoreVMSnapshotAnswer == null ? "null answer" : restoreVMSnapshotAnswer.getDetails());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2909,7 +2906,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
clusterId = cluster.getId();
|
||||
}
|
||||
if (dataCenterId == null) {
|
||||
String msg = "Unable to migrate vm: failed to create deployment destination with given volume to pool map";
|
||||
String msg = "Unable to migrate Instance: failed to create deployment destination with given volume to pool map";
|
||||
logger.debug(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
|
@ -2920,7 +2917,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
try {
|
||||
stateTransitTo(vm, Event.StorageMigrationRequested, null);
|
||||
} catch (final NoTransitionException e) {
|
||||
String msg = String.format("Unable to migrate vm: %s", vm.getUuid());
|
||||
String msg = String.format("Unable to migrate Instance: %s", vm.getUuid());
|
||||
logger.warn(msg, e);
|
||||
throw new CloudRuntimeException(msg, e);
|
||||
}
|
||||
|
|
@ -3046,8 +3043,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
private void orchestrateMigrate(final String vmUuid, final long srcHostId, final DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
||||
if (vm == null) {
|
||||
logger.debug("Unable to find the vm {}", vmUuid);
|
||||
throw new CloudRuntimeException("Unable to find a virtual machine with id " + vmUuid);
|
||||
logger.debug("Unable to find the Instance {}", vmUuid);
|
||||
throw new CloudRuntimeException("Unable to find a Instance with ID: " + vmUuid);
|
||||
}
|
||||
migrate(vm, srcHostId, dest);
|
||||
}
|
||||
|
|
@ -4018,8 +4015,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
ResourceUnavailableException {
|
||||
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
||||
if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
|
||||
logger.error("Unable to reboot VM {} due to: {} has active VM snapshot tasks", vm, vm.getInstanceName());
|
||||
throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
|
||||
logger.error("Unable to reboot Instance: {} due to: {} has active Instance Snapshot tasks", vm, vm.getInstanceName());
|
||||
throw new CloudRuntimeException("Unable to reboot Instance: " + vm + " due to: " + vm.getInstanceName() + " has active Instance Snapshots tasks");
|
||||
}
|
||||
final DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
|
||||
final Host host = _hostDao.findById(vm.getHostId());
|
||||
|
|
@ -4534,7 +4531,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
final CallContext cctx = CallContext.current();
|
||||
|
||||
checkIfNetworkExistsForUserVM(vm, network);
|
||||
logger.debug("Adding vm {} to network {}; requested nic profile {}", vm, network, requested);
|
||||
logger.debug("Adding Instance {} to Network {}; requested NIC profile {}", vm, network, requested);
|
||||
final VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());
|
||||
|
||||
|
|
@ -4553,7 +4550,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
final NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
|
||||
//4) plug the nic to the vm
|
||||
logger.debug("Plugging nic for vm {} in network {}", vm, network);
|
||||
logger.debug("Plugging NIC for Instance {} in Network {}", vm, network);
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
|
|
@ -4569,12 +4566,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
return nic;
|
||||
} else {
|
||||
logger.warn("Failed to plug nic to the vm {} in network {}", vm, network);
|
||||
logger.warn("Failed to plug NIC to the Instance {} in Network {}", vm, network);
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
if (!result) {
|
||||
logger.debug("Removing nic {} from vm {} as nic plug failed on the backend.", nic, vmProfile.getVirtualMachine());
|
||||
logger.debug("Removing NIC {} from Instance {} as NIC plug failed on the backend.", nic, vmProfile.getVirtualMachine());
|
||||
_networkMgr.removeNic(vmProfile, _nicsDao.findById(nic.getId()));
|
||||
}
|
||||
}
|
||||
|
|
@ -4645,25 +4642,25 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
if (vm.getState() == State.Running) {
|
||||
final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
logger.debug("Un-plugging nic {} for vm {} from network {}.", nic, vm, network);
|
||||
logger.debug("Un-plugging NIC {} for Instance {} from Network {}.", nic, vm, network);
|
||||
final boolean result = unplugNic(network, nicTO, vmTO, context, dest);
|
||||
if (result) {
|
||||
_userVmMgr.setupVmForPvlan(false, vm.getHostId(), nicProfile);
|
||||
logger.debug("Nic is unplugged successfully for vm {} in network {}.", vm, network);
|
||||
logger.debug("NIC is unplugged successfully for Instance {} in Network {}.", vm, network);
|
||||
final long isDefault = nic.isDefaultNic() ? 1 : 0;
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
|
||||
} else {
|
||||
logger.warn("Failed to unplug nic for the vm {} from network {}.", vm, network);
|
||||
logger.warn("Failed to unplug NIC for the Instance {} from Network {}.", vm, network);
|
||||
return false;
|
||||
}
|
||||
} else if (vm.getState() != State.Stopped) {
|
||||
logger.warn("Unable to remove vm {} from network {}", vm, network);
|
||||
throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId());
|
||||
logger.warn("Unable to remove Instance {} from Network {}", vm, network);
|
||||
throw new ResourceUnavailableException("Unable to remove Instance " + vm + " from Network, is not in the right state", DataCenter.class, vm.getDataCenterId());
|
||||
}
|
||||
|
||||
_networkMgr.releaseNic(vmProfile, nic);
|
||||
logger.debug("Successfully released nic {} for vm {}", nic, vm);
|
||||
logger.debug("Successfully released NIC {} for Instance {}", nic, vm);
|
||||
|
||||
_networkMgr.removeNic(vmProfile, nic);
|
||||
_nicsDao.remove(nic.getId());
|
||||
|
|
@ -4698,13 +4695,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
|
||||
if (nic == null) {
|
||||
logger.warn("Could not get a nic with {}", network);
|
||||
logger.warn("Could not get a NIC with {}", network);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nic.isDefaultNic() && vm.getType() == VirtualMachine.Type.User) {
|
||||
logger.warn("Failed to remove nic from {} in {}, nic is default.", vm, network);
|
||||
throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic is default.");
|
||||
logger.warn("Failed to remove NIC from {} in {}, NIC is default.", vm, network);
|
||||
throw new CloudRuntimeException("Failed to remove NIC from " + vm + " in " + network + ", NIC is default.");
|
||||
}
|
||||
|
||||
final Nic lock = _nicsDao.acquireInLockTable(nic.getId());
|
||||
|
|
@ -5371,22 +5368,22 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
|
||||
case Destroyed:
|
||||
case Expunging:
|
||||
logger.info("Receive power on report when VM is in destroyed or expunging state. vm: {}, state: {}.", vm, vm.getState());
|
||||
logger.info("Receive power on report when Instance is in destroyed or expunging state. Instance: {}, state: {}.", vm, vm.getState());
|
||||
break;
|
||||
|
||||
case Migrating:
|
||||
logger.info("VM {} is at {} and we received a power-on report while there is no pending jobs on it.", vm, vm.getState());
|
||||
logger.info("Instance {} is at {} and we received a power-on report while there is no pending jobs on it.", vm, vm.getState());
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
|
||||
} catch (final NoTransitionException e) {
|
||||
logger.warn("Unexpected VM state transition exception, race-condition?", e);
|
||||
logger.warn("Unexpected Instance state transition exception, race-condition?", e);
|
||||
}
|
||||
logger.info("VM {} is sync-ed to at Running state according to power-on report from hypervisor.", vm);
|
||||
logger.info("Instance {} is sync-ed to at Running state according to power-on report from hypervisor.", vm);
|
||||
break;
|
||||
|
||||
case Error:
|
||||
default:
|
||||
logger.info("Receive power on report when VM is in error or unexpected state. vm: {}, state: {}.", vm, vm.getState());
|
||||
logger.info("Receive power on report when Instance is in error or unexpected state. Instance: {}, state: {}.", vm, vm.getState());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -6144,7 +6141,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
|
||||
private UserVm orchestrateRestoreVirtualMachine(final long vmId, final Long newTemplateId, final Long rootDiskOfferingId, final boolean expunge, final Map<String, String> details) throws ResourceUnavailableException, InsufficientCapacityException {
|
||||
logger.debug("Restoring vm {} with templateId: {}, diskOfferingId: {}, details: {}", vmId, newTemplateId, rootDiskOfferingId, details);
|
||||
logger.debug("Restoring Instance {} with templateId: {}, diskOfferingId: {}, details: {}", vmId, newTemplateId, rootDiskOfferingId, details);
|
||||
final CallContext context = CallContext.current();
|
||||
final Account account = context.getCallingAccount();
|
||||
return _userVmService.restoreVirtualMachine(account, vmId, newTemplateId, rootDiskOfferingId, expunge, details);
|
||||
|
|
|
|||
|
|
@ -864,7 +864,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", create = true)
|
||||
@Override
|
||||
public DiskProfile allocateRawVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template, Account owner,
|
||||
Long deviceId) {
|
||||
Long deviceId, boolean incrementResourceCount) {
|
||||
if (size == null) {
|
||||
size = offering.getDiskSize();
|
||||
} else {
|
||||
|
|
@ -903,7 +903,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
|||
saveVolumeDetails(offering.getId(), vol.getId());
|
||||
|
||||
// Save usage event and update resource count for user vm volumes
|
||||
if (vm.getType() == VirtualMachine.Type.User) {
|
||||
if (vm.getType() == VirtualMachine.Type.User && incrementResourceCount) {
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null, size,
|
||||
Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
|
||||
_resourceLimitMgr.incrementVolumeResourceCount(vm.getAccountId(), vol.isDisplayVolume(), vol.getSize(), offering);
|
||||
|
|
|
|||
|
|
@ -1741,7 +1741,6 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
Pair<UnmanagedInstanceTO, Boolean> sourceInstanceDetails = getSourceVmwareUnmanagedInstance(vcenter, datacenterName, username, password, clusterName, sourceHostName, sourceVMName, serviceOffering);
|
||||
sourceVMwareInstance = sourceInstanceDetails.first();
|
||||
isClonedInstance = sourceInstanceDetails.second();
|
||||
|
||||
boolean isWindowsVm = sourceVMwareInstance.getOperatingSystem().toLowerCase().contains("windows");
|
||||
if (isWindowsVm) {
|
||||
checkConversionSupportOnHost(convertHost, sourceVMName, true);
|
||||
|
|
@ -2658,28 +2657,28 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
}
|
||||
VirtualMachine.PowerState powerState = VirtualMachine.PowerState.PowerOff;
|
||||
|
||||
try {
|
||||
userVm = userVmManager.importVM(zone, null, template, null, displayName, owner,
|
||||
null, caller, true, null, owner.getAccountId(), userId,
|
||||
serviceOffering, null, hostName,
|
||||
Hypervisor.HypervisorType.KVM, allDetails, powerState, null);
|
||||
} catch (InsufficientCapacityException ice) {
|
||||
logger.error(String.format("Failed to import vm name: %s", instanceName), ice);
|
||||
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ice.getMessage());
|
||||
}
|
||||
if (userVm == null) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import vm name: %s", instanceName));
|
||||
}
|
||||
String rootVolumeName = String.format("ROOT-%s", userVm.getId());
|
||||
DiskProfile diskProfile = volumeManager.allocateRawVolume(Volume.Type.ROOT, rootVolumeName, diskOffering, null, null, null, userVm, template, owner, null);
|
||||
try {
|
||||
userVm = userVmManager.importVM(zone, null, template, null, displayName, owner,
|
||||
null, caller, true, null, owner.getAccountId(), userId,
|
||||
serviceOffering, null, hostName,
|
||||
Hypervisor.HypervisorType.KVM, allDetails, powerState, null);
|
||||
} catch (InsufficientCapacityException ice) {
|
||||
logger.error(String.format("Failed to import vm name: %s", instanceName), ice);
|
||||
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ice.getMessage());
|
||||
}
|
||||
if (userVm == null) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import vm name: %s", instanceName));
|
||||
}
|
||||
String rootVolumeName = String.format("ROOT-%s", userVm.getId());
|
||||
DiskProfile diskProfile = volumeManager.allocateRawVolume(Volume.Type.ROOT, rootVolumeName, diskOffering, null, null, null, userVm, template, owner, null, false);
|
||||
|
||||
DiskProfile[] dataDiskProfiles = new DiskProfile[dataDisks.size()];
|
||||
int diskSeq = 0;
|
||||
for (UnmanagedInstanceTO.Disk disk : dataDisks) {
|
||||
DiskOffering offering = diskOfferingDao.findById(dataDiskOfferingMap.get(disk.getDiskId()));
|
||||
DiskProfile dataDiskProfile = volumeManager.allocateRawVolume(Volume.Type.DATADISK, String.format("DATA-%d-%s", userVm.getId(), disk.getDiskId()), offering, null, null, null, userVm, template, owner, null);
|
||||
dataDiskProfiles[diskSeq++] = dataDiskProfile;
|
||||
}
|
||||
DiskProfile[] dataDiskProfiles = new DiskProfile[dataDisks.size()];
|
||||
int diskSeq = 0;
|
||||
for (UnmanagedInstanceTO.Disk disk : dataDisks) {
|
||||
DiskOffering offering = diskOfferingDao.findById(dataDiskOfferingMap.get(disk.getDiskId()));
|
||||
DiskProfile dataDiskProfile = volumeManager.allocateRawVolume(Volume.Type.DATADISK, String.format("DATA-%d-%s", userVm.getId(), disk.getDiskId()), offering, null, null, null, userVm, template, owner, null, false);
|
||||
dataDiskProfiles[diskSeq++] = dataDiskProfile;
|
||||
}
|
||||
|
||||
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(userVm, template, serviceOffering, owner, null);
|
||||
ServiceOfferingVO dummyOffering = serviceOfferingDao.findById(userVm.getId(), serviceOffering.getId());
|
||||
|
|
@ -2835,7 +2834,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
reservations.add(volumeReservation);
|
||||
|
||||
String rootVolumeName = String.format("ROOT-%s", userVm.getId());
|
||||
DiskProfile diskProfile = volumeManager.allocateRawVolume(Volume.Type.ROOT, rootVolumeName, diskOffering, null, null, null, userVm, template, owner, null);
|
||||
DiskProfile diskProfile = volumeManager.allocateRawVolume(Volume.Type.ROOT, rootVolumeName, diskOffering, null, null, null, userVm, template, owner, null, false);
|
||||
|
||||
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(userVm, template, serviceOffering, owner, null);
|
||||
ServiceOfferingVO dummyOffering = serviceOfferingDao.findById(userVm.getId(), serviceOffering.getId());
|
||||
|
|
@ -2878,14 +2877,10 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
throw new CloudRuntimeException("Disk not found or is invalid");
|
||||
}
|
||||
diskProfile.setSize(checkVolumeAnswer.getSize());
|
||||
try {
|
||||
CheckedReservation primaryStorageReservation = new CheckedReservation(owner, Resource.ResourceType.primary_storage, resourceLimitStorageTags,
|
||||
CollectionUtils.isNotEmpty(resourceLimitStorageTags) ? diskProfile.getSize() : 0L, reservationDao, resourceLimitService);
|
||||
reservations.add(primaryStorageReservation);
|
||||
} catch (ResourceAllocationException e) {
|
||||
cleanupFailedImportVM(userVm);
|
||||
throw e;
|
||||
}
|
||||
|
||||
CheckedReservation primaryStorageReservation = new CheckedReservation(owner, Resource.ResourceType.primary_storage, resourceLimitStorageTags,
|
||||
CollectionUtils.isNotEmpty(resourceLimitStorageTags) ? diskProfile.getSize() : 0L, reservationDao, resourceLimitService);
|
||||
reservations.add(primaryStorageReservation);
|
||||
|
||||
List<Pair<DiskProfile, StoragePool>> diskProfileStoragePoolList = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -600,7 +600,7 @@ public class UnmanagedVMsManagerImplTest {
|
|||
DeployDestination mockDest = Mockito.mock(DeployDestination.class);
|
||||
when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest);
|
||||
DiskProfile diskProfile = Mockito.mock(DiskProfile.class);
|
||||
when(volumeManager.allocateRawVolume(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
when(volumeManager.allocateRawVolume(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(diskProfile);
|
||||
Map<Volume, StoragePool> storage = new HashMap<>();
|
||||
VolumeVO volume = Mockito.mock(VolumeVO.class);
|
||||
|
|
@ -836,7 +836,7 @@ public class UnmanagedVMsManagerImplTest {
|
|||
DeployDestination mockDest = Mockito.mock(DeployDestination.class);
|
||||
when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest);
|
||||
DiskProfile diskProfile = Mockito.mock(DiskProfile.class);
|
||||
when(volumeManager.allocateRawVolume(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
when(volumeManager.allocateRawVolume(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(diskProfile);
|
||||
Map<Volume, StoragePool> storage = new HashMap<>();
|
||||
VolumeVO volume = Mockito.mock(VolumeVO.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue