From 574fc3a4f8fa5927b488f817f99ff33a91eccd10 Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Mon, 23 Dec 2013 20:28:07 -0700 Subject: [PATCH] CLOUDSTACK-5662: XenServer can't discover iSCSI targets with different credentials --- api/src/com/cloud/host/Host.java | 5 + .../agent/test/CheckOnHostCommandTest.java | 4 + .../api/storage/PrimaryDataStoreDriver.java | 5 + .../subsystem/api/storage/VolumeService.java | 5 + .../test/FakePrimaryDataStoreDriver.java | 17 +- .../storage/volume/VolumeServiceImpl.java | 18 + .../vmware/resource/VmwareResource.java | 51 +- .../CloudStackPrimaryDataStoreDriverImpl.java | 8 + .../SamplePrimaryDataStoreDriverImpl.java | 8 + .../SolidfirePrimaryDataStoreDriver.java | 212 +++++++- .../storage/datastore/util/SolidFireUtil.java | 473 ++++++++++++------ .../cloud/storage/VolumeApiServiceImpl.java | 41 +- .../cloud/hypervisor/vmware/mo/HostMO.java | 5 +- 13 files changed, 670 insertions(+), 182 deletions(-) diff --git a/api/src/com/cloud/host/Host.java b/api/src/com/cloud/host/Host.java index 581bd47c5f4..9a20f6287e5 100755 --- a/api/src/com/cloud/host/Host.java +++ b/api/src/com/cloud/host/Host.java @@ -91,6 +91,11 @@ public interface Host extends StateObject, Identity, InternalIdentity { */ String getPrivateIpAddress(); + /** + * @return the ip address of the host. + */ + String getStorageUrl(); + /** * @return the ip address of the host attached to the storage network. */ diff --git a/core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java b/core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java index 031ef5cfea8..e8090db5527 100644 --- a/core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java +++ b/core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java @@ -76,6 +76,10 @@ public class CheckOnHostCommandTest { return "10.1.1.1"; }; + public String getStorageUrl() { + return null; + } + public String getStorageIpAddress() { return "10.1.1.2"; }; diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java index 6c353d9363a..36091e0dae8 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java @@ -18,14 +18,19 @@ */ package org.apache.cloudstack.engine.subsystem.api.storage; +import java.util.List; + import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.command.CommandResult; +import com.cloud.host.Host; import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; public interface PrimaryDataStoreDriver extends DataStoreDriver { public ChapInfo getChapInfo(VolumeInfo volumeInfo); + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore); + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore); public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool); public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java index 7515088f331..bdd4a17a53b 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import java.util.Map; +import java.util.List; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.framework.async.AsyncCallFuture; @@ -44,6 +45,10 @@ public interface VolumeService { ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore); + boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore); + + void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore); + /** * Creates the volume based on the given criteria * diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java index 72373e29e5f..399d2d1dc60 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java @@ -18,6 +18,8 @@ */ package org.apache.cloudstack.storage.test; +import java.util.List; +import java.util.Map; import java.util.UUID; import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; @@ -35,16 +37,29 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; +import com.cloud.host.Host; import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; public class FakePrimaryDataStoreDriver implements PrimaryDataStoreDriver { boolean snapshotResult = true; + + @Override + public Map getCapabilities() { + return null; + } + @Override public ChapInfo getChapInfo(VolumeInfo volumeInfo) { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; // To change body of implemented methods, use File | Settings | File Templates. } + @Override + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; } + + @Override + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {} + @Override public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) { return volume.getSize(); diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 3cef23db8ef..b9dbd92a875 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -159,6 +159,24 @@ public class VolumeServiceImpl implements VolumeService { return null; } + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { + DataStoreDriver dataStoreDriver = dataStore.getDriver(); + + if (dataStoreDriver instanceof PrimaryDataStoreDriver) { + return ((PrimaryDataStoreDriver)dataStoreDriver).connectVolumeToHost(volumeInfo, host, dataStore); + } + + return false; + } + + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { + DataStoreDriver dataStoreDriver = dataStore.getDriver(); + + if (dataStoreDriver instanceof PrimaryDataStoreDriver) { + ((PrimaryDataStoreDriver)dataStoreDriver).disconnectVolumeFromHost(volumeInfo, host, dataStore); + } + } + @Override public AsyncCallFuture createVolumeAsync(VolumeInfo volume, DataStore dataStore) { AsyncCallFuture future = new AsyncCallFuture(); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index ee802d2e454..45803b5cefa 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4808,22 +4808,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa target.setPort(storagePortNumber); target.setIScsiName(iqn); - HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties(); + if (StringUtils.isNotBlank(chapName) && StringUtils.isNotBlank(chapSecret)) { + HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties(); - String strAuthType = "chapRequired"; + String strAuthType = "chapRequired"; - auth.setChapAuthEnabled(true); - auth.setChapInherited(false); - auth.setChapAuthenticationType(strAuthType); - auth.setChapName(chapName); - auth.setChapSecret(chapSecret); + auth.setChapAuthEnabled(true); + auth.setChapInherited(false); + auth.setChapAuthenticationType(strAuthType); + auth.setChapName(chapName); + auth.setChapSecret(chapSecret); - auth.setMutualChapInherited(false); - auth.setMutualChapAuthenticationType(strAuthType); - auth.setMutualChapName(mutualChapName); - auth.setMutualChapSecret(mutualChapSecret); + if (StringUtils.isNotBlank(mutualChapName) && StringUtils.isNotBlank(mutualChapSecret)) { + auth.setMutualChapInherited(false); + auth.setMutualChapAuthenticationType(strAuthType); + auth.setMutualChapName(mutualChapName); + auth.setMutualChapSecret(mutualChapSecret); + } - target.setAuthenticationProperties(auth); + target.setAuthenticationProperties(auth); + } final List lstTargets = new ArrayList(); @@ -6062,11 +6066,34 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa cmd.setName(_url); cmd.setGuid(_guid); cmd.setDataCenter(_dcId); + cmd.setIqn(getIqn()); cmd.setPod(_pod); cmd.setCluster(_cluster); cmd.setVersion(VmwareResource.class.getPackage().getImplementationVersion()); } + private String getIqn() { + try { + VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); + + if (hyperHost instanceof HostMO) { + HostMO host = (HostMO)hyperHost; + HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO(); + + for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) { + if (hba instanceof HostInternetScsiHba) { + return ((HostInternetScsiHba)hba).getIScsiName(); + } + } + } + } + catch (Exception ex) { + s_logger.info("Could not locate an IQN for this host."); + } + + return null; + } + private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException, Exception { VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java index ed32a9a28c6..f1690fd7db7 100644 --- a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.storage.datastore.driver; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -52,6 +53,7 @@ import com.cloud.agent.api.to.DataTO; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.configuration.Config; import com.cloud.exception.StorageUnavailableException; +import com.cloud.host.Host; import com.cloud.host.dao.HostDao; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotDao; @@ -130,6 +132,12 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri return null; } + @Override + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; } + + @Override + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {} + @Override public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) { return volume.getSize(); diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java index 67e0a7169a8..82694e76a20 100644 --- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java @@ -40,12 +40,14 @@ import org.apache.cloudstack.storage.datastore.DataObjectManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; +import com.cloud.host.Host; import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.exception.CloudRuntimeException; import java.util.HashMap; +import java.util.List; import java.util.Map; public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { @@ -81,6 +83,12 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver return null; } + @Override + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; } + + @Override + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {} + @Override public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) { return volume.getSize(); diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java index 7534ce4dff3..ff3e33b9425 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java @@ -17,9 +17,10 @@ package org.apache.cloudstack.storage.datastore.driver; import java.text.NumberFormat; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; import javax.inject.Inject; @@ -37,7 +38,12 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.dao.DataCenterDao; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; @@ -48,6 +54,7 @@ import com.cloud.user.AccountDetailVO; import com.cloud.user.AccountDetailsDao; import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; +import com.cloud.utils.exception.CloudRuntimeException; public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { @Inject private PrimaryDataStoreDao _storagePoolDao; @@ -57,6 +64,8 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { @Inject private DataCenterDao _zoneDao; @Inject private AccountDao _accountDao; @Inject private AccountDetailsDao _accountDetailsDao; + @Inject private ClusterDetailsDao _clusterDetailsDao; + @Inject private HostDao _hostDao; @Override public Map getCapabilities() { @@ -139,35 +148,35 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { } private void updateCsDbWithAccountInfo(long csAccountId, SolidFireUtil.SolidFireAccount sfAccount) { - AccountDetailVO accountDetails = new AccountDetailVO(csAccountId, + AccountDetailVO accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.ACCOUNT_ID, String.valueOf(sfAccount.getId())); - _accountDetailsDao.persist(accountDetails); + _accountDetailsDao.persist(accountDetail); - accountDetails = new AccountDetailVO(csAccountId, + accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.CHAP_INITIATOR_USERNAME, String.valueOf(sfAccount.getName())); - _accountDetailsDao.persist(accountDetails); + _accountDetailsDao.persist(accountDetail); - accountDetails = new AccountDetailVO(csAccountId, + accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.CHAP_INITIATOR_SECRET, String.valueOf(sfAccount.getInitiatorSecret())); - _accountDetailsDao.persist(accountDetails); + _accountDetailsDao.persist(accountDetail); - accountDetails = new AccountDetailVO(csAccountId, + accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.CHAP_TARGET_USERNAME, sfAccount.getName()); - _accountDetailsDao.persist(accountDetails); + _accountDetailsDao.persist(accountDetail); - accountDetails = new AccountDetailVO(csAccountId, + accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.CHAP_TARGET_SECRET, sfAccount.getTargetSecret()); - _accountDetailsDao.persist(accountDetails); + _accountDetailsDao.persist(accountDetail); } private class ChapInfoImpl implements ChapInfo { @@ -225,8 +234,180 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { String chapTargetSecret = accountDetail.getValue(); - return new ChapInfoImpl(chapInitiatorUsername, chapInitiatorSecret, - chapTargetUsername, chapTargetSecret); + return new ChapInfoImpl(chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret); + } + + // get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) + // if the VAG exists + // update the VAG to contain all IQNs of the hosts (ModifyVolumeAccessGroup) + // if the ID of volumeInfo in not in the VAG, add it (ModifyVolumeAccessGroup) + // if the VAG doesn't exist, create it with the IQNs of the hosts and the ID of volumeInfo (CreateVolumeAccessGroup) + @Override + public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) + { + if (volumeInfo == null || host == null || dataStore == null) { + return false; + } + + long sfVolumeId = Long.parseLong(volumeInfo.getFolder()); + long clusterId = host.getClusterId(); + long storagePoolId = dataStore.getId(); + + ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, getVagKey(storagePoolId)); + + String vagId = clusterDetail != null ? clusterDetail.getValue() : null; + + List hosts = _hostDao.findByClusterId(clusterId); + + if (!hostsSupport_iScsi(hosts)) { + return false; + } + + SolidFireConnection sfConnection = getSolidFireConnection(storagePoolId); + + if (vagId != null) { + SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(), + sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), Long.parseLong(vagId)); + + long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true); + + SolidFireUtil.modifySolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(), + sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), sfVag.getId(), + getIqnsFromHosts(hosts), volumeIds); + } + else { + long lVagId = SolidFireUtil.createSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(), + sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), "CloudStack-" + UUID.randomUUID().toString(), + getIqnsFromHosts(hosts), new long[] { sfVolumeId }); + + clusterDetail = new ClusterDetailsVO(clusterId, getVagKey(storagePoolId), String.valueOf(lVagId)); + + _clusterDetailsDao.persist(clusterDetail); + } + + return true; + } + + // get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) // might not exist if using CHAP + // if the VAG exists + // remove the ID of volumeInfo from the VAG (ModifyVolumeAccessGroup) + @Override + public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) + { + if (volumeInfo == null || host == null || dataStore == null) { + return; + } + + long sfVolumeId = Long.parseLong(volumeInfo.getFolder()); + long clusterId = host.getClusterId(); + long storagePoolId = dataStore.getId(); + + ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, getVagKey(storagePoolId)); + + String vagId = clusterDetail != null ? clusterDetail.getValue() : null; + + if (vagId != null) { + List hosts = _hostDao.findByClusterId(clusterId); + + SolidFireConnection sfConnection = getSolidFireConnection(storagePoolId); + + SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(), + sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), Long.parseLong(vagId)); + + long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, false); + + SolidFireUtil.modifySolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(), + sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), sfVag.getId(), + getIqnsFromHosts(hosts), volumeIds); + } + } + + private boolean hostsSupport_iScsi(List hosts) { + if (hosts == null || hosts.size() == 0) { + return false; + } + + for (Host host : hosts) { + if (host == null || host.getStorageUrl() == null || host.getStorageUrl().trim().length() == 0 || !host.getStorageUrl().startsWith("iqn")) { + return false; + } + } + + return true; + } + + private long[] getNewVolumeIds(long[] volumeIds, long volumeIdToAddOrRemove, boolean add) { + if (add) { + return getNewVolumeIdsAdd(volumeIds, volumeIdToAddOrRemove); + } + + return getNewVolumeIdsRemove(volumeIds, volumeIdToAddOrRemove); + } + + private long[] getNewVolumeIdsAdd(long[] volumeIds, long volumeIdToAdd) { + List lstVolumeIds = new ArrayList(); + + if (volumeIds != null) { + for (long volumeId : volumeIds) { + lstVolumeIds.add(volumeId); + } + } + + if (lstVolumeIds.contains(volumeIdToAdd)) { + return volumeIds; + } + + lstVolumeIds.add(volumeIdToAdd); + + return convertArray(lstVolumeIds); + } + + private long[] getNewVolumeIdsRemove(long[] volumeIds, long volumeIdToRemove) { + List lstVolumeIds = new ArrayList(); + + if (volumeIds != null) { + for (long volumeId : volumeIds) { + lstVolumeIds.add(volumeId); + } + } + + lstVolumeIds.remove(volumeIdToRemove); + + return convertArray(lstVolumeIds); + } + + private long[] convertArray(List items) { + if (items == null) { + return new long[0]; + } + + long[] outArray = new long[items.size()]; + + for (int i = 0; i < items.size(); i++) { + Long value = items.get(i); + + outArray[i] = value; + } + + return outArray; + } + + private String getVagKey(long storagePoolId) { + return "sfVolumeAccessGroup_" + storagePoolId; + } + + private String[] getIqnsFromHosts(List hosts) { + if (hosts == null || hosts.size() == 0) { + throw new CloudRuntimeException("There do not appear to be any hosts in this cluster."); + } + + List lstIqns = new ArrayList(); + + for (Host host : hosts) { + lstIqns.add(host.getStorageUrl()); + } + + return lstIqns.toArray(new String[0]); } private long getDefaultMinIops(long storagePoolId) { @@ -462,6 +643,7 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { callback.complete(result); } + /* private void deleteSolidFireAccount(long sfAccountId, SolidFireConnection sfConnection) { String mVip = sfConnection.getManagementVip(); int mPort = sfConnection.getManagementPort(); @@ -502,10 +684,10 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { return false; } + */ @Override - public void deleteAsync(DataStore dataStore, DataObject dataObject, - AsyncCompletionCallback callback) { + public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback callback) { String errMsg = null; if (dataObject.getType() == DataObjectType.VOLUME) { diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java index c3e302502a0..a3724977b8a 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java @@ -95,32 +95,6 @@ public class SolidFireUtil return volumeCreateResult.result.volumeID; } - public static SolidFireVolume deleteSolidFireVolume(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVolumeId) - { - SolidFireVolume sfVolume = getSolidFireVolume(strSfMvip, iSfPort, strSfAdmin, strSfPassword, lVolumeId); - - final Gson gson = new GsonBuilder().create(); - - VolumeToDelete volumeToDelete = new VolumeToDelete(lVolumeId); - - String strVolumeToDeleteJson = gson.toJson(volumeToDelete); - - executeJsonRpc(strVolumeToDeleteJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); - - return sfVolume; - } - - public static void purgeSolidFireVolume(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVolumeId) - { - final Gson gson = new GsonBuilder().create(); - - VolumeToPurge volumeToPurge = new VolumeToPurge(lVolumeId); - - String strVolumeToPurgeJson = gson.toJson(volumeToPurge); - - executeJsonRpc(strVolumeToPurgeJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); - } - public static SolidFireVolume getSolidFireVolume(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVolumeId) { final Gson gson = new GsonBuilder().create(); @@ -167,9 +141,59 @@ public class SolidFireUtil } return sfVolumes; - } + } - private static final String ACTIVE = "active"; + public static List getDeletedVolumes(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword) + { + final Gson gson = new GsonBuilder().create(); + + ListDeletedVolumes listDeletedVolumes = new ListDeletedVolumes(); + + String strListDeletedVolumesJson = gson.toJson(listDeletedVolumes); + + String strListDeletedVolumesResultJson = executeJsonRpc(strListDeletedVolumesJson, strSfMvip, iSfPort, + strSfAdmin, strSfPassword); + + VolumeGetResult volumeGetResult = gson.fromJson(strListDeletedVolumesResultJson, VolumeGetResult.class); + + verifyResult(volumeGetResult.result, strListDeletedVolumesResultJson, gson); + + List deletedVolumes = new ArrayList (); + + for (VolumeGetResult.Result.Volume volume : volumeGetResult.result.volumes) { + deletedVolumes.add(new SolidFireVolume(volume.volumeID, volume.name, volume.iqn, volume.accountID, volume.status, volume.totalSize)); + } + + return deletedVolumes; + } + + public static SolidFireVolume deleteSolidFireVolume(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVolumeId) + { + SolidFireVolume sfVolume = getSolidFireVolume(strSfMvip, iSfPort, strSfAdmin, strSfPassword, lVolumeId); + + final Gson gson = new GsonBuilder().create(); + + VolumeToDelete volumeToDelete = new VolumeToDelete(lVolumeId); + + String strVolumeToDeleteJson = gson.toJson(volumeToDelete); + + executeJsonRpc(strVolumeToDeleteJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); + + return sfVolume; + } + + public static void purgeSolidFireVolume(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVolumeId) + { + final Gson gson = new GsonBuilder().create(); + + VolumeToPurge volumeToPurge = new VolumeToPurge(lVolumeId); + + String strVolumeToPurgeJson = gson.toJson(volumeToPurge); + + executeJsonRpc(strVolumeToPurgeJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); + } + + private static final String ACTIVE = "active"; public static class SolidFireVolume { @@ -250,7 +274,7 @@ public class SolidFireUtil return false; } - } + } public static long createSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, String strAccountName) @@ -270,18 +294,6 @@ public class SolidFireUtil return accountAddResult.result.accountID; } - public static void deleteSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, - long lAccountId) - { - final Gson gson = new GsonBuilder().create(); - - AccountToRemove accountToRemove = new AccountToRemove(lAccountId); - - String strAccountToRemoveJson = gson.toJson(accountToRemove); - - executeJsonRpc(strAccountToRemoveJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); - } - public static SolidFireAccount getSolidFireAccountById(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lSfAccountId) { @@ -326,6 +338,18 @@ public class SolidFireUtil return new SolidFireAccount(lSfAccountId, strSfAccountName, strSfAccountInitiatorSecret, strSfAccountTargetSecret); } + public static void deleteSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, + long lAccountId) + { + final Gson gson = new GsonBuilder().create(); + + AccountToRemove accountToRemove = new AccountToRemove(lAccountId); + + String strAccountToRemoveJson = gson.toJson(accountToRemove); + + executeJsonRpc(strAccountToRemoveJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); + } + public static class SolidFireAccount { private final long _id; @@ -382,46 +406,23 @@ public class SolidFireUtil } SolidFireAccount sfa = (SolidFireAccount)obj; - + if (_id == sfa._id && _name.equals(sfa._name) && _initiatorSecret.equals(sfa._initiatorSecret) && _targetSecret.equals(sfa._targetSecret)) { return true; } - + return false; } } - public static List getDeletedVolumes(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword) + public static long createSolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, String strVagName, + String[] iqns, long[] volumeIds) { final Gson gson = new GsonBuilder().create(); - ListDeletedVolumes listDeletedVolumes = new ListDeletedVolumes(); - - String strListDeletedVolumesJson = gson.toJson(listDeletedVolumes); - - String strListDeletedVolumesResultJson = executeJsonRpc(strListDeletedVolumesJson, strSfMvip, iSfPort, - strSfAdmin, strSfPassword); - - VolumeGetResult volumeGetResult = gson.fromJson(strListDeletedVolumesResultJson, VolumeGetResult.class); - - verifyResult(volumeGetResult.result, strListDeletedVolumesResultJson, gson); - - List deletedVolumes = new ArrayList (); - - for (VolumeGetResult.Result.Volume volume : volumeGetResult.result.volumes) { - deletedVolumes.add(new SolidFireVolume(volume.volumeID, volume.name, volume.iqn, volume.accountID, volume.status, volume.totalSize)); - } - - return deletedVolumes; - } - - public static long createSolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, String strVagName) - { - final Gson gson = new GsonBuilder().create(); - - VagToCreate vagToCreate = new VagToCreate(strVagName); + VagToCreate vagToCreate = new VagToCreate(strVagName, iqns, volumeIds); String strVagCreateJson = gson.toJson(vagToCreate); @@ -434,6 +435,38 @@ public class SolidFireUtil return vagCreateResult.result.volumeAccessGroupID; } + public static void modifySolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVagId, + String[] iqns, long[] volumeIds) + { + final Gson gson = new GsonBuilder().create(); + + VagToModify vagToModify = new VagToModify(lVagId, iqns, volumeIds); + + String strVagModifyJson = gson.toJson(vagToModify); + + executeJsonRpc(strVagModifyJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); + } + + public static SolidFireVag getSolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVagId) + { + final Gson gson = new GsonBuilder().create(); + + VagToGet vagToGet = new VagToGet(lVagId); + + String strVagToGetJson = gson.toJson(vagToGet); + + String strVagGetResultJson = executeJsonRpc(strVagToGetJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); + + VagGetResult vagGetResult = gson.fromJson(strVagGetResultJson, VagGetResult.class); + + verifyResult(vagGetResult.result, strVagGetResultJson, gson); + + String[] vagIqns = getVagIqns(vagGetResult, lVagId); + long[] vagVolumeIds = getVagVolumeIds(vagGetResult, lVagId); + + return new SolidFireVag(lVagId, vagIqns, vagVolumeIds); + } + public static void deleteSolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVagId) { final Gson gson = new GsonBuilder().create(); @@ -445,6 +478,64 @@ public class SolidFireUtil executeJsonRpc(strVagToDeleteJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword); } + public static class SolidFireVag + { + private final long _id; + private final String[] _initiators; + private final long[] _volumeIds; + + public SolidFireVag(long id, String[] initiators, long[] volumeIds) + { + _id = id; + _initiators = initiators; + _volumeIds = volumeIds; + } + + public long getId() + { + return _id; + } + + public String[] getInitiators() + { + return _initiators; + } + + public long[] getVolumeIds() + { + return _volumeIds; + } + + @Override + public int hashCode() { + return String.valueOf(_id).hashCode(); + } + + @Override + public String toString() { + return String.valueOf(_id); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (!obj.getClass().equals(SolidFireVag.class)) { + return false; + } + + SolidFireVag sfvag = (SolidFireVag)obj; + + if (_id == sfvag._id) { + return true; + } + + return false; + } + } + @SuppressWarnings("unused") private static final class VolumeToCreate { @@ -505,56 +596,6 @@ public class SolidFireUtil } } - @SuppressWarnings("unused") - private static final class VolumeToDelete - { - private final String method = "DeleteVolume"; - private final VolumeToDeleteParams params; - - private VolumeToDelete(final long lVolumeId) - { - params = new VolumeToDeleteParams(lVolumeId); - } - - private static final class VolumeToDeleteParams - { - private long volumeID; - - private VolumeToDeleteParams(final long lVolumeId) - { - volumeID = lVolumeId; - } - } - } - - @SuppressWarnings("unused") - private static final class ListDeletedVolumes - { - private final String method = "ListDeletedVolumes"; - } - - @SuppressWarnings("unused") - private static final class VolumeToPurge - { - private final String method = "PurgeDeletedVolume"; - private final VolumeToPurgeParams params; - - private VolumeToPurge(final long lVolumeId) - { - params = new VolumeToPurgeParams(lVolumeId); - } - - private static final class VolumeToPurgeParams - { - private long volumeID; - - private VolumeToPurgeParams(final long lVolumeId) - { - volumeID = lVolumeId; - } - } - } - @SuppressWarnings("unused") private static final class VolumeToGet { @@ -600,6 +641,56 @@ public class SolidFireUtil } } + @SuppressWarnings("unused") + private static final class ListDeletedVolumes + { + private final String method = "ListDeletedVolumes"; + } + + @SuppressWarnings("unused") + private static final class VolumeToDelete + { + private final String method = "DeleteVolume"; + private final VolumeToDeleteParams params; + + private VolumeToDelete(final long lVolumeId) + { + params = new VolumeToDeleteParams(lVolumeId); + } + + private static final class VolumeToDeleteParams + { + private long volumeID; + + private VolumeToDeleteParams(final long lVolumeId) + { + volumeID = lVolumeId; + } + } + } + + @SuppressWarnings("unused") + private static final class VolumeToPurge + { + private final String method = "PurgeDeletedVolume"; + private final VolumeToPurgeParams params; + + private VolumeToPurge(final long lVolumeId) + { + params = new VolumeToPurgeParams(lVolumeId); + } + + private static final class VolumeToPurgeParams + { + private long volumeID; + + private VolumeToPurgeParams(final long lVolumeId) + { + volumeID = lVolumeId; + } + } + } + @SuppressWarnings("unused") private static final class AccountToAdd { @@ -622,28 +713,6 @@ public class SolidFireUtil } } - @SuppressWarnings("unused") - private static final class AccountToRemove - { - private final String method = "RemoveAccount"; - private final AccountToRemoveParams params; - - private AccountToRemove(final long lAccountId) - { - params = new AccountToRemoveParams(lAccountId); - } - - private static final class AccountToRemoveParams - { - private long accountID; - - private AccountToRemoveParams(final long lAccountId) - { - accountID = lAccountId; - } - } - } - @SuppressWarnings("unused") private static final class AccountToGetById { @@ -688,24 +757,99 @@ public class SolidFireUtil } } + @SuppressWarnings("unused") + private static final class AccountToRemove + { + private final String method = "RemoveAccount"; + private final AccountToRemoveParams params; + + private AccountToRemove(final long lAccountId) + { + params = new AccountToRemoveParams(lAccountId); + } + + private static final class AccountToRemoveParams + { + private long accountID; + + private AccountToRemoveParams(final long lAccountId) + { + accountID = lAccountId; + } + } + } + @SuppressWarnings("unused") private static final class VagToCreate { private final String method = "CreateVolumeAccessGroup"; private final VagToCreateParams params; - private VagToCreate(final String strVagName) + private VagToCreate(final String strVagName, final String[] iqns, final long[] volumeIds) { - params = new VagToCreateParams(strVagName); + params = new VagToCreateParams(strVagName, iqns, volumeIds); } private static final class VagToCreateParams { private final String name; + private final String[] initiators; + private final long[] volumes; - private VagToCreateParams(final String strVagName) + private VagToCreateParams(final String strVagName, final String[] iqns, final long[] volumeIds) { name = strVagName; + initiators = iqns; + volumes = volumeIds; + } + } + } + + @SuppressWarnings("unused") + private static final class VagToModify + { + private final String method = "ModifyVolumeAccessGroup"; + private final VagToModifyParams params; + + private VagToModify(final long lVagName, final String[] iqns, final long[] volumeIds) + { + params = new VagToModifyParams(lVagName, iqns, volumeIds); + } + + private static final class VagToModifyParams + { + private final long volumeAccessGroupID; + private final String[] initiators; + private final long[] volumes; + + private VagToModifyParams(final long lVagName, final String[] iqns, final long[] volumeIds) + { + volumeAccessGroupID = lVagName; + initiators = iqns; + volumes = volumeIds; + } + } + } + + @SuppressWarnings("unused") + private static final class VagToGet + { + private final String method = "ListVolumeAccessGroups"; + private final VagToGetParams params; + + private VagToGet(final long lVagId) + { + params = new VagToGetParams(lVagId); + } + + private static final class VagToGetParams + { + private final long startVolumeAccessGroupID; + private final long limit = 1; + + private VagToGetParams(final long lVagId) + { + startVolumeAccessGroupID = lVagId; } } } @@ -800,6 +944,23 @@ public class SolidFireUtil } } + private static final class VagGetResult + { + private Result result; + + private static final class Result + { + private Vag[] volumeAccessGroups; + + private static final class Vag + { + private long volumeAccessGroupID; + private String[] initiators; + private long[] volumes; + } + } + } + private static final class JsonError { private Error error; @@ -859,7 +1020,7 @@ public class SolidFireUtil httpClient = getHttpClient(iPort); - URI uri = new URI("https://" + strMvip + ":" + iPort + "/json-rpc/1.0"); + URI uri = new URI("https://" + strMvip + ":" + iPort + "/json-rpc/5.0"); AuthScope authScope = new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_SCHEME); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(strAdmin, strPassword); @@ -983,4 +1144,26 @@ public class SolidFireUtil throw new CloudRuntimeException("Could not determine the total size of the volume for volume ID of " + lVolumeId + "."); } + + private static String[] getVagIqns(VagGetResult vagGetResult, long lVagId) + { + if (vagGetResult.result.volumeAccessGroups != null && vagGetResult.result.volumeAccessGroups.length == 1 && + vagGetResult.result.volumeAccessGroups[0].volumeAccessGroupID == lVagId) + { + return vagGetResult.result.volumeAccessGroups[0].initiators; + } + + throw new CloudRuntimeException("Could not determine the IQNs of the volume access group for volume access group ID of " + lVagId + "."); + } + + private static long[] getVagVolumeIds(VagGetResult vagGetResult, long lVagId) + { + if (vagGetResult.result.volumeAccessGroups != null && vagGetResult.result.volumeAccessGroups.length == 1 && + vagGetResult.result.volumeAccessGroups[0].volumeAccessGroupID == lVagId) + { + return vagGetResult.result.volumeAccessGroups[0].volumes; + } + + throw new CloudRuntimeException("Could not determine the volume IDs of the volume access group for volume access group ID of " + lVagId + "."); + } } diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 1d1c2b1e7bc..90038e74b29 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1439,8 +1439,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic Volume volume = _volumeDao.findById(volumeId); VMInstanceVO vm = _vmInstanceDao.findById(vmId); - String errorMsg = "Failed to detach volume: " + volume.getName() + " from VM: " + vm.getHostName(); - boolean sendCommand = (vm.getState() == State.Running); + String errorMsg = "Failed to detach volume " + volume.getName() + " from VM " + vm.getHostName(); + boolean sendCommand = vm.getState() == State.Running; Long hostId = vm.getHostId(); @@ -1454,10 +1454,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } } + HostVO host = null; StoragePoolVO volumePool = _storagePoolDao.findById(volume.getPoolId()); if (hostId != null) { - HostVO host = _hostDao.findById(hostId); + host = _hostDao.findById(hostId); if (host != null && host.getHypervisorType() == HypervisorType.XenServer && volumePool.isManaged()) { sendCommand = true; @@ -1486,10 +1487,14 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } } + DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary); + if (!sendCommand || (answer != null && answer.getResult())) { // Mark the volume as detached _volsDao.detachVolume(volume.getId()); + volService.disconnectVolumeFromHost(volFactory.getVolume(volume.getId()), host, dataStore); + return _volsDao.findById(volumeId); } else { @@ -1871,13 +1876,14 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } private VolumeVO sendAttachVolumeCommand(UserVmVO vm, VolumeVO volumeToAttach, Long deviceId) { - String errorMsg = "Failed to attach volume: " + volumeToAttach.getName() + " to VM: " + vm.getHostName(); - boolean sendCommand = (vm.getState() == State.Running); + String errorMsg = "Failed to attach volume " + volumeToAttach.getName() + " to VM " + vm.getHostName(); + boolean sendCommand = vm.getState() == State.Running; AttachAnswer answer = null; Long hostId = vm.getHostId(); if (hostId == null) { hostId = vm.getLastHostId(); + HostVO host = _hostDao.findById(hostId); if (host != null && host.getHypervisorType() == HypervisorType.VMware) { @@ -1896,6 +1902,22 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } } + DataStore dataStore = dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), DataStoreRole.Primary); + + boolean queryForChap = true; + + if (host != null) { + try { + // if connectVolumeToHost returns true, then we do not want to use CHAP because the volume is already connected to the host(s) + queryForChap = !volService.connectVolumeToHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); + } + catch (Exception e) { + volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); + + throw new CloudRuntimeException(e.getMessage()); + } + } + if (sendCommand) { if (host.getHypervisorType() == HypervisorType.KVM && volumeToAttachStoragePool.isManaged() && @@ -1910,9 +1932,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic AttachCommand cmd = new AttachCommand(disk, vm.getInstanceName()); - VolumeInfo volumeInfo = volFactory.getVolume(volumeToAttach.getId()); - DataStore dataStore = dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), DataStoreRole.Primary); - ChapInfo chapInfo = volService.getChapInfo(volumeInfo, dataStore); + ChapInfo chapInfo = queryForChap ? volService.getChapInfo(volFactory.getVolume(volumeToAttach.getId()), dataStore) : null; Map details = new HashMap(); @@ -1934,6 +1954,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic try { answer = (AttachAnswer)_agentMgr.send(hostId, cmd); } catch (Exception e) { + volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); + throw new CloudRuntimeException(errorMsg + " due to: " + e.getMessage()); } } @@ -1970,6 +1992,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic errorMsg += "; " + details; } } + + volService.disconnectVolumeFromHost(volFactory.getVolume(volumeToAttach.getId()), host, dataStore); + throw new CloudRuntimeException(errorMsg); } } diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java index c4836a8ad1d..7ef8326033f 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java @@ -718,7 +718,10 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost { ManagedObjectReference morDs = oc.getObj(); String name = (String)VmwareHelper.getPropValue(oc, "name"); - dsList.add(new Pair(morDs, name)); + // "-iqn." is an identifier we use to note a CloudStack-managed datastore that should never be added to CloudStack as primary storage + if (!name.startsWith("-iqn.")) { + dsList.add(new Pair(morDs, name)); + } } } }