Search in sources :

Example 26 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testDeleteVMSnapshotCommand.

@Test
public void testDeleteVMSnapshotCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final VMSnapshotTO snapshotTO = Mockito.mock(VMSnapshotTO.class);
    final List<VolumeObjectTO> volumeTOs = new ArrayList<>();
    final DeleteVMSnapshotCommand vmSnapshot = new DeleteVMSnapshotCommand("Test", snapshotTO, volumeTOs, "Debian");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(vmSnapshot, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class KvmStoragePoolManager method disconnectPhysicalDisksViaVmSpec.

public boolean disconnectPhysicalDisksViaVmSpec(final VirtualMachineTO vmSpec) {
    if (vmSpec == null) {
        /*
       * CloudStack often tries to stop VMs that shouldn't be running, to ensure a known state, for example if we lose
       * communication with the agent and the VM is brought up elsewhere. We may not know about these yet. This might
       * mean that we can't use the vmspec map, because when we restart the agent we lose all of the info about running
       * VMs.
       */
        s_logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map");
        return true;
    }
    boolean result = true;
    final String vmName = vmSpec.getName();
    final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
    for (final DiskTO disk : disks) {
        if (disk.getType() != Volume.Type.ISO) {
            s_logger.debug("Disconnecting disk " + disk.getPath());
            final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) vol.getDataStore();
            final KvmStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid());
            if (pool == null) {
                s_logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic");
                continue;
            }
            final StorageAdaptor adaptor = getStorageAdaptor(pool.getType());
            // if a disk fails to disconnect, still try to disconnect remaining
            final boolean subResult = adaptor.disconnectPhysicalDisk(vol.getPath(), pool);
            if (!subResult) {
                s_logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString());
                result = false;
            }
        }
    }
    return result;
}
Also used : PrimaryDataStoreTO(com.cloud.storage.to.PrimaryDataStoreTO) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 28 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method createVolume.

@Override
public Answer createVolume(final CreateObjectCommand cmd) {
    final VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    KvmStoragePool primaryPool = null;
    KvmPhysicalDisk vol = null;
    final long disksize;
    try {
        primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        disksize = volume.getSize();
        final PhysicalDiskFormat format;
        if (volume.getFormat() == null) {
            format = primaryPool.getDefaultFormat();
        } else {
            format = PhysicalDiskFormat.valueOf(volume.getFormat().toString().toUpperCase());
        }
        vol = primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), disksize);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        if (vol != null) {
            newVol.setPath(vol.getName());
        }
        newVol.setSize(volume.getSize());
        newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
        return new CreateObjectAnswer(newVol);
    } catch (final Exception e) {
        logger.debug("Failed to create volume: ", e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(com.cloud.storage.to.PrimaryDataStoreTO) CreateObjectAnswer(com.cloud.storage.command.CreateObjectAnswer) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) QemuImgException(com.cloud.utils.qemu.QemuImgException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) PhysicalDiskFormat(com.cloud.utils.qemu.QemuImg.PhysicalDiskFormat)

Example 29 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method dettachVolume.

@Override
public Answer dettachVolume(final DettachCommand cmd) {
    final DiskTO disk = cmd.getDisk();
    final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore();
    final String vmName = cmd.getVmName();
    final String serial = resource.diskUuidToSerial(vol.getUuid());
    try {
        final Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
        final KvmPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
        attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue(), serial);
        storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
        return new DettachAnswer(disk);
    } catch (final LibvirtException e) {
        logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
        return new DettachAnswer(e.toString());
    } catch (final InternalErrorException e) {
        logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
        return new DettachAnswer(e.toString());
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) PrimaryDataStoreTO(com.cloud.storage.to.PrimaryDataStoreTO) DettachAnswer(com.cloud.storage.command.DettachAnswer) Connect(org.libvirt.Connect) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) InternalErrorException(com.cloud.exception.InternalErrorException) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 30 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method cloneVolumeFromBaseTemplate.

@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final TemplateObjectTO template = (TemplateObjectTO) srcData;
    final DataStoreTO imageStore = template.getDataStore();
    final VolumeObjectTO volume = (VolumeObjectTO) destData;
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    KvmPhysicalDisk baseVolume;
    KvmStoragePool primaryPool;
    KvmPhysicalDisk vol;
    try {
        primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        String templatePath = template.getPath();
        if (primaryPool.getType() == StoragePoolType.CLVM) {
            templatePath = imageStore.getUrl() + File.separator + templatePath;
            vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds());
        } else {
            if (templatePath.contains("/mnt")) {
                // upgrade issue, if the path contains path, need to extract the volume uuid from path
                templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
            }
            baseVolume = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
            vol = storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds());
        }
        if (vol == null) {
            return new CopyCmdAnswer(" Can't create storage volume on storage pool");
        }
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(vol.getName());
        newVol.setSize(volume.getSize());
        if (vol.getFormat() == PhysicalDiskFormat.RAW) {
            newVol.setFormat(ImageFormat.RAW);
        } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
            newVol.setFormat(ImageFormat.QCOW2);
        } else if (vol.getFormat() == PhysicalDiskFormat.DIR) {
            newVol.setFormat(ImageFormat.DIR);
        }
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        logger.debug("Failed to create volume: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(com.cloud.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(com.cloud.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Aggregations

VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)58 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)36 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)22 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)21 Connection (com.xensource.xenapi.Connection)19 InternalErrorException (com.cloud.exception.InternalErrorException)18 VDI (com.xensource.xenapi.VDI)17 NfsTO (com.cloud.agent.api.to.NfsTO)16 DataTO (com.cloud.agent.api.to.DataTO)15 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)14 ArrayList (java.util.ArrayList)14 SR (com.xensource.xenapi.SR)13 XenAPIException (com.xensource.xenapi.Types.XenAPIException)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)13 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)10 IOException (java.io.IOException)10 LibvirtException (org.libvirt.LibvirtException)10 VolumeVO (com.cloud.storage.VolumeVO)9 URI (java.net.URI)9 HashMap (java.util.HashMap)8