You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/07/19 07:54:22 UTC

[GitHub] [cloudstack] slavkap commented on a diff in pull request #6550: Emc networker b&r

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


##########
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:
   Hi, @fermosan, I'm not sure, but I think you will have a problem if you have a VM with more volumes and restore them at some point. They will have the same `deviceId`. The issue will appear at the start of the VM when the `LibvirtComputingResource::createVbd` is invoked.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org