Search in sources :

Example 1 with QuotaStorageConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter in project ovirt-engine by oVirt.

the class ImportVmCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    for (Disk disk : getParameters().getVm().getDiskMap().values()) {
        // TODO: handle import more than once;
        if (disk instanceof DiskImage) {
            DiskImage diskImage = (DiskImage) disk;
            list.add(new QuotaStorageConsumptionParameter(diskImage.getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.CONSUME, imageToDestinationDomainMap.get(diskImage.getId()), (double) diskImage.getSizeInGigabytes()));
        }
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 2 with QuotaStorageConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter in project ovirt-engine by oVirt.

the class RemoveVmTemplateCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    getImageTemplates();
    if (imageTemplates != null) {
        for (DiskImage disk : imageTemplates) {
            if (disk.getQuotaId() != null && !Guid.Empty.equals(disk.getQuotaId())) {
                for (Guid storageId : disk.getStorageIds()) {
                    list.add(new QuotaStorageConsumptionParameter(disk.getQuotaId(), null, QuotaStorageConsumptionParameter.QuotaAction.RELEASE, storageId, (double) disk.getSizeInGigabytes()));
                }
            }
        }
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 3 with QuotaStorageConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter in project ovirt-engine by oVirt.

the class RemoveVmCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    if (getParameters().isRemoveDisks()) {
        List<QuotaConsumptionParameter> list = new ArrayList<>();
        imagesHandler.fillImagesBySnapshots(getVm());
        for (DiskImage disk : getVm().getDiskList()) {
            for (DiskImage snapshot : disk.getSnapshots()) {
                if (snapshot.getQuotaId() != null && !Guid.Empty.equals(snapshot.getQuotaId())) {
                    if (snapshot.getActive()) {
                        list.add(new QuotaStorageConsumptionParameter(snapshot.getQuotaId(), null, QuotaStorageConsumptionParameter.QuotaAction.RELEASE, disk.getStorageIds().get(0), (double) snapshot.getSizeInGigabytes()));
                    } else {
                        list.add(new QuotaStorageConsumptionParameter(snapshot.getQuotaId(), null, QuotaStorageConsumptionParameter.QuotaAction.RELEASE, disk.getStorageIds().get(0), snapshot.getActualSize()));
                    }
                }
            }
        }
        return list;
    }
    return Collections.emptyList();
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 4 with QuotaStorageConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter in project ovirt-engine by oVirt.

the class RestoreAllSnapshotsCommand method getQuotaStorageConsumptionParameters.

@Override
public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    List<DiskImage> disks = getImagesList();
    if (disks != null && !disks.isEmpty()) {
        // TODO: need to be fixed. sp id should be available
        setStoragePoolId(disks.get(0).getStoragePoolId());
        for (DiskImage image : disks) {
            if (!image.getImage().isActive() && image.getQuotaId() != null && !Guid.Empty.equals(image.getQuotaId())) {
                list.add(new QuotaStorageConsumptionParameter(image.getQuotaId(), null, QuotaConsumptionParameter.QuotaAction.RELEASE, image.getStorageIds().get(0), image.getActualSize()));
            }
        }
    }
    return list;
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) ArrayList(java.util.ArrayList) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with QuotaStorageConsumptionParameter

use of org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter in project ovirt-engine by oVirt.

the class UpdateVmDiskCommandTest method testExtendingDiskWithQuota.

@Test
public void testExtendingDiskWithQuota() {
    Guid quotaId = Guid.newGuid();
    DiskImage oldDiskImage = createDiskImage();
    oldDiskImage.setQuotaId(quotaId);
    oldDiskImage.setSize(SizeConverter.convert(3L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    DiskImage newDiskImage = createDiskImage();
    newDiskImage.setQuotaId(quotaId);
    newDiskImage.setSize(SizeConverter.convert(5L, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());
    command.getParameters().setDiskVmElement(new DiskVmElement(newDiskImage.getId(), vmId));
    command.getParameters().setDiskInfo(newDiskImage);
    long diskExtendingDiffInGB = newDiskImage.getSizeInGigabytes() - oldDiskImage.getSizeInGigabytes();
    when(diskDao.get(diskImageGuid)).thenReturn(oldDiskImage);
    initializeCommand();
    QuotaStorageConsumptionParameter consumptionParameter = (QuotaStorageConsumptionParameter) command.getQuotaStorageConsumptionParameters().get(0);
    assertEquals(consumptionParameter.getRequestedStorageGB().longValue(), diskExtendingDiffInGB);
}
Also used : QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

QuotaStorageConsumptionParameter (org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter)10 ArrayList (java.util.ArrayList)9 QuotaConsumptionParameter (org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)7 Guid (org.ovirt.engine.core.compat.Guid)2 Test (org.junit.Test)1 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)1 AddDiskParameters (org.ovirt.engine.core.common.action.AddDiskParameters)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1