fermosan commented on code in PR #6550:
URL: https://github.com/apache/cloudstack/pull/6550#discussion_r924834714
##########
server/src/main/java/com/cloud/hypervisor/KVMGuru.java:
##########
@@ -297,4 +309,49 @@ public Map<String, String> getClusterSettings(long vmId) {
return null;
}
-}
+ @Override
+ public VirtualMachine importVirtualMachineFromBackup(long zoneId, long
domainId, long accountId, long userId, String vmInternalName, Backup backup)
throws Exception {
+ s_logger.debug(String.format("Trying to import VM [vmInternalName: %s]
from Backup [%s].", vmInternalName,
+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(backup, "id", "uuid",
"vmId", "externalId", "backupType")));
+
+ VMInstanceVO vm =
_instanceDao.findVMByInstanceNameIncludingRemoved(vmInternalName);
+ if (vm.getRemoved() != null) {
+ vm.setState(VirtualMachine.State.Stopped);
+ vm.setPowerState(VirtualMachine.PowerState.PowerOff);
+ _instanceDao.update(vm.getId(), vm);
+ _instanceDao.unremove(vm.getId());
+ }
+ for (final VolumeVO volume :
_volumeDao.findIncludingRemovedByInstanceAndType(vm.getId(), null)) {
+ volume.setState(Volume.State.Ready);
+ volume.setAttached(new Date());
+ _volumeDao.update(volume.getId(), volume);
+ _volumeDao.unremove(volume.getId());
+ }
+
+ return vm;
+ }
+
+
+
+ @Override public boolean attachRestoredVolumeToVirtualMachine(long zoneId,
String location, Backup.VolumeInfo volumeInfo, VirtualMachine vm, long poolId,
Backup backup)
+ throws Exception {
+
+ VMInstanceVO targetVM =
_instanceDao.findVMByInstanceNameIncludingRemoved(vm.getName());
+ List<VolumeVO> devices =
_volumeDao.findIncludingRemovedByInstanceAndType(targetVM.getId(), null);
+ VolumeVO restoredVolume = _volumeDao.findByUuid(location);
+ Integer deviceId = devices.size();
+
+
+ if (restoredVolume != null) {
+ restoredVolume.setState(Volume.State.Ready);
+ _volumeDao.update(restoredVolume.getId(), restoredVolume);
+ try {
+ _volumeDao.attachVolume(restoredVolume.getId(), vm.getId(),
deviceId);
Review Comment:
@slavkap you got me thinking about this and there is a scenario that will
not play well. Supposedly we have VM with originally 5 attached disks that at
some point the user removes disk number 3. Then tries to restore a volume and
attach it to that vm. This scenario will not work. However, testing this there
is no error. The new volume is just overwriting the entry for the current
volume. The VM is starting normally but the disk at that original slot is
missing. I will do some more tests in order to come up with a solution.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]