Search in sources :

Example 1 with CreateAnswer

use of com.cloud.agent.api.storage.CreateAnswer 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 CreateAnswer

use of com.cloud.agent.api.storage.CreateAnswer 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 3 with CreateAnswer

use of com.cloud.agent.api.storage.CreateAnswer in project cloudstack by apache.

the class CitrixCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    VDI vdi = null;
    try {
        final SR poolSr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
        if (command.getTemplateUrl() != null) {
            VDI tmpltvdi = null;
            tmpltvdi = citrixResourceBase.getVDIbyUuid(conn, command.getTemplateUrl());
            vdi = tmpltvdi.createClone(conn, new HashMap<String, String>());
            vdi.setNameLabel(conn, dskch.getName());
        } else {
            final VDI.Record vdir = new VDI.Record();
            vdir.nameLabel = dskch.getName();
            vdir.SR = poolSr;
            vdir.type = Types.VdiType.USER;
            vdir.virtualSize = dskch.getSize();
            vdi = VDI.create(conn, vdir);
        }
        VDI.Record vdir;
        vdir = vdi.getRecord(conn);
        s_logger.debug("Succesfully created VDI for " + command + ".  Uuid = " + vdir.uuid);
        final VolumeTO vol = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
        return new CreateAnswer(command, vol);
    } catch (final Exception e) {
        s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) SR(com.xensource.xenapi.SR)

Example 4 with CreateAnswer

use of com.cloud.agent.api.storage.CreateAnswer in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method createVolume.

@Override
public CreateAnswer createVolume(CreateCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
    if (storagePool == null) {
        return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
    }
    String volumeName = UUID.randomUUID().toString();
    MockVolumeVO volume = new MockVolumeVO();
    volume.setPoolId(storagePool.getId());
    volume.setName(volumeName);
    volume.setPath(storagePool.getMountPoint() + volumeName);
    volume.setSize(dskch.getSize());
    volume.setType(MockVolumeType.VOLUME);
    volume = _mockVolumeDao.persist(volume);
    VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(), volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);
    return new CreateAnswer(cmd, volumeTo);
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 5 with CreateAnswer

use of com.cloud.agent.api.storage.CreateAnswer in project cloudstack by apache.

the class HypervDirectConnectResourceTest method testCreateCommand.

@Test
public final void testCreateCommand() {
    String sample = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + s_testLocalStoreUUID + "\",\"host\":\"10.70.176.29\"" + ",\"path\":" + s_testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"}," + "\"diskCharacteristics\":{\"size\":0," + "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\"," + "\"useLocalStorage\":true,\"recreatable\":true," + "\"diskOfferingId\":11," + "\"volumeId\":10,\"hyperType\":\"Hyperv\"}," + "\"templateUrl\":" + s_testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}";
    File destDir = new File(s_testLocalStorePath);
    Assert.assertTrue(destDir.isDirectory());
    File testSampleTemplateURLFile = new File(s_testLocalStorePath + File.separator + s_gson.fromJson(s_testSampleTemplateURLJSON, String.class));
    Assert.assertTrue("The template that create should make" + " volumes from is missing from path " + testSampleTemplateURLFile.getPath(), testSampleTemplateURLFile.exists());
    int fileCount = destDir.listFiles().length;
    s_logger.debug(" test local store has " + fileCount + "files");
    // Test requires there to be a template at the tempalteUrl, which is its
    // location in the local file system.
    CreateCommand cmd = s_gson.fromJson(sample, CreateCommand.class);
    CreateAnswer ans = (CreateAnswer) s_hypervresource.executeRequest(cmd);
    Assert.assertTrue(ans.getDetails(), ans.getResult());
    Assert.assertTrue("CreateCommand should add a file to the folder", fileCount + 1 == destDir.listFiles().length);
    File newFile = new File(ans.getVolume().getPath());
    Assert.assertTrue("The new file should have a size greater than zero", newFile.length() > 0);
    newFile.delete();
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) CreateCommand(com.cloud.agent.api.storage.CreateCommand) File(java.io.File) Test(org.junit.Test)

Aggregations

CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)8 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)7 VolumeTO (com.cloud.agent.api.to.VolumeTO)7 DiskProfile (com.cloud.vm.DiskProfile)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 URISyntaxException (java.net.URISyntaxException)3 Answer (com.cloud.agent.api.Answer)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 MockVolumeVO (com.cloud.simulator.MockVolumeVO)2 ConfigurationException (javax.naming.ConfigurationException)2 AttachVolumeAnswer (com.cloud.agent.api.AttachVolumeAnswer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)1 DeleteSnapshotBackupAnswer (com.cloud.agent.api.DeleteSnapshotBackupAnswer)1 FenceAnswer (com.cloud.agent.api.FenceAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1