use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method findDomainForMemoryImagesAndCreateDummies.
private StorageDomain findDomainForMemoryImagesAndCreateDummies(List<DiskImage> disksList) {
List<DiskImage> memoryDisksList = MemoryUtils.createDiskDummies(vmOverheadCalculator.getSnapshotMemorySizeInBytes(getVm()), MemoryUtils.METADATA_SIZE_IN_BYTES);
StorageDomain storageDomain = memoryStorageHandler.findStorageDomainForMemory(getParameters().getStoragePoolId(), memoryDisksList, getVmDisksDummies(), getVm());
disksList.addAll(memoryDisksList);
return storageDomain;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method moveOrCopyAllImageGroups.
protected void moveOrCopyAllImageGroups(Guid containerID, Iterable<DiskImage> disks) {
for (DiskImage disk : disks) {
ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForDisk(disk, containerID));
if (!vdcRetValue.getSucceeded()) {
throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy disk!");
}
// TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method getVmDisksDummies.
private Collection<DiskImage> getVmDisksDummies() {
Collection<DiskImage> disksDummies = new LinkedList<>();
for (Guid storageDomainId : getParameters().getImageToDestinationDomainMap().values()) {
DiskImage diskImage = new DiskImage();
diskImage.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));
disksDummies.add(diskImage);
}
return disksDummies;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method validateImages.
protected boolean validateImages(Map<Guid, StorageDomain> domainsMap) {
List<String> validationMessages = getReturnValue().getValidationMessages();
// Iterate over all the VM images (active image and snapshots)
for (DiskImage image : getImages()) {
if (Guid.Empty.equals(image.getVmSnapshotId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
if (getParameters().getCopyCollapse()) {
// a match with the image from the VM.
for (DiskImage p : imageList) {
// only if requested by the user
if (p.getImageId().equals(image.getImageId())) {
if (p.getVolumeFormat() != null) {
image.setVolumeFormat(p.getVolumeFormat());
}
if (p.getVolumeType() != null) {
image.setVolumeType(p.getVolumeType());
}
// Validate the configuration of the image got from the parameters.
if (!validateImageConfig(validationMessages, domainsMap, image)) {
return false;
}
break;
}
}
}
image.setStoragePoolId(getParameters().getStoragePoolId());
// we put the source domain id in order that copy will
// work properly.
// we fix it to DestDomainId in
// MoveOrCopyAllImageGroups();
image.setStorageIds(new ArrayList<>(Arrays.asList(getSourceDomainId(image))));
}
Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(getImages());
images.entrySet().stream().forEach(e -> getVm().getDiskMap().put(e.getKey(), getActiveVolumeDisk(e.getValue())));
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method addVmImagesAndSnapshots.
protected void addVmImagesAndSnapshots() {
Map<Guid, List<DiskImage>> images = ImagesHandler.getImagesLeaf(getImages());
if (isCopyCollapseOrNoSnapshots()) {
Guid snapshotId = Guid.newGuid();
int aliasCounter = 0;
for (List<DiskImage> diskList : images.values()) {
DiskImage disk = getActiveVolumeDisk(diskList);
disk.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
disk.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
disk.setVmSnapshotId(snapshotId);
disk.setActive(true);
if (getParameters().getVm().getDiskMap() != null && getParameters().getVm().getDiskMap().containsKey(disk.getId())) {
DiskImageBase diskImageBase = (DiskImageBase) getParameters().getVm().getDiskMap().get(disk.getId());
disk.setVolumeFormat(diskImageBase.getVolumeFormat());
disk.setVolumeType(diskImageBase.getVolumeType());
}
setDiskStorageDomainInfo(disk);
if (getParameters().isImportAsNewEntity()) {
generateNewDiskId(diskList, disk);
updateManagedDeviceMap(disk, getVm().getStaticData().getManagedDeviceMap());
} else {
newDiskIdForDisk.put(disk.getId(), disk);
}
disk.setCreationDate(new Date());
saveImage(disk);
ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
saveBaseDisk(disk);
saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
saveDiskImageDynamic(disk);
}
Snapshot snapshot = addActiveSnapshot(snapshotId);
getVm().setSnapshots(Arrays.asList(snapshot));
} else {
Guid snapshotId = null;
for (DiskImage disk : getImages()) {
disk.setActive(false);
setDiskStorageDomainInfo(disk);
saveImage(disk);
snapshotId = disk.getVmSnapshotId();
saveSnapshotIfNotExists(snapshotId, disk);
saveDiskImageDynamic(disk);
}
int aliasCounter = 0;
for (List<DiskImage> diskList : images.values()) {
DiskImage disk = getActiveVolumeDisk(diskList);
newDiskIdForDisk.put(disk.getId(), disk);
snapshotId = disk.getVmSnapshotId();
disk.setActive(true);
ImagesHandler.setDiskAlias(disk, getVm(), ++aliasCounter);
updateImage(disk);
saveBaseDisk(disk);
saveDiskVmElement(disk.getId(), getVmId(), disk.getDiskVmElementForVm(getParameters().getVmId()));
}
// Update active snapshot's data, since it was inserted as a regular snapshot.
updateActiveSnapshot(snapshotId);
}
}
Aggregations