Search in sources :

Example 41 with VmNic

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

the class AddVmInterfaceCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }
    macPool = getMacPool();
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (getVm().isHostedEngine() && !getVm().isManagedHostedEngine()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_UNMANAGED_HOSTED_ENGINE);
    }
    if (!updateVnicForBackwardCompatibility()) {
        return false;
    }
    if (!validate(vmStatusLegal(vmDynamicDao.get(getParameters().getVmId()).getStatus()))) {
        return false;
    }
    List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getVmId());
    if (!uniqueInterfaceName(interfaces)) {
        return false;
    }
    if (!validate(vmTemplateEmpty())) {
        return false;
    }
    // check that not exceeded PCI and IDE limit
    List<VmNic> allInterfaces = new ArrayList<>(interfaces);
    allInterfaces.add(getInterface());
    if (!pciAndIdeWithinLimit(getVm(), allInterfaces)) {
        return false;
    }
    Version compatibilityVersion = getVm().getClusterCompatibilityVersion();
    VmNicValidator nicValidator = new VmNicValidator(getInterface(), compatibilityVersion, getVm().getOs());
    if (!validate(nicValidator.isCompatibleWithOs()) || !validate(nicValidator.profileValid(getVm().getClusterId())) || !validate(nicValidator.typeMatchesProfile()) || !validate(nicValidator.passthroughIsLinked()) || !validate(nicValidator.validateProfileNotEmptyForHostedEngineVm(getVm()))) {
        return false;
    }
    if (StringUtils.isNotEmpty(getMacAddress())) {
        if (!validate(macAvailable())) {
            return false;
        }
    } else if (macPool.getAvailableMacsCount() <= 0) {
        addValidationMessage(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
        return false;
    }
    return true;
}
Also used : Version(org.ovirt.engine.core.compat.Version) ArrayList(java.util.ArrayList) VmNicValidator(org.ovirt.engine.core.bll.validator.VmNicValidator) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 42 with VmNic

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

the class UpdateVmInterfaceCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (!validate(vmStatusLegal(getVm().getStatus()))) {
        return false;
    }
    initVmData();
    if (oldIface == null || oldVmDevice == null) {
        addValidationMessage(EngineMessage.VM_INTERFACE_NOT_EXIST);
        return false;
    }
    if (!updateVnicForBackwardCompatibility(oldIface)) {
        return false;
    }
    if (!StringUtils.equals(oldIface.getName(), getInterfaceName()) && !uniqueInterfaceName(vmInterfaces)) {
        return false;
    }
    // check that not exceeded PCI and IDE limit
    List<VmNic> allInterfaces = new ArrayList<>(vmInterfaces);
    allInterfaces.remove(oldIface);
    allInterfaces.add(getInterface());
    if (!pciAndIdeWithinLimit(getVm(), allInterfaces)) {
        return false;
    }
    if (!validate(vmTemplateEmpty())) {
        return false;
    }
    UpdateVmNicValidator nicValidator = new UpdateVmNicValidator(getInterface(), getVm().getClusterCompatibilityVersion(), getVm().getOs());
    if (!validate(nicValidator.unplugPlugNotRequired()) || !validate(nicValidator.isCompatibleWithOs()) || !validate(nicValidator.hotUpdatePossible()) || !validate(nicValidator.profileValid(getVm().getClusterId())) || !validate(nicValidator.canVnicWithExternalNetworkBePlugged()) || !validate(nicValidator.typeMatchesProfile()) || !validate(nicValidator.passthroughIsLinked()) || !validate(nicValidator.validateProfileNotEmptyForHostedEngineVm(getVm()))) {
        return false;
    }
    Network network = networkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId());
    if (getRequiredAction() == RequiredAction.UPDATE_VM_DEVICE) {
        Network oldNetwork = networkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId());
        if (!validate(nicValidator.hotUpdateDoneWithInternalNetwork(oldNetwork, network)) || !validate(nicValidator.networkExistsOnHost(network))) {
            return false;
        }
    }
    initMacPoolData();
    if (macShouldBeChanged && macShouldBeAddedIntoPool() && !validate(macAvailable())) {
        return false;
    }
    return true;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) UpdateVmNic(org.ovirt.engine.core.common.validation.group.UpdateVmNic)

Example 43 with VmNic

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

the class AddVmTemplateInterfaceCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    List<VmNic> interfaces = vmNicDao.getAllForTemplate(getParameters().getVmTemplateId());
    if (!interfaceNameUnique(interfaces) || !validate(templateExists()) || !validate(linkedToTemplate())) {
        return false;
    }
    vmTemplateHandler.updateDisksFromDb(getVmTemplate());
    // not relevant for instance types - will be checked when a VM will be created out of it
    if (getVmTemplate().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
        if (!updateVnicForBackwardCompatibility()) {
            return false;
        }
        List<VmNic> interfacesForCheckPciLimit = new ArrayList<>(interfaces);
        interfacesForCheckPciLimit.add(getParameters().getInterface());
        if (!validate(VmValidator.checkPciAndIdeLimit(getVmTemplate().getOsId(), getCluster().getCompatibilityVersion(), getVmTemplate().getNumOfMonitors(), interfacesForCheckPciLimit, getTemplateDiskVmElements(), getVmDeviceUtils().hasVirtioScsiController(getVmTemplate().getId()), getVmDeviceUtils().hasWatchdog(getVmTemplate().getId()), getVmDeviceUtils().hasMemoryBalloon(getVmTemplate().getId()), getVmDeviceUtils().hasSoundDevice(getVmTemplate().getId())))) {
            return false;
        }
        Version clusterCompatibilityVersion = getCluster().getCompatibilityVersion();
        VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, getVmTemplate().getOsId());
        return validate(nicValidator.isCompatibleWithOs()) && validate(nicValidator.profileValid(getVmTemplate().getClusterId())) && validate(nicValidator.typeMatchesProfile()) && validate(nicValidator.passthroughIsLinked());
    }
    return true;
}
Also used : Version(org.ovirt.engine.core.compat.Version) ArrayList(java.util.ArrayList) VmNicValidator(org.ovirt.engine.core.bll.validator.VmNicValidator) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 44 with VmNic

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

the class UpdateVmTemplateInterfaceCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    if (!validate(linkedToTemplate())) {
        return false;
    }
    List<VmNic> interfaces = vmNicDao.getAllForTemplate(getParameters().getVmTemplateId());
    if (!validate(templateExists())) {
        return false;
    }
    // Interface oldIface = interfaces.First(i => i.id ==
    // AddVmInterfaceParameters.Interface.id);
    VmNic oldIface = interfaces.stream().filter(i -> i.getId().equals(getParameters().getInterface().getId())).findFirst().orElse(null);
    if (oldIface == null) {
        addValidationMessage(EngineMessage.VM_INTERFACE_NOT_EXIST);
        return false;
    }
    if (!updateVnicForBackwardCompatibility(oldIface)) {
        return false;
    }
    // not relevant for instance types - will be checked when a VM will be created out of it
    if (getVmTemplate().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
        Version clusterCompatibilityVersion = getCluster().getCompatibilityVersion();
        VmNicValidator nicValidator = new VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, getVmTemplate().getOsId());
        if (!validate(nicValidator.isCompatibleWithOs()) || !validate(nicValidator.profileValid(getVmTemplate().getClusterId())) || !validate(nicValidator.typeMatchesProfile()) || !validate(nicValidator.passthroughIsLinked())) {
            return false;
        }
        if (!checkPciAndIdeLimit(oldIface, new ArrayList<>(interfaces), clusterCompatibilityVersion)) {
            return false;
        }
    }
    if (!StringUtils.equals(oldIface.getName(), getInterfaceName()) && !interfaceNameUnique(interfaces)) {
        return false;
    }
    return true;
}
Also used : Version(org.ovirt.engine.core.compat.Version) ArrayList(java.util.ArrayList) VmNicValidator(org.ovirt.engine.core.bll.validator.VmNicValidator) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 45 with VmNic

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

the class SyncMacsOfDbNicsWithSnapshotTest method createNic.

private VmNic createNic(String macAddress) {
    VmNic nic = Mockito.mock(VmNic.class);
    when(nic.getMacAddress()).thenReturn(macAddress);
    return nic;
}
Also used : 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