use of org.ovirt.engine.core.common.osinfo.OsRepository in project ovirt-engine by oVirt.
the class VmValidator method checkPciAndIdeLimit.
/**
* This method checks that with the given parameters, the max PCI and IDE limits defined are not passed.
*/
public static ValidationResult checkPciAndIdeLimit(int osId, Version clusterVersion, int monitorsNumber, List<? extends VmNic> interfaces, List<DiskVmElement> diskVmElements, boolean virtioScsiEnabled, boolean hasWatchdog, boolean isBalloonEnabled, boolean isSoundDeviceEnabled) {
// this adds: monitors + 2 * (interfaces with type rtl_pv) + (all other
// interfaces) + (all disks that are not IDE)
int pciInUse = monitorsNumber;
for (VmNic a : interfaces) {
if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.rtl8139_pv) {
pciInUse += 2;
} else if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.spaprVlan) {
// Do not count sPAPR VLAN devices since they are not PCI
} else {
pciInUse += 1;
}
}
pciInUse += diskVmElements.stream().filter(dve -> dve.getDiskInterface() == DiskInterface.VirtIO).count();
// VirtIO SCSI controller requires one PCI slot
pciInUse += virtioScsiEnabled ? 1 : 0;
// VmWatchdog controller requires one PCI slot
pciInUse += hasWatchdog ? 1 : 0;
// Balloon controller requires one PCI slot
pciInUse += isBalloonEnabled ? 1 : 0;
// Sound device controller requires one PCI slot
pciInUse += isSoundDeviceEnabled ? 1 : 0;
OsRepository osRepository = Injector.get(OsRepository.class);
int maxPciSlots = osRepository.getMaxPciDevices(osId, clusterVersion);
ArrayList<EngineMessage> messages = new ArrayList<>();
if (pciInUse > maxPciSlots) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS);
} else if (VmCommand.MAX_IDE_SLOTS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.IDE).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_IDE_SLOTS);
} else if (VmCommand.MAX_VIRTIO_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.VirtIO_SCSI).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_VIRTIO_SCSI_DISKS);
} else if (VmCommand.MAX_SPAPR_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.SPAPR_VSCSI).count()) {
messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_SPAPR_VSCSI_DISKS);
}
if (!messages.isEmpty()) {
return new ValidationResult(messages);
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.osinfo.OsRepository in project ovirt-engine by oVirt.
the class BackendOperatingSystemResource method get.
@Override
public OperatingSystemInfo get() {
OsRepository repository = SimpleDependencyInjector.getInstance().get(OsRepository.class);
OperatingSystemInfo model = new OperatingSystemInfo();
model.setId(id);
Integer key = Integer.valueOf(id);
String uniqueName = repository.getUniqueOsNames().get(key);
if (uniqueName == null) {
return notFound();
}
model.setName(uniqueName);
String name = repository.getOsNames().get(key);
if (name != null) {
model.setDescription(name);
}
final VmIconDefault vmIconDefault = getEntity(VmIconDefault.class, QueryType.GetVmIconDefault, new GetVmIconDefaultParameters(key), "VmIconDefault");
if (vmIconDefault != null) {
model.setSmallIcon(IconHelper.createIcon(vmIconDefault.getSmallIconId()));
model.setLargeIcon(IconHelper.createIcon(vmIconDefault.getLargeIconId()));
}
return addLinks(model);
}
use of org.ovirt.engine.core.common.osinfo.OsRepository in project ovirt-engine by oVirt.
the class RunVmValidatorTest method mockOsRepository.
private void mockOsRepository() {
OsRepository osRepository = mock(OsRepository.class);
when(osRepository.get64bitOss()).thenReturn(Collections.singletonList(_64_BIT_OS));
final Map<Integer, ArchitectureType> osArchitectures = Collections.singletonMap(_64_BIT_OS, ArchitectureType.x86_64);
when(osRepository.getOsArchitectures()).thenReturn(Collections.unmodifiableMap(osArchitectures));
SimpleDependencyInjector.getInstance().bind(OsRepository.class, osRepository);
}
use of org.ovirt.engine.core.common.osinfo.OsRepository in project ovirt-engine by oVirt.
the class VmNicValidatorTest method isCompatibleWithOsTest.
private void isCompatibleWithOsTest(Matcher<ValidationResult> matcher, int vmInterfaceType) {
VmNicValidator validator = spy(new VmNicValidator(nic, version, 0));
OsRepository osRepository = mock(OsRepository.class);
when(osRepository.getNetworkDevices(anyInt(), any())).thenReturn(NETWORK_DEVICES);
when(nic.getType()).thenReturn(vmInterfaceType);
injectorRule.bind(OsRepository.class, osRepository);
assertThat(validator.isCompatibleWithOs(), matcher);
}
use of org.ovirt.engine.core.common.osinfo.OsRepository in project ovirt-engine by oVirt.
the class VmWatchdogValidatorTest method isModelCompatibleWithOsTest.
private void isModelCompatibleWithOsTest(Matcher<ValidationResult> matcher, VmWatchdogType watchDogModel) {
Version version = new Version();
VmWatchdog vmWatchdog = new VmWatchdog();
vmWatchdog.setModel(watchDogModel);
VmWatchdogValidator.VmWatchdogClusterDependentValidator validator = spy(new VmWatchdogValidator.VmWatchdogClusterDependentValidator(0, vmWatchdog, version));
OsRepository osRepository = mock(OsRepository.class);
when(validator.getOsRepository()).thenReturn(osRepository);
when(osRepository.getVmWatchdogTypes(anyInt(), any())).thenReturn(WATCHDOG_MODELS);
assertThat(validator.isValid(), matcher);
}
Aggregations