fermosan commented on code in PR #6550:
URL: https://github.com/apache/cloudstack/pull/6550#discussion_r927021781


##########
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:
   Done



-- 
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]

Reply via email to