Search in sources :

Example 1 with OsRepository

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;
}
Also used : Arrays(java.util.Arrays) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) ArrayList(java.util.ArrayList) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) Map(java.util.Map) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) Version(org.ovirt.engine.core.compat.Version) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmCommand(org.ovirt.engine.core.bll.VmCommand) Config(org.ovirt.engine.core.common.config.Config) ActionUtils(org.ovirt.engine.core.common.ActionUtils) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) HostDeviceManager(org.ovirt.engine.core.bll.hostdev.HostDeviceManager) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) DiskDao(org.ovirt.engine.core.dao.DiskDao) Injector(org.ovirt.engine.core.di.Injector) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) ArrayList(java.util.ArrayList) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 2 with OsRepository

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);
}
Also used : GetVmIconDefaultParameters(org.ovirt.engine.core.common.queries.GetVmIconDefaultParameters) OperatingSystemInfo(org.ovirt.engine.api.model.OperatingSystemInfo) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmIconDefault(org.ovirt.engine.core.common.businessentities.VmIconDefault)

Example 3 with OsRepository

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);
}
Also used : ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository)

Example 4 with 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);
}
Also used : OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository)

Example 5 with OsRepository

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);
}
Also used : Version(org.ovirt.engine.core.compat.Version) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Aggregations

OsRepository (org.ovirt.engine.core.common.osinfo.OsRepository)10 OperatingSystemInfo (org.ovirt.engine.api.model.OperatingSystemInfo)2 ArchitectureType (org.ovirt.engine.core.common.businessentities.ArchitectureType)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 OperatingSystemInfos (org.ovirt.engine.api.model.OperatingSystemInfos)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 VmCommand (org.ovirt.engine.core.bll.VmCommand)1 HostDeviceManager (org.ovirt.engine.core.bll.hostdev.HostDeviceManager)1 DisksFilter (org.ovirt.engine.core.bll.storage.disk.image.DisksFilter)1 ONLY_ACTIVE (org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE)1 ONLY_NOT_SHAREABLE (org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE)1