Search in sources :

Example 6 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class MacsUsedAcrossWholeSystem method calculateAllMacsUsedInVmAndItsSnapshot.

private Stream<String> calculateAllMacsUsedInVmAndItsSnapshot(List<? extends VmNic> vmInterfaces, List<? extends VmNic> snapshotInterfaces) {
    CountMacUsageDifference countMacUsageDifference = new CountMacUsageDifference(macAddressesOfInterfaces(snapshotInterfaces), macAddressesOfInterfaces(vmInterfaces));
    Stream<String> macsDuplicatedByNumberOfTimesTheyAreUsed = countMacUsageDifference.maxUsage().entrySet().stream().flatMap(entry -> LongStream.range(0, entry.getValue()).boxed().map(e -> entry.getKey()));
    return macsDuplicatedByNumberOfTimesTheyAreUsed;
}
Also used : CountMacUsageDifference(org.ovirt.engine.core.bll.snapshots.CountMacUsageDifference) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) LongStream(java.util.stream.LongStream) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) VmNicDao(org.ovirt.engine.core.dao.network.VmNicDao) Inject(javax.inject.Inject) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) Stream(java.util.stream.Stream) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) SnapshotsManager(org.ovirt.engine.core.bll.snapshots.SnapshotsManager) Map(java.util.Map) Optional(java.util.Optional) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) CountMacUsageDifference(org.ovirt.engine.core.bll.snapshots.CountMacUsageDifference)

Example 7 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class RemoveVmInterfaceCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    this.setVmName(vmStaticDao.get(getParameters().getVmId()).getName());
    VmNic iface = vmNicDao.get(getParameters().getInterfaceId());
    if (iface != null) {
        interfaceName = iface.getName();
        // Get Interface type.
        String interType = VmInterfaceType.forValue(iface.getType()).getDescription();
        if (interType != null) {
            addCustomValue("InterfaceType", interType);
        }
        externalNetworkManagerFactory.create(iface).deallocateIfExternal();
    }
    // remove from db
    TransactionSupport.executeInNewTransaction(() -> {
        vmStaticDao.incrementDbGeneration(getParameters().getVmId());
        vmNicDao.remove(getParameters().getInterfaceId());
        vmNetworkStatisticsDao.remove(getParameters().getInterfaceId());
        vmDeviceDao.remove(new VmDeviceId(getParameters().getInterfaceId(), getParameters().getVmId()));
        // return mac to pool
        if (iface != null) {
            String macOfNicBeingRemoved = iface.getMacAddress();
            MacIsNotReservedInSnapshotAndCanBeReleased canBeReleased = new MacIsNotReservedInSnapshotAndCanBeReleased();
            if (canBeReleased.macCanBeReleased(macOfNicBeingRemoved, getVm(), snapshotsManager)) {
                getMacPool().freeMac(macOfNicBeingRemoved);
            }
        }
        setSucceeded(true);
        return null;
    });
}
Also used : VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 8 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class ReorderVmNicsCommand method reorderNics.

private void reorderNics() {
    Map<Guid, VmDevice> vmInterfaceDevices = getVmInterfaceDevices();
    List<VmNic> nics = vmNicDao.getAllForVm(getParameters().getVmId());
    List<VmNic> nicsToReorder = new ArrayList<>();
    List<String> macsToReorder = new ArrayList<>();
    for (VmNic nic : nics) {
        VmDevice nicDevice = vmInterfaceDevices.get(nic.getId());
        // If there is not device, or the PCI address is empty
        if (nicDevice == null || StringUtils.isEmpty(nicDevice.getAddress())) {
            nicsToReorder.add(nic);
            // We know that all the NICs have a MAC address
            macsToReorder.add(nic.getMacAddress());
        }
    }
    // Sorting the NICs to reorder by name
    Collections.sort(nicsToReorder, numericSuffixNameableComparator);
    // Sorting the MAC addresses to reorder
    Collections.sort(macsToReorder);
    for (int i = 0; i < nicsToReorder.size(); ++i) {
        VmNic nic = nicsToReorder.get(i);
        nic.setMacAddress(macsToReorder.get(i));
        vmNicDao.update(nic);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 9 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic in project ovirt-engine by oVirt.

the class UpdateVmTemplateInterfaceCommand method getPermissionCheckSubjects.

@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    List<PermissionSubject> permissionList = super.getPermissionCheckSubjects();
    VmNic nic = getParameters().getInterface();
    if (nic != null && nic.getVnicProfileId() != null && getVmTemplate() != null) {
        VmNic oldNic = vmNicDao.get(nic.getId());
        if (oldNic == null || isVnicProfileChanged(oldNic, nic)) {
            permissionList.add(new PermissionSubject(nic.getVnicProfileId(), VdcObjectType.VnicProfile, getActionType().getActionGroup()));
        }
    }
    return permissionList;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 10 with VmNic

use of org.ovirt.engine.core.common.businessentities.network.VmNic 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)

Aggregations

VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)47 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 VM (org.ovirt.engine.core.common.businessentities.VM)6 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)6 Network (org.ovirt.engine.core.common.businessentities.network.Network)5 Guid (org.ovirt.engine.core.compat.Guid)5 HashMap (java.util.HashMap)4 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 List (java.util.List)3 Map (java.util.Map)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 Version (org.ovirt.engine.core.compat.Version)3 Collectors (java.util.stream.Collectors)2 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)2 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)2 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)2 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2