Search in sources :

Example 1 with CreateAnswer

use of com.cloud.legacymodel.communication.answer.CreateAnswer in project cosmic by MissionCriticalCloud.

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<>());
            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);
        }
        final 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, null, 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.legacymodel.communication.answer.CreateAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) SR(com.xensource.xenapi.SR)

Example 2 with CreateAnswer

use of com.cloud.legacymodel.communication.answer.CreateAnswer in project cosmic by MissionCriticalCloud.

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;
    final 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 if (primaryPool.getType() == StoragePoolType.LVM) {
                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, null, null);
        volume.setBytesReadRate(dskch.getBytesReadRate());
        volume.setBytesWriteRate(dskch.getBytesWriteRate());
        volume.setIopsReadRate(dskch.getIopsReadRate());
        volume.setIopsWriteRate(dskch.getIopsWriteRate());
        volume.setIopsTotalRate(dskch.getIopsTotalRate());
        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.legacymodel.communication.answer.CreateAnswer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) 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) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile)

Aggregations

CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)2 DiskProfile (com.cloud.legacymodel.storage.DiskProfile)2 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)2 VolumeTO (com.cloud.legacymodel.to.VolumeTO)2 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)1 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 Connection (com.xensource.xenapi.Connection)1 SR (com.xensource.xenapi.SR)1 VDI (com.xensource.xenapi.VDI)1 HashMap (java.util.HashMap)1