use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmTemplateFromConfigurationCommand method populateDisksCopies.
private void populateDisksCopies(List<ImageStorageDomainMap> copiedTemplateDisks, List<DiskImage> originalTemplateImages, Guid storageDomainId) {
List<Guid> imagesContainedInStorageDomain = getImagesGuidFromStorage(storageDomainId, getStoragePoolId());
for (DiskImage templateDiskImage : originalTemplateImages) {
if (storageDomainId.equals(templateDiskImage.getStorageIds().get(0))) {
// The original Storage Domain was already saved. skipping it.
continue;
}
if (imagesContainedInStorageDomain.contains(templateDiskImage.getId())) {
log.info("Found a copied image of '{}' on Storage Domain id '{}'", templateDiskImage.getId(), storageDomainId);
ImageStorageDomainMap imageStorageDomainMap = new ImageStorageDomainMap(templateDiskImage.getImageId(), storageDomainId, templateDiskImage.getQuotaId(), templateDiskImage.getDiskProfileId());
copiedTemplateDisks.add(imageStorageDomainMap);
}
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmTemplateFromConfigurationCommand method validateUnregisteredEntity.
private boolean validateUnregisteredEntity(VmTemplate entityFromConfiguration, OvfEntityData ovfEntityData) {
if (ovfEntityData == null && !getParameters().isImportAsNewEntity()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_UNSUPPORTED_OVF);
}
if (entityFromConfiguration == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_OVF_CONFIGURATION_NOT_SUPPORTED);
}
ImportValidator importValidator = new ImportValidator(getParameters());
if (!validate(importValidator.validateDiskNotAlreadyExistOnDB(getImages(), getParameters().isAllowPartialImport(), imageToDestinationDomainMap, failedDisksToImportForAuditLog))) {
return false;
}
for (DiskImage image : new ArrayList<>(getImages())) {
DiskImage fromIrs = null;
Guid storageDomainId = image.getStorageIds().get(0);
Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
try {
fromIrs = (DiskImage) runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getStoragePool().getId(), storageDomainId, imageGroupId, image.getImageId())).getReturnValue();
} catch (Exception e) {
log.debug("Unable to get image info from storage", e);
}
if (fromIrs == null) {
if (!getParameters().isAllowPartialImport()) {
return failValidation(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
}
log.warn("Disk image '{}/{}' doesn't exist on storage domain '{}'. Ignoring since force flag in on", imageGroupId, image.getImageId(), storageDomainId);
getImages().remove(image);
failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
}
}
for (DiskImage image : getImages()) {
StorageDomain sd = storageDomainDao.getForStoragePool(image.getStorageIds().get(0), getStoragePool().getId());
ValidationResult result = new StorageDomainValidator(sd).isDomainExistAndActive();
if (!result.isValid()) {
if (!getParameters().isAllowPartialImport()) {
return validate(result);
} else {
log.warn("storage domain '{}' does not exists. Ignoring since force flag in on", image.getStorageIds().get(0));
getImages().remove(image);
failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
}
}
}
if (!getStorageDomain().getStorageDomainType().isDataDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_UNSUPPORTED, String.format("$domainId %1$s", getParameters().getStorageDomainId()), String.format("$domainType %1$s", getStorageDomain().getStorageDomainType()));
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage 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;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method createMemoryDisk.
private DiskImage createMemoryDisk(Snapshot snapshot) {
StorageDomainStatic sd = validateStorageDomainExistsInDb(snapshot, memoryDiskDomainMap.get(snapshot.getMemoryDiskId()));
DiskImage disk = isMemoryDiskAlreadyExistsInDb(snapshot, snapshot.getMemoryDiskId());
if (sd == null || disk != null) {
return null;
}
VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
DiskImage memoryDisk = MemoryUtils.createSnapshotMemoryDisk(vm, sd.getStorageType(), vmOverheadCalculator, MemoryUtils.generateMemoryDiskDescription(vm, snapshot.getDescription()));
memoryDisk.setId(snapshot.getMemoryDiskId());
memoryDisk.setImageId(getMemoryDiskImageId(snapshot.getMemoryDiskId()));
memoryDisk.setStorageIds(new ArrayList<>(Collections.singletonList(sd.getId())));
memoryDisk.setStoragePoolId(getStoragePoolId());
memoryDisk.setCreationDate(snapshot.getCreationDate());
memoryDisk.setActive(true);
memoryDisk.setWipeAfterDelete(vm.getDiskList().stream().anyMatch(DiskImage::isWipeAfterDelete));
return memoryDisk;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskImage in project ovirt-engine by oVirt.
the class ImportVmCommand method createMetadataDisk.
private DiskImage createMetadataDisk(VM vm, Snapshot snapshot) {
StorageDomainStatic sd = validateStorageDomainExistsInDb(snapshot, memoryDiskDomainMap.get(snapshot.getMetadataDiskId()));
DiskImage disk = isMemoryDiskAlreadyExistsInDb(snapshot, snapshot.getMetadataDiskId());
if (sd == null || disk != null) {
return null;
}
DiskImage memoryDisk = MemoryUtils.createSnapshotMetadataDisk(MemoryUtils.generateMemoryDiskDescription(vm, snapshot.getDescription()));
memoryDisk.setId(snapshot.getMetadataDiskId());
memoryDisk.setImageId(getMemoryDiskImageId(snapshot.getMetadataDiskId()));
memoryDisk.setStorageIds(new ArrayList<>(Collections.singletonList(sd.getId())));
memoryDisk.setStoragePoolId(getStoragePoolId());
memoryDisk.setCreationDate(snapshot.getCreationDate());
memoryDisk.setActive(true);
memoryDisk.setWipeAfterDelete(vm.getDiskList().stream().anyMatch(DiskImage::isWipeAfterDelete));
return memoryDisk;
}
Aggregations