use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class ImportVmFromConfigurationCommand method attemptToAttachDisksToImportedVm.
private AuditLogType attemptToAttachDisksToImportedVm(Collection<Disk> disks) {
List<String> failedDisks = new LinkedList<>();
for (Disk disk : disks) {
DiskVmElement dve = disk.getDiskVmElements().iterator().next();
AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve, dve.isPlugged());
ActionReturnValue returnVal = runInternalAction(ActionType.AttachDiskToVm, params, cloneContextAndDetachFromParent());
if (!returnVal.getSucceeded()) {
failedDisks.add(disk.getDiskAlias());
}
}
if (!failedDisks.isEmpty()) {
this.addCustomValue("DiskAliases", StringUtils.join(failedDisks, ","));
return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_ATTACH_DISKS_FAILED;
}
return AuditLogType.VM_IMPORT_FROM_CONFIGURATION_EXECUTED_SUCCESSFULLY;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class ImportVmTemplateCommand method addVmTemplateToDb.
protected void addVmTemplateToDb() {
getVmTemplate().setClusterId(getParameters().getClusterId());
// if "run on host" field points to a non existent vds (in the current cluster) -> remove field and continue
if (!vmHandler.validateDedicatedVdsExistOnSameCluster(getVmTemplate()).isValid()) {
getVmTemplate().setDedicatedVmForVdsList(Collections.emptyList());
}
getVmTemplate().setStatus(VmTemplateStatus.Locked);
getVmTemplate().setQuotaId(getParameters().getQuotaId());
vmHandler.autoSelectResumeBehavior(getVmTemplate(), getCluster());
vmTemplateDao.save(getVmTemplate());
getCompensationContext().snapshotNewEntity(getVmTemplate());
int count = 1;
for (DiskImage image : getImages()) {
image.setActive(true);
ImageStorageDomainMap map = imagesHandler.saveImage(image);
getCompensationContext().snapshotNewEntity(image.getImage());
getCompensationContext().snapshotNewEntity(map);
if (!baseDiskDao.exists(image.getId())) {
image.setDiskAlias(ImagesHandler.getSuggestedDiskAlias(image, getVmTemplateName(), count));
count++;
baseDiskDao.save(image);
getCompensationContext().snapshotNewEntity(image);
}
DiskImageDynamic diskDynamic = new DiskImageDynamic();
diskDynamic.setId(image.getImageId());
diskDynamic.setActualSize(image.getActualSizeInBytes());
diskImageDynamicDao.save(diskDynamic);
DiskVmElement dve = DiskVmElement.copyOf(image.getDiskVmElementForVm(sourceTemplateId), image.getId(), getVmTemplateId());
diskVmElementDao.save(dve);
getCompensationContext().snapshotNewEntity(diskDynamic);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AddVmCommand method createAndSaveNewDiskVmElement.
private void createAndSaveNewDiskVmElement(Guid newDiskImageId, Guid newVmId, DiskVmElement oldDve) {
DiskVmElement newDve = DiskVmElement.copyOf(oldDve, newDiskImageId, newVmId);
diskVmElementDao.save(newDve);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method isPassDiscardSupportedForImagesDestSds.
protected ValidationResult isPassDiscardSupportedForImagesDestSds() {
Map<Disk, DiskVmElement> diskToDiskVmElement = diskHandler.getDiskToDiskVmElementMap(getVm().getId(), diskInfoDestinationMap);
Map<Guid, Guid> diskIdToDestSdId = diskInfoDestinationMap.values().stream().collect(Collectors.toMap(DiskImage::getId, diskImage -> diskImage.getStorageIds().get(0)));
MultipleDiskVmElementValidator multipleDiskVmElementValidator = createMultipleDiskVmElementValidator(diskToDiskVmElement);
return multipleDiskVmElementValidator.isPassDiscardSupportedForDestSds(diskIdToDestSdId);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method addTemplateDiskVmElement.
private void addTemplateDiskVmElement(Guid newDiskId, Guid oldDiskId) {
DiskVmElement oldDve = diskVmElementDao.get(new VmDeviceId(oldDiskId, getVmId()));
DiskVmElement newDve = DiskVmElement.copyOf(oldDve);
newDve.setId(new VmDeviceId(newDiskId, getVmTemplateId()));
diskVmElementDao.save(newDve);
}
Aggregations