Search in sources :

Example 6 with CreateAnswer

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

the class OvmResourceBase method execute.

protected CreateAnswer execute(CreateCommand cmd) {
    StorageFilerTO primaryStorage = cmd.getPool();
    DiskProfile disk = cmd.getDiskCharacteristics();
    try {
        OvmVolume.Details vol = null;
        if (cmd.getTemplateUrl() != null) {
            vol = OvmVolume.createFromTemplate(_conn, primaryStorage.getUuid(), cmd.getTemplateUrl());
        } else {
            vol = OvmVolume.createDataDsik(_conn, primaryStorage.getUuid(), Long.toString(disk.getSize()), disk.getType() == Volume.Type.ROOT);
        }
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), vol.name, vol.path, vol.size, null);
        return new CreateAnswer(cmd, volume);
    } catch (Exception e) {
        s_logger.debug("CreateCommand failed", e);
        return new CreateAnswer(cmd, e.getMessage());
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) OvmVolume(com.cloud.ovm.object.OvmVolume)

Example 7 with CreateAnswer

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

the class MockStorageManagerImpl method createVolume.

@Override
public CreateAnswer createVolume(CreateCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    MockStoragePoolVO storagePool = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
        txn.commit();
        if (storagePool == null) {
            return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    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);
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        volume = _mockVolumeDao.persist(volume);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when saving volume " + volume, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    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) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with CreateAnswer

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

the class Ovm3StorageProcessor method execute.

public CreateAnswer execute(CreateCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    StorageFilerTO primaryStorage = cmd.getPool();
    DiskProfile disk = cmd.getDiskCharacteristics();
    /* disk should have a uuid */
    // should also be replaced with getVirtualDiskPath ?
    String fileName = UUID.randomUUID().toString() + ".raw";
    String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
    try {
        StoragePlugin store = new StoragePlugin(c);
        if (cmd.getTemplateUrl() != null) {
            LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
            Linux host = new Linux(c);
            host.copyFile(cmd.getTemplateUrl(), dst);
        } else {
            /* this is a dup with the createVolume ? */
            LOGGER.debug("CreateCommand " + dst);
            store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
        }
        FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
        VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
        return new CreateAnswer(cmd, volume);
    } catch (Exception e) {
        LOGGER.debug("CreateCommand failed", e);
        return new CreateAnswer(cmd, e.getMessage());
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) VolumeTO(com.cloud.agent.api.to.VolumeTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

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