CLOUDSTACK-5873: [Automation] Failed to attach volume to VM, if the vm is created with option startvm=false

This commit is contained in:
Mike Tutkowski 2014-01-14 19:40:14 -07:00
parent aa6dddc778
commit 3ef560d925
3 changed files with 15 additions and 6 deletions

View File

@ -158,8 +158,9 @@ public class VolumeServiceImpl implements VolumeService {
return null;
}
@Override
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
DataStoreDriver dataStoreDriver = dataStore.getDriver();
DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null;
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
return ((PrimaryDataStoreDriver)dataStoreDriver).connectVolumeToHost(volumeInfo, host, dataStore);
@ -168,8 +169,9 @@ public class VolumeServiceImpl implements VolumeService {
return false;
}
@Override
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
DataStoreDriver dataStoreDriver = dataStore.getDriver();
DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null;
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
((PrimaryDataStoreDriver)dataStoreDriver).disconnectVolumeFromHost(volumeInfo, host, dataStore);

View File

@ -108,7 +108,11 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
if (volume.getVolumeType() == Volume.Type.DATADISK) {
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
if (storagePool.isManaged()) {
// storagePool should be null if we are expunging a volume that was never
// attached to a VM that was started (the "trick" for storagePool to be null
// is that none of the VMs this volume may have been attached to were ever started,
// so the volume was never assigned to a storage pool)
if (storagePool != null && storagePool.isManaged()) {
DataTO volTO = _volFactory.getVolume(volume.getId()).getTO();
DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());

View File

@ -1482,12 +1482,13 @@ 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());
// volume.getPoolId() should be null if the VM we are attaching the disk to has never been started before
DataStore dataStore = volume.getPoolId() != null ? dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary) : null;
volService.disconnectVolumeFromHost(volFactory.getVolume(volume.getId()), host, dataStore);
return _volsDao.findById(volumeId);
@ -1955,10 +1956,12 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
}
}
DataStore dataStore = dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), DataStoreRole.Primary);
// volumeToAttachStoragePool should be null if the VM we are attaching the disk to has never been started before
DataStore dataStore = volumeToAttachStoragePool != null ? dataStoreMgr.getDataStore(volumeToAttachStoragePool.getId(), DataStoreRole.Primary) : null;
boolean queryForChap = true;
// if we don't have a host, the VM we are attaching the disk to has never been started before
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)