Search in sources :

Example 1 with VolumeTO

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());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)

Example 2 with VolumeTO

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) Volume(com.cloud.legacymodel.storage.Volume) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Test(org.junit.Test)

Example 3 with VolumeTO

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) Volume(com.cloud.legacymodel.storage.Volume) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Test(org.junit.Test)

Example 4 with VolumeTO

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) InputSource(org.xml.sax.InputSource) StoragePool(org.libvirt.StoragePool) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) LibvirtStorageVolumeDef(com.cloud.agent.resource.kvm.xml.LibvirtStorageVolumeDef) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) LibvirtException(org.libvirt.LibvirtException) VolumeTO(com.cloud.legacymodel.to.VolumeTO) MigrateWithStorageAcrossClustersAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageAcrossClustersAnswer) StringReader(java.io.StringReader) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) Domain(org.libvirt.Domain)

Example 5 with VolumeTO

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;
}
Also used : VolumeTO(com.cloud.legacymodel.to.VolumeTO) StoragePool(com.cloud.legacymodel.storage.StoragePool) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

VolumeTO (com.cloud.legacymodel.to.VolumeTO)16 Answer (com.cloud.legacymodel.communication.answer.Answer)10 Connection (com.xensource.xenapi.Connection)10 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)9 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)8 Pair (com.cloud.legacymodel.utils.Pair)8 SR (com.xensource.xenapi.SR)8 HashMap (java.util.HashMap)8 NicTO (com.cloud.legacymodel.to.NicTO)7 VDI (com.xensource.xenapi.VDI)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Network (com.xensource.xenapi.Network)6 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)4 MigrateWithStorageSendCommand (com.cloud.legacymodel.communication.command.MigrateWithStorageSendCommand)3 StoragePool (com.cloud.legacymodel.storage.StoragePool)3