GutoVeronezi commented on a change in pull request #5030:
URL: https://github.com/apache/cloudstack/pull/5030#discussion_r637958086
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -6365,24 +6329,75 @@ public VirtualMachine
migrateVirtualMachineWithVolume(Long vmId, Host destinatio
}
}
}
+ return volToPoolObjectMap;
+ }
- // Check if all the volumes are in the correct state.
- for (VolumeVO volume : vmVolumes) {
- if (volume.getState() != Volume.State.Ready) {
- throw new CloudRuntimeException("Volume " + volume + " of the
VM is not in Ready state. Cannot " + "migrate the vm with its volumes.");
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription =
"migrating VM", async = true)
+ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host
destinationHost, Map<String, String> volumeToPool) throws
ResourceUnavailableException,
+ ConcurrentOperationException, ManagementServerException,
VirtualMachineMigrationException {
+ // Access check - only root administrator can migrate VM.
+ Account caller = CallContext.current().getCallingAccount();
+ if (!_accountMgr.isRootAdmin(caller.getId())) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Caller is not a root admin, permission denied
to migrate the VM");
}
+ throw new PermissionDeniedException("No permission to migrate VM,
Only Root Admin can migrate a VM!");
}
- // Check max guest vm limit for the destinationHost.
- HostVO destinationHostVO = _hostDao.findById(destinationHost.getId());
- if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
- throw new VirtualMachineMigrationException("Host name: " +
destinationHost.getName() + ", hostId: " + destinationHost.getId()
- + " already has max running vms (count includes system VMs).
Cannot" + " migrate to this host");
+ VMInstanceVO vm = _vmInstanceDao.findById(vmId);
+ if (vm == null) {
+ throw new InvalidParameterValueException("Unable to find the VM by
ID " + vmId);
}
- checkHostsDedication(vm, srcHostId, destinationHost.getId());
+ // OfflineVmwareMigration: this would be it ;) if multiple paths
exist: unify
+ if (vm.getState() != State.Running) {
+ // OfflineVmwareMigration: and not vmware
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("VM is not Running, unable to migrate the vm "
+ vm);
+ }
+ CloudRuntimeException ex = new
CloudRuntimeException(String.format("Unable to migrate the VM %s (ID: %s) as it
is not in Running state", vm.getInstanceName(), vm.getUuid()));
+ ex.addProxyObject(vm.getUuid(), "vmId");
+ throw ex;
+ }
+
+ if(serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(),
GPU.Keys.pciDevice.toString()) != null) {
+ throw new InvalidParameterValueException("Live Migration of GPU
enabled VM is not supported");
+ }
+
+ // OfflineVmwareMigration: this condition is to complicated. (already
a method somewhere)
+ if (!Arrays.asList(new HypervisorType[]{
+ HypervisorType.XenServer,
+ HypervisorType.VMware,
+ HypervisorType.KVM,
+ HypervisorType.Simulator}).contains(vm.getHypervisorType())) {
+ throw new
InvalidParameterValueException(String.format("Unsupported hypervisor: %s for VM
migration, we support XenServer/VMware/KVM only", vm.getHypervisorType()));
+ }
+
+ // Check that Vm does not have VM Snapshots
Review comment:
As the code is clear and we have a explanation on the exception message,
is this comment still needed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]