Search in sources :

Example 61 with Network

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

the class ReportedConfigurationsFiller method getNicToWhichIsNetworkAttached.

private VdsNetworkInterface getNicToWhichIsNetworkAttached(Map<String, VdsNetworkInterface> networkNameToNicMap, BusinessEntityMap<Network> networkMap, NetworkAttachment networkAttachment) {
    Guid networkId = networkAttachment.getNetworkId();
    Network network = networkMap.get(networkId);
    return networkNameToNicMap.get(network.getName());
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) Guid(org.ovirt.engine.core.compat.Guid)

Example 62 with Network

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

the class ReportedConfigurationsFiller method fillReportedConfigurations.

private void fillReportedConfigurations(Map<String, VdsNetworkInterface> networkNameToNicMap, BusinessEntityMap<Network> networkMap, NetworkAttachment networkAttachment, DnsResolverConfiguration reportedDnsResolverConfiguration, Cluster cluster) {
    Network network = networkMap.get(networkAttachment.getNetworkId());
    VdsNetworkInterface nic = getNicToWhichIsNetworkAttached(networkNameToNicMap, networkMap, networkAttachment);
    if (nic != null) {
        NetworkInSyncWithVdsNetworkInterface isInSync = createNetworkInSyncWithVdsNetworkInterface(networkAttachment, nic, network, reportedDnsResolverConfiguration, cluster);
        ReportedConfigurations reportedConfigurations = isInSync.reportConfigurationsOnHost();
        networkAttachment.setReportedConfigurations(reportedConfigurations);
    }
}
Also used : ReportedConfigurations(org.ovirt.engine.core.common.businessentities.network.ReportedConfigurations) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkInSyncWithVdsNetworkInterface(org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface) NetworkInSyncWithVdsNetworkInterface(org.ovirt.engine.core.utils.NetworkInSyncWithVdsNetworkInterface)

Example 63 with Network

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

the class UpdateVmInterfaceCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    addCustomValue("InterfaceType", VmInterfaceType.forValue(getInterface().getType()).getDescription().toString());
    boolean succeeded = false;
    boolean macAddedToPool = false;
    try {
        if (isVnicProfileChanged(oldIface, getInterface())) {
            Network newNetwork = networkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId());
            Network oldNetwork = networkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId());
            if (!Objects.equals(oldNetwork, newNetwork)) {
                externalNetworkManagerFactory.create(oldIface).deallocateIfExternal();
            }
        }
        macAddedToPool = allocateMacFromRequest();
        if (mustChangeAddress(oldIface.getType(), getInterface().getType())) {
            vmDeviceDao.clearDeviceAddress(getInterface().getId());
        }
        getInterface().setSpeed(VmInterfaceType.forValue(getInterface().getType()).getSpeed());
        TransactionSupport.executeInNewTransaction(() -> {
            bumpVmVersion();
            updatePassthoughDeviceIfNeeded();
            getCompensationContext().snapshotEntity(oldIface);
            vmNicDao.update(getInterface());
            saveNetworkFilterParameters();
            getCompensationContext().stateChanged();
            return null;
        });
        succeeded = updateHost();
    } finally {
        setSucceeded(succeeded);
        macPoolCleanupAfterExecution(macAddedToPool);
    }
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 64 with Network

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

the class VnicProfileHelper method updateNicWithVnicProfile.

/**
 * Updates the vnic profile id of a given {@code VmNic} by a network name and vnic profile name.
 *
 * @param iface
 *            The vm network interface to be updated
 * @param user
 *            The user which performs the action
 * @return {@code true} if the vnic profile id is updated, else {@code false}
 */
private boolean updateNicWithVnicProfile(VmNetworkInterface iface, DbUser user) {
    if (iface.getNetworkName() == null) {
        iface.setVnicProfileId(null);
        return true;
    }
    Network network = getNetworksInCluster().get(iface.getNetworkName());
    if (network == null || !network.isVmNetwork()) {
        return false;
    }
    VnicProfile vnicProfile = getVnicProfileForNetwork(network, iface.getVnicProfileName());
    if (vnicProfile == null) {
        vnicProfile = findVnicProfileForUser(user, network);
        if (vnicProfile == null) {
            return false;
        }
    }
    iface.setVnicProfileId(vnicProfile.getId());
    return true;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile)

Example 65 with Network

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

the class NetworkPolicyUnit method filter.

@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
    if (hosts == null || hosts.isEmpty()) {
        return Collections.emptyList();
    }
    List<VDS> toRemoveHostList = new ArrayList<>();
    List<VmNetworkInterface> vmNICs = vmNetworkInterfaceDao.getAllForVm(vm.getId());
    Guid clusterId = hosts.get(0).getClusterId();
    List<Network> clusterNetworks = networkDao.getAllForCluster(clusterId);
    Map<String, Network> networksByName = Entities.entitiesByName(clusterNetworks);
    Map<Guid, List<String>> hostNics = interfaceDao.getHostNetworksByCluster(clusterId);
    Network displayNetwork = NetworkUtils.getDisplayNetwork(clusterNetworks);
    Map<Guid, VdsNetworkInterface> hostDisplayNics = getDisplayNics(displayNetwork);
    for (VDS host : hosts) {
        ValidationResult result = validateRequiredNetworksAvailable(host, vm, vmNICs, displayNetwork, networksByName, hostNics.get(host.getId()), hostDisplayNics.get(host.getId()));
        if (result.isValid()) {
            result = validatePassthroughVnics(vm.getId(), host, vmNICs);
        }
        if (!result.isValid()) {
            toRemoveHostList.add(host);
            messages.addMessages(host.getId(), result.getVariableReplacements());
            messages.addMessages(host.getId(), result.getMessagesAsStrings());
        }
    }
    hosts.removeAll(toRemoveHostList);
    return hosts;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Network (org.ovirt.engine.core.common.businessentities.network.Network)292 Test (org.junit.Test)105 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)63 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)47 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)46 ArrayList (java.util.ArrayList)44 Guid (org.ovirt.engine.core.compat.Guid)44 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)39 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)23 List (java.util.List)21 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)21 HashMap (java.util.HashMap)19 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)19 Map (java.util.Map)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)13 HashSet (java.util.HashSet)9 Set (java.util.Set)9 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9