use of org.ovirt.engine.core.common.businessentities.storage.BaseDisk in project ovirt-engine by oVirt.
the class ImportHostedEngineStorageDomainCommand method removeHostedEngineLunDisk.
private void removeHostedEngineLunDisk() {
List<BaseDisk> disks = baseDiskDao.getDisksByAlias(StorageConstants.HOSTED_ENGINE_LUN_DISK_ALIAS);
if (disks != null && !disks.isEmpty()) {
BaseDisk heDirectLun = disks.get(0);
ActionReturnValue removeDisk = backend.runInternalAction(ActionType.RemoveDisk, new RemoveDiskParameters(heDirectLun.getId()));
if (!removeDisk.getSucceeded()) {
setSucceeded(false);
log.error("Failed to remove the hosted engine direct lun disk");
return;
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.storage.BaseDisk in project ovirt-engine by oVirt.
the class CreateSnapshotForVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
return false;
}
if (!canRunActionOnNonManagedVm()) {
return false;
}
Set<Guid> specifiedDiskIds = getParameters().getDiskIds();
if (specifiedDiskIds != null && !specifiedDiskIds.isEmpty()) {
if (!isSpecifiedDisksExist(specifiedDiskIds)) {
return false;
}
List<Disk> allDisksForVm = diskDao.getAllForVm(getVm().getId());
String notAllowSnapshot = allDisksForVm.stream().filter(disk -> specifiedDiskIds.contains(disk.getId())).filter(disk -> !disk.isAllowSnapshot()).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
if (!notAllowSnapshot.isEmpty()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_SNAPSHOT_NOT_SUPPORTED, String.format("$diskAliases %s", notAllowSnapshot));
}
Set<Guid> guidsOfVmDisks = allDisksForVm.stream().map(BaseDisk::getId).collect(Collectors.toSet());
String notAttachedToVm = specifiedDiskIds.stream().filter(guid -> !guidsOfVmDisks.contains(guid)).map(guid -> diskDao.get(guid)).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
if (!notAttachedToVm.isEmpty()) {
String[] replacements = { ReplacementUtils.createSetVariableString("VmName", getVm().getName()), ReplacementUtils.createSetVariableString("diskAliases", notAttachedToVm) };
return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISKS_NOT_ATTACHED_TO_VM, replacements);
}
}
// Initialize validators.
VmValidator vmValidator = createVmValidator();
StoragePoolValidator spValidator = createStoragePoolValidator();
if (!(validateVM(vmValidator) && validate(spValidator.existsAndUp()) && validate(vmValidator.vmNotIlegal()) && validate(vmValidator.vmNotLocked()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(vmValidator.vmNotDuringMigration()) && validate(vmValidator.vmNotRunningStateless()) && (!getParameters().isSaveMemory() || validate(vmValidator.vmNotHavingPciPassthroughDevices())))) {
return false;
}
List<DiskImage> disksList = getDisksListForChecks();
if (disksList.size() > 0) {
DiskImagesValidator diskImagesValidator = createDiskImageValidator(disksList);
if (!(validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(vmValidator.vmWithoutLocalDiskUserProperty()))) {
return false;
}
}
return validateStorage();
}
use of org.ovirt.engine.core.common.businessentities.storage.BaseDisk in project ovirt-engine by oVirt.
the class MultipleVmsValidator method vmNotHavingPluggedDiskSnapshots.
/**
* @return ValidationResult indicating whether there are plugged disk snapshots
*/
public ValidationResult vmNotHavingPluggedDiskSnapshots(EngineMessage message) {
List<String> vmPluggedDiskSnapshotsInfo = null;
for (VM vm : vms) {
List<DiskImage> pluggedDiskSnapshots = DbFacade.getInstance().getDiskImageDao().getAttachedDiskSnapshotsToVm(vm.getId(), Boolean.TRUE);
if (!pluggedDiskSnapshots.isEmpty()) {
if (vmPluggedDiskSnapshotsInfo == null) {
vmPluggedDiskSnapshotsInfo = new LinkedList<>();
}
List<String> pluggedDiskSnapshotAliases = new LinkedList<>();
for (BaseDisk disk : pluggedDiskSnapshots) {
pluggedDiskSnapshotAliases.add(disk.getDiskAlias());
}
vmPluggedDiskSnapshotsInfo.add(String.format("%s / %s", vm.getName(), StringUtils.join(pluggedDiskSnapshotAliases, ",")));
}
}
if (vmPluggedDiskSnapshotsInfo != null) {
return new ValidationResult(message, String.format("$disksInfo %s", String.format(StringUtils.join(vmPluggedDiskSnapshotsInfo, "%n"))));
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.storage.BaseDisk in project ovirt-engine by oVirt.
the class RunVmValidator method validateIsoPath.
protected ValidationResult validateIsoPath(VM vm, String diskPath, String floppyPath, Guid activeIsoDomainId) {
if (vm.isAutoStartup()) {
return ValidationResult.VALID;
}
if (StringUtils.isEmpty(vm.getIsoPath()) && StringUtils.isEmpty(diskPath) && StringUtils.isEmpty(floppyPath)) {
return ValidationResult.VALID;
}
if (!StringUtils.isEmpty(floppyPath) && activeIsoDomainId == null) {
return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
}
String effectiveIsoPath = StringUtils.isEmpty(diskPath) ? vm.getIsoPath() : diskPath;
if (!StringUtils.isEmpty(effectiveIsoPath)) {
if (effectiveIsoPath.matches(ValidationUtils.GUID)) {
BaseDisk disk = diskDao.get(Guid.createGuidFromString(effectiveIsoPath));
if (disk == null || disk.getContentType() != DiskContentType.ISO) {
return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_ISO_IMAGE_PATH);
}
Guid domainId = ((DiskImage) disk).getStorageIds().get(0);
StoragePoolIsoMap spim = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(domainId, vm.getStoragePoolId()));
if (spim == null || spim.getStatus() != StorageDomainStatus.Active) {
return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
}
} else if (activeIsoDomainId == null) {
return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
} else if (!isRepoImageExists(effectiveIsoPath, activeIsoDomainId, ImageFileType.ISO)) {
return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_ISO_IMAGE_PATH);
}
return ValidationResult.VALID;
}
if (!StringUtils.isEmpty(floppyPath) && !isRepoImageExists(floppyPath, activeIsoDomainId, ImageFileType.Floppy)) {
return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_FLOPPY_IMAGE_PATH);
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.storage.BaseDisk in project ovirt-engine by oVirt.
the class BaseDiskDaoTest method generateNewEntity.
@Override
protected BaseDisk generateNewEntity() {
BaseDisk d = new BaseDisk();
d.setId(Guid.newGuid());
d.setWipeAfterDelete(true);
d.setPropagateErrors(PropagateErrors.Off);
d.setDiskAlias("DiskName");
d.setSgio(ScsiGenericIO.FILTERED);
return d;
}
Aggregations