Search in sources :

Example 1 with VmNicValidator

use of org.ovirt.engine.core.bll.validator.VmNicValidator 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 2 with VmNicValidator

use of org.ovirt.engine.core.bll.validator.VmNicValidator 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 3 with VmNicValidator

use of org.ovirt.engine.core.bll.validator.VmNicValidator 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)

Aggregations

ArrayList (java.util.ArrayList)3 VmNicValidator (org.ovirt.engine.core.bll.validator.VmNicValidator)3 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)3 Version (org.ovirt.engine.core.compat.Version)3