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;
}
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;
}
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;
}
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()));
}
}
}
}
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());
}
Aggregations