Search in sources :

Example 1 with StorageFilerTO

use of com.cloud.agent.api.to.StorageFilerTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected Answer execute(CreateCommand cmd) {
    StorageFilerTO pool = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    KVMPhysicalDisk BaseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    long disksize;
    try {
        primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
        if (cmd.getTemplateUrl() != null) {
            BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
            vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), primaryPool);
            if (vol == null) {
                return new Answer(cmd, false, " Can't create storage volume on storage pool");
            }
            disksize = vol.getSize();
        } else {
            disksize = dskch.getSize();
            vol = primaryPool.createPhysicalDisk(UUID.randomUUID().toString(), dskch.getSize());
        }
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null);
        return new CreateAnswer(cmd, volume);
    } catch (CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: " + e.toString());
        return new CreateAnswer(cmd, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 2 with StorageFilerTO

use of com.cloud.agent.api.to.StorageFilerTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    boolean copyToSecondary = cmd.toSecondaryStorage();
    String volumePath = cmd.getVolumePath();
    StorageFilerTO pool = cmd.getPool();
    String secondaryStorageUrl = cmd.getSecondaryStorageURL();
    KVMStoragePool secondaryStoragePool = null;
    try {
        KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
        String volumeName = UUID.randomUUID().toString();
        if (copyToSecondary) {
            String destVolumeName = volumeName + ".qcow2";
            KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd.getVolumePath());
            String volumeDestPath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
            secondaryStoragePool.createFolder(volumeDestPath);
            secondaryStoragePool.delete();
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumeDestPath);
            _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        } else {
            volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumePath);
            KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
            _storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        }
    } catch (CloudRuntimeException e) {
        return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 3 with StorageFilerTO

use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.

the class LibvirtCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    KVMPhysicalDisk baseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    long disksize;
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid());
        disksize = dskch.getSize();
        if (command.getTemplateUrl() != null) {
            if (primaryPool.getType() == StoragePoolType.CLVM) {
                vol = libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primaryPool, dskch.getPath());
            } else {
                baseVol = primaryPool.getPhysicalDisk(command.getTemplateUrl());
                vol = storagePoolMgr.createDiskFromTemplate(baseVol, dskch.getPath(), dskch.getProvisioningType(), primaryPool, 0);
            }
            if (vol == null) {
                return new Answer(command, false, " Can't create storage volume on storage pool");
            }
        } else {
            vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getProvisioningType(), dskch.getSize());
            if (vol == null) {
                return new Answer(command, false, " Can't create Physical Disk");
            }
        }
        final VolumeTO volume = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null);
        volume.setBytesReadRate(dskch.getBytesReadRate());
        volume.setBytesWriteRate(dskch.getBytesWriteRate());
        volume.setIopsReadRate(dskch.getIopsReadRate());
        volume.setIopsWriteRate(dskch.getIopsWriteRate());
        volume.setCacheMode(dskch.getCacheMode());
        return new CreateAnswer(command, volume);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: " + e.toString());
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 4 with StorageFilerTO

use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime2.

@Test
public void testCopyVolumeCommandCloudRuntime2() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long volumeId = 1l;
    final int wait = 0;
    final String volumePath = "/vol/path";
    final boolean toSecondaryStorage = false;
    final boolean executeInSequence = false;
    final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
    final StorageFilerTO pool = command.getPool();
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("error"));
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test)

Example 5 with StorageFilerTO

use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.

the class OvmResourceBase method execute.

protected Answer execute(ModifyStoragePoolCommand cmd) {
    StorageFilerTO pool = cmd.getPool();
    try {
        if (pool.getType() == StoragePoolType.NetworkFilesystem) {
            createNfsSr(pool);
        } else if (pool.getType() == StoragePoolType.OCFS2) {
            createOCFS2Sr(pool);
        } else {
            return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
        }
        setupHeartBeat(pool.getUuid());
        OvmStoragePool.Details d = OvmStoragePool.getDetailsByUuid(_conn, pool.getUuid());
        Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
        ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, d.totalSpace, d.freeSpace, tInfo);
        return answer;
    } catch (Exception e) {
        s_logger.debug("ModifyStoragePoolCommand failed", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) FenceAnswer(com.cloud.agent.api.FenceAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) OvmStoragePool(com.cloud.ovm.object.OvmStoragePool) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)54 Answer (com.cloud.agent.api.Answer)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)27 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)21 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)20 Test (org.junit.Test)19 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)17 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)16 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)16 VolumeTO (com.cloud.agent.api.to.VolumeTO)15 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)15 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)10 DiskProfile (com.cloud.vm.DiskProfile)10 ConfigurationException (javax.naming.ConfigurationException)10 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)9 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)8 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)8 Pair (com.cloud.utils.Pair)8 Connection (com.xensource.xenapi.Connection)8 HashMap (java.util.HashMap)8