use of com.cloud.legacymodel.to.VolumeTO in project cosmic by MissionCriticalCloud.
the class LibvirtDestroyCommandWrapper method execute.
@Override
public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VolumeTO vol = command.getVolume();
try {
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final KvmStoragePool pool = storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid());
pool.deletePhysicalDisk(vol.getPath(), null);
return new Answer(command, true, "Success");
} catch (final CloudRuntimeException e) {
s_logger.debug("Failed to delete volume: " + e.toString());
return new Answer(command, false, e.toString());
}
}
use of com.cloud.legacymodel.to.VolumeTO in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testDestroyCommandError.
@Test
public void testDestroyCommandError() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final Volume volume = Mockito.mock(Volume.class);
final String vmName = "Test";
final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final VolumeTO vol = command.getVolume();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
use of com.cloud.legacymodel.to.VolumeTO in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testDestroyCommand.
@Test
public void testDestroyCommand() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final Volume volume = Mockito.mock(Volume.class);
final String vmName = "Test";
final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final VolumeTO vol = command.getVolume();
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
use of com.cloud.legacymodel.to.VolumeTO in project cosmic by MissionCriticalCloud.
the class LibvirtMigrateWithStorageAcrossClustersCommandWrapper method execute.
@Override
public Answer execute(final MigrateWithStorageAcrossClustersCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VirtualMachineTO vm = command.getVirtualMachine();
try {
final LibvirtUtilitiesHelper utilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect sourceConnection = utilitiesHelper.getConnectionByVmName(vm.getName());
final Connect destinationConnection = utilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIpAddress() + "/system");
final Domain domain = sourceConnection.domainLookupByName(vm.getName());
// VIR_DOMAIN_XML_MIGRATABLE = 8
String domainXml = domain.getXMLDesc(8);
final XPath xPath = XPathFactory.newInstance().newXPath();
final XPathExpression expression = xPath.compile("/pool/target/path");
final List<VolumeObjectTO> volumes = new ArrayList<>();
for (final Pair<VolumeTO, StorageFilerTO> entry : command.getVolumeMapping()) {
final VolumeTO volumeTO = entry.first();
final StorageFilerTO storageFilerTO = entry.second();
final StoragePool sourcePool = sourceConnection.storagePoolLookupByName(volumeTO.getPoolUuid());
final String sourcePoolXml = sourcePool.getXMLDesc(0);
final StoragePool destinationPool = destinationConnection.storagePoolLookupByName(storageFilerTO.getUuid());
final String destinationPoolXml = destinationPool.getXMLDesc(0);
final String sourcePath = expression.evaluate(new InputSource(new StringReader(sourcePoolXml)));
final String sourceLocation = sourcePath + "/" + volumeTO.getPath();
final String destinationPath = expression.evaluate(new InputSource(new StringReader(destinationPoolXml)));
final String destinationLocation = destinationPath + "/" + volumeTO.getPath();
domainXml = domainXml.replace(sourceLocation, destinationLocation);
final VolumeObjectTO volumeObjectTO = new VolumeObjectTO();
volumeObjectTO.setId(volumeTO.getId());
volumeObjectTO.setPath(volumeTO.getPath());
volumes.add(volumeObjectTO);
StorageVol storageVol = null;
try {
storageVol = destinationPool.storageVolLookupByName(volumeTO.getPath());
} catch (final LibvirtException e) {
s_logger.debug("Could not find volume " + volumeTO.getPath() + ": " + e.getMessage());
}
if (storageVol == null) {
LibvirtStorageVolumeDef volumeDef = new LibvirtStorageVolumeDef(volumeTO.getPath(), volumeTO.getSize(), LibvirtStorageVolumeDef.VolumeFormat.getFormat(volumeTO.getImageFormat().name()), null, null, volumeTO.getStorageProvisioningType());
destinationPool.storageVolCreateXML(volumeDef.toString(), 0);
}
}
// VIR_MIGRATE_LIVE = 1
// VIR_MIGRATE_UNDEFINE_SOURCE = 16
// VIR_MIGRATE_NON_SHARED_DISK = 64
domain.migrate(destinationConnection, 1 | 16 | 64, domainXml, vm.getName(), null, libvirtComputingResource.getMigrateSpeedAcrossCluster());
return new MigrateWithStorageAcrossClustersAnswer(command, volumes);
} catch (final Exception e) {
s_logger.error("Migration of vm " + vm.getName() + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageAcrossClustersAnswer(command, e);
}
}
use of com.cloud.legacymodel.to.VolumeTO in project cosmic by MissionCriticalCloud.
the class AbstractHyperVisorStorageMotionStrategy method buildVolumeMapping.
protected List<Pair<VolumeTO, StorageFilerTO>> buildVolumeMapping(final Map<VolumeInfo, DataStore> volumeToPool) {
final List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<>();
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
final VolumeInfo volume = entry.getKey();
final StoragePool storagePool = storagePoolDao.findById(volume.getPoolId());
final VolumeTO volumeTo = new VolumeTO(volume.getId(), volume.getVolumeType(), storagePool.getPoolType(), storagePool.getUuid(), volume.getName(), volume.getFolder(), volume.getPath(), volume.getSize(), volume.getChainInfo(), volume.getFormat(), volume.getProvisioningType());
final StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
volumeToFilerto.add(new Pair<>(volumeTo, filerTo));
}
return volumeToFilerto;
}
Aggregations