CLOUDSTACK-6170 Corrected an issue related to the "Reinstall VM" command and managed storage with VMware

This commit is contained in:
Mike Tutkowski 2014-05-01 21:50:47 -06:00
parent 7f595778ad
commit 8ac7784db2
3 changed files with 45 additions and 22 deletions

View File

@ -1334,7 +1334,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
AttachAnswer answer = new AttachAnswer(disk);
if (isAttach) {
vmMo.attachDisk(new String[] {datastoreVolumePath}, morDs);
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
} else {
vmMo.removeAllSnapshots();
vmMo.detachDisk(datastoreVolumePath, false);
@ -1800,7 +1800,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return null;
}
private void deleteVmfsDatastore(VmwareHypervisorHost hyperHost, String volumeUuid, String storageIpAddress, int storagePortNumber, String iqn) throws Exception {
private void removeVmfsDatastore(VmwareHypervisorHost hyperHost, String volumeUuid, String storageIpAddress, int storagePortNumber, String iqn) throws Exception {
// hyperHost.unmountDatastore(volumeUuid);
VmwareContext context = hostService.getServiceContext(null);
@ -1994,7 +1994,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
deleteVmfsDatastore(hyperHost, VmwareResource.getDatastoreName(iqn), storageHost, storagePort, trimIqn(iqn));
removeVmfsDatastore(hyperHost, VmwareResource.getDatastoreName(iqn), storageHost, storagePort, trimIqn(iqn));
}
private void removeManagedTargetsFromCluster(List<String> iqns) throws Exception {

View File

@ -1514,7 +1514,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
// 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
// volume.getPoolId() should be null if the VM we are detaching the disk from 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);

View File

@ -71,6 +71,7 @@ import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationSer
import org.apache.cloudstack.engine.service.api.OrchestrationService;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@ -82,6 +83,7 @@ import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.storage.command.DeleteCommand;
import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@ -97,7 +99,6 @@ import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.StartAnswer;
import com.cloud.agent.api.VmDiskStatsEntry;
import com.cloud.agent.api.VmStatsEntry;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
@ -4609,14 +4610,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume);
}
handleManagedStorage(vm, root);
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
/* Detach and destory the old root volume */
_volsDao.detachVolume(root.getId());
handleManagedStorage(vm, root);
volumeMgr.destroyVolume(root);
// For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage
@ -4671,19 +4672,44 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (hostId != null) {
DataTO volTO = volFactory.getVolume(root.getId()).getTO();
DiskTO disk = new DiskTO(volTO, root.getDeviceId(), root.getPath(), root.getVolumeType());
VolumeInfo volumeInfo = volFactory.getVolume(root.getId());
Host host = _hostDao.findById(hostId);
// it's OK in this case to send a detach command to the host for a root volume as this
// will simply lead to the SR that supports the root volume being removed
DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName());
final Command cmd;
cmd.setManaged(true);
if (host.getHypervisorType() == HypervisorType.XenServer) {
DiskTO disk = new DiskTO(volumeInfo.getTO(), root.getDeviceId(), root.getPath(), root.getVolumeType());
cmd.setStorageHost(storagePool.getHostAddress());
cmd.setStoragePort(storagePool.getPort());
// it's OK in this case to send a detach command to the host for a root volume as this
// will simply lead to the SR that supports the root volume being removed
cmd = new DettachCommand(disk, vm.getInstanceName());
cmd.set_iScsiName(root.get_iScsiName());
DettachCommand detachCommand = (DettachCommand)cmd;
detachCommand.setManaged(true);
detachCommand.setStorageHost(storagePool.getHostAddress());
detachCommand.setStoragePort(storagePool.getPort());
detachCommand.set_iScsiName(root.get_iScsiName());
}
else if (host.getHypervisorType() == HypervisorType.VMware) {
PrimaryDataStore primaryDataStore = (PrimaryDataStore)volumeInfo.getDataStore();
Map<String, String> details = primaryDataStore.getDetails();
if (details == null) {
details = new HashMap<String, String>();
primaryDataStore.setDetails(details);
}
details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
cmd = new DeleteCommand(volumeInfo.getTO());
}
else {
throw new CloudRuntimeException("This hypervisor type is not supported on managed storage for this command.");
}
Commands cmds = new Commands(Command.OnError.Stop);
@ -4706,13 +4732,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
}
if (hostId != null) {
// root.getPoolId() should be null if the VM we are attaching the disk to has never been started before
DataStore dataStore = root.getPoolId() != null ? _dataStoreMgr.getDataStore(root.getPoolId(), DataStoreRole.Primary) : null;
Host host = _hostDao.findById(hostId);
// root.getPoolId() should be null if the VM we are detaching the disk from has never been started before
DataStore dataStore = root.getPoolId() != null ? _dataStoreMgr.getDataStore(root.getPoolId(), DataStoreRole.Primary) : null;
volumeMgr.disconnectVolumeFromHost(volFactory.getVolume(root.getId()), host, dataStore);
}
volumeMgr.disconnectVolumeFromHost(volFactory.getVolume(root.getId()), host, dataStore);
}
}
}