Search in sources :

Example 26 with VmNic

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

the class VmInterfaceManagerTest method removeAll.

@Test
public void removeAll() {
    List<VmNic> interfaces = Arrays.asList(createNewInterface(), createNewInterface());
    when(vmNicDao.getAllForVm(any())).thenReturn(interfaces);
    vmInterfaceManager.removeAllAndReleaseMacAddresses(Guid.newGuid());
    for (VmNic iface : interfaces) {
        verify(vmNicDao).remove(iface.getId());
        verify(vmNetworkStatisticsDao).remove(iface.getId());
    }
    verify(macPool).freeMacs(interfaces.stream().map(VmNic::getMacAddress).collect(Collectors.toList()));
}
Also used : VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Test(org.junit.Test)

Example 27 with VmNic

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

the class MacsUsedAcrossWholeSystemTest method createVm.

private VM createVm(Cluster cluster, Guid vmId, boolean running, boolean stateless, VmNetworkInterface... nics) {
    VM vm = new VM();
    vm.setId(vmId);
    vm.setInterfaces(new ArrayList<>(Arrays.asList(nics)));
    vm.setClusterId(cluster.getId());
    vm.setStatus(running ? VMStatus.Up : VMStatus.Down);
    vm.setStateless(stateless);
    when(vmNicDao.<VmNic>getAllForVm(vm.getId())).<VmNic>thenReturn(new ArrayList<>(vm.getInterfaces()));
    return vm;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 28 with VmNic

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

the class HotPlugOrUnplugNicVDSCommand method initNicStructure.

private Map<String, Object> initNicStructure() {
    Map<String, Object> map = new HashMap<>();
    VmNic nic = getParameters().getNic();
    VmDevice vmDevice = getParameters().getVmDevice();
    VM vm = getParameters().getVm();
    if (!nic.isPassthrough()) {
        map.put(VdsProperties.Type, vmDevice.getType().getValue());
        map.put(VdsProperties.Device, VmDeviceType.BRIDGE.getName());
        map.put(VdsProperties.MAC_ADDR, nic.getMacAddress());
        map.put(VdsProperties.LINK_ACTIVE, String.valueOf(nic.isLinked()));
        if (StringUtils.isNotBlank(vmDevice.getAddress())) {
            map.put(VdsProperties.Address, StringMapUtils.string2Map(getParameters().getVmDevice().getAddress()));
        }
        map.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
        map.put(VdsProperties.NIC_TYPE, vmInfoBuildUtils.evaluateInterfaceType(VmInterfaceType.forValue(nic.getType()), vm.getHasAgent()));
        map.put(VdsProperties.DeviceId, vmDevice.getId().getDeviceId().toString());
        vmInfoBuildUtils.addProfileDataToNic(map, vm, vmDevice, nic);
        vmInfoBuildUtils.addNetworkFiltersToNic(map, nic);
    } else {
        vmInfoBuildUtils.addNetworkVirtualFunctionProperties(map, nic, vmDevice, vmDevice.getHostDevice(), vm);
    }
    return map;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 29 with VmNic

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

the class UpdateVmInterfaceVDSCommand method initDeviceStructure.

protected Map<String, Object> initDeviceStructure() {
    Map<String, Object> deviceStruct = new HashMap<>();
    deviceStruct.put(VdsProperties.DeviceType, getParameters().getVmDevice().getType().getValue());
    deviceStruct.put(VdsProperties.Alias, getParameters().getVmDevice().getAlias());
    VmNic nic = getParameters().getNic();
    deviceStruct.put(VdsProperties.LINK_ACTIVE, String.valueOf(nic.isLinked()));
    VmDevice vmDevice = getParameters().getVmDevice();
    vmInfoBuildUtils.addProfileDataToNic(deviceStruct, getParameters().getVm(), vmDevice, nic);
    return deviceStruct;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 30 with VmNic

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

the class VmInfoBuildUtilsTest method testAddNetworkFiltersToNic.

@Test
public void testAddNetworkFiltersToNic() {
    Map<String, Object> struct = new HashMap<>();
    VmNic vmNic = new VmNic();
    vmNic.setVnicProfileId(VNIC_PROFILE_ID);
    vmNic.setId(VM_NIC_ID);
    underTest.addNetworkFiltersToNic(struct, vmNic);
    List<Map<String, Object>> parametersList = (List<Map<String, Object>>) struct.get(VdsProperties.NETWORK_FILTER_PARAMETERS);
    assertNotNull(struct.get(VdsProperties.NW_FILTER));
    assertEquals(struct.get(VdsProperties.NW_FILTER), NETWORK_FILTER_NAME);
    assertNotNull(parametersList);
    assertEquals(2, parametersList.size());
    assertEquals(NETWORK_FILTER_PARAMETER_0_NAME, parametersList.get(0).get("name"));
    assertEquals(NETWORK_FILTER_PARAMETER_0_VALUE, parametersList.get(0).get("value"));
    assertEquals(NETWORK_FILTER_PARAMETER_1_NAME, parametersList.get(1).get("name"));
    assertEquals(NETWORK_FILTER_PARAMETER_1_VALUE, parametersList.get(1).get("value"));
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Test(org.junit.Test)

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