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 2018/06/18 12:24:09 UTC

[GitHub] DaanHoogland closed pull request #2709: only ask for the root volume, removing extensive query

DaanHoogland closed pull request #2709: only ask for the root volume, removing extensive query
URL: https://github.com/apache/cloudstack/pull/2709
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
index a304ea43fa2..a4debf945c9 100644
--- a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
+++ b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
@@ -30,6 +30,7 @@
 import org.apache.cloudstack.storage.configdrive.ConfigDrive;
 import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -56,7 +57,6 @@
 import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.Storage;
-import com.cloud.storage.StoragePool;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.GuestOSCategoryDao;
@@ -322,20 +322,9 @@ public void commitMigration(NicProfile nic, Network network, VirtualMachineProfi
     private DataStore findDataStore(VirtualMachineProfile profile, DeployDestination dest) {
         DataStore dataStore = null;
         if (VirtualMachineManager.VmConfigDriveOnPrimaryPool.value()) {
-            if (dest.getStorageForDisks() != null) {
-                for (final Volume volume : dest.getStorageForDisks().keySet()) {
-                    if (volume.getVolumeType() == Volume.Type.ROOT) {
-                        final StoragePool primaryPool = dest.getStorageForDisks().get(volume);
-                        dataStore = _dataStoreMgr.getDataStore(primaryPool.getId(), DataStoreRole.Primary);
-                        break;
-                    }
-                }
-            }
-            if (dataStore == null) {
-                final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(profile.getVirtualMachine().getId(), Volume.Type.ROOT);
-                if (volumes != null && volumes.size() > 0) {
-                    dataStore = _dataStoreMgr.getDataStore(volumes.get(0).getPoolId(), DataStoreRole.Primary);
-                }
+            final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(profile.getVirtualMachine().getId(), Volume.Type.ROOT);
+            if (CollectionUtils.isNotEmpty(volumes)) {
+                dataStore = pickDataStoreFromVolumes(volumes);
             }
         } else {
             dataStore = _dataStoreMgr.getImageStore(dest.getDataCenter().getId());
@@ -343,6 +332,42 @@ private DataStore findDataStore(VirtualMachineProfile profile, DeployDestination
         return dataStore;
     }
 
+    private DataStore pickDataStoreFromVolumes(List<VolumeVO> volumes) {
+        DataStore dataStore = null;
+        for (Volume vol : volumes) {
+            switch (vol.getState()) {
+            case Migrating:
+            case Expunging:
+            case Expunged:
+            case Destroy:
+            case Destroying:
+            case UploadOp:
+            case Uploaded:
+            case NotUploaded:
+            case UploadInProgress:
+            case UploadError:
+            case UploadAbandoned:
+            default:
+                break;
+            case Allocated:
+            case Creating:
+            case Ready:
+            case Snapshotting:
+            case RevertSnapshotting:
+            case Resizing:
+            case Copying:
+            case Attaching:
+                dataStore = _dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
+                if (dataStore != null) {
+                    return dataStore;
+                }
+                break;
+            }
+
+        }
+        return dataStore;
+    }
+
     private Long findAgentIdForImageStore(final DataStore dataStore) throws ResourceUnavailableException {
         EndPoint endpoint = _ep.select(dataStore);
         if (endpoint == null) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services