@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(); }
public static void fillImagesBySnapshots(VM vm) { for (Disk disk : vm.getDiskMap().values()) { if (disk.getDiskStorageType().isInternal()) { DiskImage diskImage = (DiskImage) disk; diskImage.getSnapshots().addAll(getAllImageSnapshots(diskImage.getImageId())); } } }
public static List<DiskImage> getSnapshotsDummiesForStorageAllocations( Collection<DiskImage> originalDisks) { List<DiskImage> diskDummies = new ArrayList<>(); for (DiskImage snapshot : originalDisks) { DiskImage clone = DiskImage.copyOf(snapshot); // Add the child snapshot into which the deleted snapshot is going to be merged to the // DiskImage for StorageDomainValidator to handle List<DiskImage> snapshots = DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForParent(clone.getImageId()); clone.getSnapshots().clear(); clone .getSnapshots() .add(clone); // Add the clone itself since snapshots should contain the entire chain. clone.getSnapshots().addAll(snapshots); diskDummies.add(clone); } return diskDummies; }
public static DiskImage createDiskImageWithExcessData(DiskImage diskImage, Guid sdId) { DiskImage dummy = DiskImage.copyOf(diskImage); dummy.setStorageIds(new ArrayList<>(Collections.singletonList(sdId))); dummy.getSnapshots().addAll(getAllImageSnapshots(dummy.getImageId())); return dummy; }
/** * Assert the given disk contains {@link #NUM_DISKS_OF_EACH_KIND} copies of itself as snapshot (as * should have been returned by the Dao) * * @param disk The disk to check */ private static void assertCorrectSnapshots(DiskImage disk) { for (int i = 0; i < NUM_DISKS_OF_EACH_KIND; ++i) { assertEquals( "Wrong snapshot " + i + " for disk ", disk.getId(), disk.getSnapshots().get(i).getId()); } }