You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "abh1sar (via GitHub)" <gi...@apache.org> on 2025/09/04 04:01:35 UTC

Re: [PR] Create Instance from backup on another Zone (DRaaS use case) [cloudstack]

abh1sar commented on code in PR #11560:
URL: https://github.com/apache/cloudstack/pull/11560#discussion_r2320762899


##########
plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java:
##########
@@ -115,27 +130,38 @@ public class NASBackupProvider extends AdapterBase implements BackupProvider, Co
     @Inject
     private DiskOfferingDao diskOfferingDao;
 
+    protected Long getClusterIdFromRootVolume(VirtualMachine vm) {
+        VolumeVO rootVolume = _volsDao.getInstanceRootVolume(vm.getId());
+        StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolume.getPoolId());
+        return rootDiskPool.getClusterId();
+    }
+
     protected Host getLastVMHypervisorHost(VirtualMachine vm) {
         Long hostId = vm.getLastHostId();
-        if (hostId == null) {
-            LOG.debug("Cannot find last host for vm. This should never happen, please check your database.");
-            return null;
-        }
-        Host host = hostDao.findById(hostId);
+        Long clusterId = null;
 
-        if (host.getStatus() == Status.Up) {
-            return host;
+        if (hostId != null) {
+            Host host = hostDao.findById(hostId);
+            if (host.getStatus() == Status.Up) {
+                return host;
+            }
+            clusterId = host.getClusterId();
         } else {
+            clusterId = getClusterIdFromRootVolume(vm);

Review Comment:
   fyi - hostId won't be set for create Instance from Backup. But we can get the clusterId from the root volume which is already created.



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