Search in sources :

Example 86 with VmNetworkInterface

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

the class BackendVmNicsResource method list.

@Override
public Nics list() {
    Nics nics = new Nics();
    List<VmNetworkInterface> entities = getBackendCollection(QueryType.GetVmInterfacesByVmId, new IdQueryParameters(vmId));
    for (VmNetworkInterface entity : entities) {
        Nic nic = populate(map(entity), entity);
        nics.getNics().add(addLinks(nic));
    }
    return nics;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Nic(org.ovirt.engine.api.model.Nic) Nics(org.ovirt.engine.api.model.Nics)

Example 87 with VmNetworkInterface

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

the class BackendInstanceTypeNicResourceTest method setUpNicExpectations.

private VmNetworkInterface setUpNicExpectations() {
    VmNetworkInterface nic = mock(VmNetworkInterface.class);
    when(nic.getId()).thenReturn(NIC_ID);
    when(nic.getType()).thenReturn(0);
    return nic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)

Example 88 with VmNetworkInterface

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

the class RegisterEntityModel method getNewVnicProfileMappings.

/**
 * create a {@link VnicProfileMappingEntity} with no target profile for each pre-loaded interface of the registered entity
 * if a previous mapping for the same source profile is not found.
 *
 * @param interfaces the interfaces of the registered entity initially loaded by the frontend when the register action started
 * @param previousClusterVnicProfileMappings the mappings passed to {@link VnicProfileMappingModel}, with user selections of target profiles
 * @return a set of mappings for all interfaces of registered entity
 */
private Set<VnicProfileMappingEntity> getNewVnicProfileMappings(List<VmNetworkInterface> interfaces, Set<VnicProfileMappingEntity> previousClusterVnicProfileMappings) {
    Set<VnicProfileMappingEntity> result = new HashSet<>();
    for (VmNetworkInterface vnic : interfaces) {
        VnicProfileMappingEntity newMapping = new VnicProfileMappingEntity(vnic.getNetworkName(), vnic.getVnicProfileName(), null);
        VnicProfileMappingEntity mapping = previousClusterVnicProfileMappings.stream().filter(x -> x.isSameSourceProfile(newMapping)).findFirst().orElse(newMapping);
        // warning: the Set.add() uses the equals of {@link VnicProfileMappingEntity} which only compares the source profile
        result.add(mapping);
    }
    return result;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VnicProfileMappingEntity(org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity) HashSet(java.util.HashSet)

Example 89 with VmNetworkInterface

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

the class SyncNetworkProviderCommand method disconnectVms.

private void disconnectVms(Guid networkId) {
    Map<Guid, VnicProfile> profiles = vnicProfileDao.getAllForNetwork(networkId).stream().collect(Collectors.toConcurrentMap(VnicProfile::getId, Function.identity()));
    for (VM vm : vmDao.getAllForNetwork(networkId)) {
        vmHandler.updateNetworkInterfacesFromDb(vm);
        for (VmNetworkInterface iface : vm.getInterfaces()) {
            if (profiles.get(iface.getVnicProfileId()) != null) {
                log.warn("External network '{}' disappeared from provider '{}', disconnecting interface '{}' of VM '{}'.", networkId, getProvider().getName(), iface.getName(), vm.getName());
                iface.setVnicProfileId(null);
                iface.setPlugged(false);
                propagateReturnValue(runInternalAction(ActionType.UpdateVmInterface, new AddVmInterfaceParameters(vm.getId(), iface), getInternalCommandContext()));
            }
        }
    }
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VM(org.ovirt.engine.core.common.businessentities.VM) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) Guid(org.ovirt.engine.core.compat.Guid) AddVmInterfaceParameters(org.ovirt.engine.core.common.action.AddVmInterfaceParameters)

Example 90 with VmNetworkInterface

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

the class VmDeviceCommonUtilsTest method testUpdateVmDevicesBootOrder.

@Test
public void testUpdateVmDevicesBootOrder() {
    Map<VmDeviceId, DiskVmElement> idToDiskElement = new HashMap<>();
    List<VmNetworkInterface> interfaces = new LinkedList<>();
    VmDevice nic1 = createNetworkInterface(true, NIC_1_NAME, interfaces);
    VmDevice unmanagedNic = createUnmanagedNetworkInterface(true);
    VmDevice nic2 = createNetworkInterface(true, NIC_2_NAME, interfaces);
    VmDevice nonBootableNic = createNetworkInterface(false, "", interfaces);
    VmDevice bootableDisk = createDiskDevice(true, idToDiskElement);
    VmDevice nonBootableDisk = createDiskDevice(false, idToDiskElement);
    VmDevice cd = createCdRomDevice();
    doReturn(BootSequence.DNC).when(vm).getDefaultBootSequence();
    // it is important that nic2 will be before nic1 to ensure their boot order is
    // ordered according to their names and not according to their position in the list
    VmDeviceCommonUtils.updateVmDevicesBootOrder(vm.getDefaultBootSequence(), Arrays.asList(bootableDisk, nic2, cd, nic1, nonBootableDisk, unmanagedNic), interfaces, idToDiskElement);
    int index = 1;
    assertEquals("Wrong boot order for CD", index++, cd.getBootOrder());
    assertEquals("Wrong boot order for nic1", index++, nic1.getBootOrder());
    assertEquals("Wrong boot order for nic2", index++, nic2.getBootOrder());
    assertEquals("Wrong boot order for non bootable nic", 0, nonBootableNic.getBootOrder());
    assertEquals("Wrong boot order for unmanaged nic", 0, unmanagedNic.getBootOrder());
    assertEquals("Wrong boot order for bootable disk", index++, bootableDisk.getBootOrder());
    assertEquals("Wrong boot order for non bootable disk", 0, nonBootableDisk.getBootOrder());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)115 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)25 Guid (org.ovirt.engine.core.compat.Guid)19 VM (org.ovirt.engine.core.common.businessentities.VM)16 HashMap (java.util.HashMap)11 List (java.util.List)9 Map (java.util.Map)9 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 PairQueryable (org.ovirt.engine.core.common.utils.PairQueryable)6 MapVnicsContext (org.ovirt.engine.core.bll.exportimport.vnics.MapVnicsContext)5 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)5 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)5 VmNetworkStatistics (org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics)5 Nic (org.ovirt.engine.api.model.Nic)4 VnicProfileHelper (org.ovirt.engine.core.bll.network.vm.VnicProfileHelper)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)4 Collection (java.util.Collection)3