Search in sources :

Example 26 with HostNicVfsConfig

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

the class UpdateHostNicVfsConfigCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean result = true;
    HostNicVfsConfig oldVfsConfig = getVfsConfig();
    boolean allNetworksAllowedChanged = isAllNetworksAllowed() != oldVfsConfig.isAllNetworksAllowed();
    super.executeCommand();
    // Check if 'allNetworksAllowed' has changed
    if (allNetworksAllowedChanged) {
        oldVfsConfig.setAllNetworksAllowed(isAllNetworksAllowed());
        if (isAllNetworksAllowed()) {
            oldVfsConfig.setNetworks(Collections.emptySet());
            oldVfsConfig.setNetworkLabels(Collections.emptySet());
        }
    }
    boolean shouldRefreshHost = false;
    if (wasNumOfVfsChanged()) {
        shouldRefreshHost = true;
        String deviceName = networkDeviceHelper.getPciDeviceNameByNic(getNic());
        try {
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.HostDevChangeNumVfs, new HostDevChangeNumVfsVDSParameters(getVdsId(), deviceName, getNumOfVfs()));
            result = returnValue.getSucceeded();
        } catch (EngineException e) {
            throw new EngineException(EngineError.UPDATE_NUM_VFS_FAILURE);
        }
    }
    if (result) {
        setSucceeded(saveChangesToDb(shouldRefreshHost, oldVfsConfig, allNetworksAllowedChanged));
    }
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) HostDevChangeNumVfsVDSParameters(org.ovirt.engine.core.common.vdscommands.HostDevChangeNumVfsVDSParameters)

Example 27 with HostNicVfsConfig

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

the class UpdateHostNicVfsConfigCommand method getVfsConfig.

@Override
public HostNicVfsConfig getVfsConfig() {
    HostNicVfsConfig tmpVfsConfig = super.getVfsConfig();
    if (hostNicVfsConfig == null) {
        networkDeviceHelper.updateHostNicVfsConfigWithNumVfsData(tmpVfsConfig);
    }
    hostNicVfsConfig = tmpVfsConfig;
    return hostNicVfsConfig;
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)

Example 28 with HostNicVfsConfig

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

the class VfSchedulerImpl method validatePassthroughVnics.

@Override
public List<String> validatePassthroughVnics(Guid vmId, Guid hostId, List<VmNetworkInterface> allVmNics) {
    List<VmNetworkInterface> pluggedPassthroughVnics = getPluggedPassthroughVnics(allVmNics);
    if (pluggedPassthroughVnics.isEmpty()) {
        return Collections.emptyList();
    }
    Map<Guid, Map<Guid, String>> hostToVnicToVfMap = vmToHostToVnicToVfMap.get(vmId);
    if (hostToVnicToVfMap == null) {
        hostToVnicToVfMap = new HashMap<>();
        vmToHostToVnicToVfMap.put(vmId, hostToVnicToVfMap);
    }
    Map<Guid, List<String>> nicToUsedVfs = new HashMap<>();
    Map<Guid, VdsNetworkInterface> fetchedNics = new HashMap<>();
    List<String> problematicVnics = new ArrayList<>();
    List<HostNicVfsConfig> vfsConfigs = networkDeviceHelper.getHostNicVfsConfigsWithNumVfsDataByHostId(hostId);
    Map<Guid, String> vnicToVfMap = new HashMap<>();
    hostToVnicToVfMap.put(hostId, vnicToVfMap);
    for (final VmNetworkInterface vnic : pluggedPassthroughVnics) {
        String freeVf = findFreeVfForVnic(vfsConfigs, nicToUsedVfs, fetchedNics, vnic.getNetworkName() == null ? null : networkDao.getByNameAndDataCenter(vnic.getNetworkName(), hostDao.get(hostId).getStoragePoolId()), vnic.getVmId(), true);
        if (freeVf == null) {
            problematicVnics.add(vnic.getName());
        } else {
            vnicToVfMap.put(vnic.getId(), freeVf);
        }
    }
    return problematicVnics;
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with HostNicVfsConfig

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

the class HostNicVfsConfigDaoTest method testRemoveNetwork.

@Test
public void testRemoveNetwork() {
    HostNicVfsConfig vfsConfig = dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
    checkNetworks(vfsConfig, 1);
    dao.removeNetwork(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, vfsConfig.getNetworks().iterator().next());
    vfsConfig = dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
    checkNetworks(vfsConfig, 0);
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) Test(org.junit.Test)

Example 30 with HostNicVfsConfig

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

the class HostNicVfsConfigDaoTest method testGetAll.

/**
 * Ensures that all hostNicVfsConfig are returned.
 */
@Test
public void testGetAll() {
    List<HostNicVfsConfig> result = dao.getAll();
    assertNotNull(result);
    assertEquals(EXPECTED_GUIDS.size(), result.size());
    for (HostNicVfsConfig vfsConfig : result) {
        assertTrue(EXPECTED_GUIDS.containsKey(vfsConfig.getId()));
        Pair<Integer, Integer> expectedConfig = EXPECTED_GUIDS.get(vfsConfig.getId());
        checkNetworksAndLabels(vfsConfig, expectedConfig.getFirst(), expectedConfig.getSecond());
    }
}
Also used : HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) Test(org.junit.Test)

Aggregations

HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)34 Test (org.junit.Test)13 Guid (org.ovirt.engine.core.compat.Guid)8 ArrayList (java.util.ArrayList)7 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)7 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)5 List (java.util.List)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Arrays (java.util.Arrays)2 Collectors (java.util.stream.Collectors)2 RandomStringUtils (org.apache.commons.lang.RandomStringUtils)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertNull (org.junit.Assert.assertNull)2 Before (org.junit.Before)2