use of org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters 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.vdscommands.GetImageInfoVDSCommandParameters in project ovirt-engine by oVirt.
the class LiveMigrateDiskCommand method updateImagesInfo.
private void updateImagesInfo() {
for (DiskImage image : diskImageDao.getAllSnapshotsForImageGroup(getParameters().getImageGroupID())) {
VDSReturnValue ret = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getTargetStorageDomainId(), getParameters().getImageGroupID(), image.getImageId()));
DiskImage imageFromIRS = (DiskImage) ret.getReturnValue();
setQcowCompatForSnapshot(image, imageFromIRS);
DiskImageDynamic diskImageDynamic = diskImageDynamicDao.get(image.getImageId());
// Update image's actual size in DB
if (imageFromIRS != null && diskImageDynamic != null) {
diskImageDynamic.setActualSize(imageFromIRS.getActualSizeInBytes());
diskImageDynamicDao.update(diskImageDynamic);
}
}
}
use of org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters in project ovirt-engine by oVirt.
the class ImagesHandler method isImageExist.
private DiskImage isImageExist(Guid storagePoolId, DiskImage image) {
DiskImage fromIrs = null;
Guid storageDomainId = image.getStorageIds().get(0);
Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
try {
fromIrs = (DiskImage) resourceManager.runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, imageGroupId, image.getImageId())).getReturnValue();
} catch (Exception e) {
log.debug("Unable to get image info from storage", e);
}
return fromIrs;
}
use of org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters in project ovirt-engine by oVirt.
the class ExtendImageSizeCommand method getImageInfo.
private DiskImage getImageInfo() {
DiskImage diskImage = null;
GetImageInfoVDSCommandParameters params = new GetImageInfoVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId(), getParameters().getImageGroupID(), getParameters().getImageId());
try {
diskImage = (DiskImage) runVdsCommand(VDSCommandType.GetImageInfo, params).getReturnValue();
} catch (EngineException e) {
log.error("Failed to retrieve image '{}' info: {}", params.getImageId(), e.getMessage());
log.debug("Exception", e);
}
return diskImage;
}
use of org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters in project ovirt-engine by oVirt.
the class ExportVmCommand method updateCopyVmInSpm.
private void updateCopyVmInSpm(Guid storagePoolId, VM vm, Guid storageDomainId) {
HashMap<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndMetaDictionary = new HashMap<>();
List<DiskImage> vmImages = new ArrayList<>();
List<LunDisk> lunDisks = new ArrayList<>();
List<VmNetworkInterface> interfaces = vm.getInterfaces();
if (interfaces != null) {
// TODO remove this when the API changes
interfaces.clear();
interfaces.addAll(vmNetworkInterfaceDao.getAllForVm(vm.getId()));
}
List<Guid> imageGroupIds = new ArrayList<>();
for (Disk disk : getDisksBasedOnImage()) {
DiskImage diskImage = (DiskImage) disk;
diskImage.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
diskImage.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
diskImage.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomainId)));
DiskImage diskForVolumeInfo = getDiskForVolumeInfo(diskImage);
diskImage.setVolumeFormat(diskForVolumeInfo.getVolumeFormat());
diskImage.setVolumeType(diskForVolumeInfo.getVolumeType());
VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, diskImage.getId(), diskImage.getImageId()));
if (vdsReturnValue != null && vdsReturnValue.getSucceeded()) {
DiskImage fromVdsm = (DiskImage) vdsReturnValue.getReturnValue();
diskImage.setActualSizeInBytes(fromVdsm.getActualSizeInBytes());
}
vmImages.add(diskImage);
imageGroupIds.add(disk.getId());
}
if (StringUtils.isEmpty(vm.getVmtName())) {
VmTemplate t = vmTemplateDao.get(vm.getVmtGuid());
vm.setVmtName(t.getName());
}
lunDisks.addAll(DisksFilter.filterLunDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE));
lunDisks.forEach(lun -> lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId()))));
getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setClusterName(vm.getClusterName());
fullEntityOvfData.setDiskImages(vmImages);
fullEntityOvfData.setLunDisks(lunDisks);
String vmMeta = ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
vmsAndMetaDictionary.put(vm.getId(), new KeyValuePairCompat<>(vmMeta, imageGroupIds));
UpdateVMVDSCommandParameters tempVar = new UpdateVMVDSCommandParameters(storagePoolId, vmsAndMetaDictionary);
tempVar.setStorageDomainId(storageDomainId);
runVdsCommand(VDSCommandType.UpdateVM, tempVar);
}
Aggregations