use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreateCommand.
@Test
public void testCreateCommand() {
final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final String templateUrl = "http://template";
final boolean executeInSequence = false;
final CreateCommand command = new CreateCommand(diskCharacteristics, templateUrl, pool, executeInSequence);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.getType()).thenReturn(StoragePoolType.CLVM);
when(this.libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.legacymodel.storage.DiskProfile 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);
}
}
use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testExecuteCreateCommand.
@Test
public void testExecuteCreateCommand() {
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final DiskProfile diskProfile = Mockito.mock(DiskProfile.class);
final CreateCommand createCommand = new CreateCommand(diskProfile, "", poolVO, false);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(createCommand, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method moveVolume.
@Override
public VolumeInfo moveVolume(final VolumeInfo volume, final long destPoolDcId, final Long destPoolPodId, final Long destPoolClusterId, final HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException {
// Find a destination storage pool with the specified criteria
final DiskOffering diskOffering = this._entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
final DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
dskCh.setHyperType(dataDiskHyperType);
final DataCenter destPoolDataCenter = this._entityMgr.findById(DataCenter.class, destPoolDcId);
final Pod destPoolPod = this._entityMgr.findById(Pod.class, destPoolPodId);
final StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<>());
if (destPool == null) {
throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to.");
}
final Volume newVol = migrateVolume(volume, destPool);
return this.volFactory.getVolume(newVol.getId());
}
use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method hasSuitablePoolsForVolume.
private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) {
final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
final ExcludeList avoid = new ExcludeList();
for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
if (poolList != null && !poolList.isEmpty()) {
return true;
}
}
return false;
}
Aggregations