private VdsNetworkInterface lookupInterfaceById(String id) { for (VdsNetworkInterface iface : getCollection()) { if (iface.getId().toString().equals(id)) { return iface; } } return null; }
private NetworkInterfaceModel createSlaveModel(final Map<Guid, VdsNetworkInterface> nicsById, VdsNetworkInterface slave) { final VdsNetworkInterface physicalFunction = findPhysicalFunction(nicsById, slave.getId()); NetworkInterfaceModel slaveModel = new NetworkInterfaceModel(slave, nicToVfsConfig.containsKey(slave.getId()), physicalFunction == null ? null : physicalFunction.getName(), this); slaveModel.setBonded(true); return slaveModel; }
private boolean isPhysicalNic(VdsNetworkInterface nic, Set<String> bondNames, Set<String> slaveNames) { boolean isBond = bondNames.contains(nic.getName()); boolean isRemovedBond = hostSetupNetworksParametersData.getRemovedBonds().contains(nic.getId()); boolean isSlave = slaveNames.contains(nic.getName()); boolean isVlanDevice = NetworkCommonUtils.isVlan(nic); return !(isBond || isRemovedBond || isSlave || isVlanDevice); }
protected HostNic addMasterLink(HostNic nic, String bondName, List<VdsNetworkInterface> ifaces) { for (VdsNetworkInterface i : ifaces) { if (i.getName().equals(bondName)) { nic.getLinks().add(masterLink(i.getId().toString())); break; } } return nic; }
public NetworkAttachment(VdsNetworkInterface baseNic, Network network, IpConfiguration ipConfiguration) { this.networkId = network.getId(); this.networkName = network.getName(); this.nicId = baseNic.getId(); this.nicName = baseNic.getName(); this.ipConfiguration = ipConfiguration; }
public void updateAllInBatch(String procedureName, Collection<VdsNetworkInterface> paramValues, MapSqlParameterMapper<VdsNetworkInterface> mapper) { for (VdsNetworkInterface entity : paramValues) { hostNetworkQosDao.persistQosChanges(entity.getId(), entity.getQos()); } getCallsHandler().executeStoredProcAsBatch(procedureName, paramValues, mapper); }
@Override public void saveInterfaceForVds(VdsNetworkInterface nic) { hostNetworkQosDao.persistQosChanges(nic.getId(), nic.getQos()); MapSqlParameterSource parameterSource = createInterfaceParametersMapper(nic); getCallsHandler().executeModification("Insertvds_interface", parameterSource); }
private void initNicLabelsParameters() { for (VdsNetworkInterface nic : allExistingNics) { if (nic.getLabels() != null) { for (String label : nic.getLabels()) { getHostSetupNetworksParametersData().getLabels() .add(new NicLabel(nic.getId(), nic.getName(), label)); } getHostSetupNetworksParametersData().getOriginalLabels().addAll(nic.getLabels()); } } }
@Override public void updateInterfaceForVds(VdsNetworkInterface nic) { hostNetworkQosDao.persistQosChanges(nic.getId(), nic.getQos()); getCallsHandler().executeModification("Updatevds_interface", createInterfaceParametersMapper(nic)); }
private void verifyNicExistenceToHandle404StatusCode() { List<VdsNetworkInterface> hostInterfaces = getBackendCollection(VdsNetworkInterface.class, QueryType.GetVdsInterfacesByVdsId, new IdQueryParameters(getHostId())); boolean found = false; for (VdsNetworkInterface hostInterface : hostInterfaces) { if (hostInterface.getId().equals(nicId)) { found = true; break; } } if (!found) { notFound(VdsNetworkInterface.class); } }
protected VdsNetworkInterface setUpStatisticalExpectations() { VdsNetworkStatistics stats = mock(VdsNetworkStatistics.class); VdsNetworkInterface entity = mock(VdsNetworkInterface.class); when(entity.getSpeed()).thenReturn(SPEED); when(entity.getStatistics()).thenReturn(stats); when(entity.getId()).thenReturn(NIC_ID); when(stats.getReceiveRate()).thenReturn(RECEIVE_RATE); when(stats.getTransmitRate()).thenReturn(TRANSMIT_RATE); when(stats.getReceiveDropRate()).thenReturn(RECEIVE_DROP_RATE); when(stats.getTransmitDropRate()).thenReturn(TRANSMIT_DROP_RATE); when(stats.getReceivedBytes()).thenReturn(RECEIVED_BYTES); when(stats.getTransmittedBytes()).thenReturn(TRANSMITTED_BYTES); List<VdsNetworkInterface> ifaces = new ArrayList<>(); ifaces.add(entity); setUpEntityQueryExpectations(QueryType.GetVdsInterfacesByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { PARENT_GUID }, ifaces); return entity; }
@Test public void testCreatingBrandNewNetworkAttachment() { initNetworkIdToExistingAttachmentIdMap(); when(logicalNetworkModelOfNetworkA.isAttached()).thenReturn(false); NetworkOperation.ATTACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, networkInterfaceModelOfNicA, dataFromHostSetupNetworksModel); assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1)); NetworkAttachment networkAttachment = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(); assertNetworkAttachment(networkAttachment, null, networkA.getId(), nicA.getId()); assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().isEmpty(), is(true)); }
protected HostNic addActiveSlaveLink(HostNic nic, VdsNetworkInterface iface, List<VdsNetworkInterface> ifaces) { if (iface instanceof Bond) { Bond bond = (Bond) iface; if(nic.getBonding() == null) { nic.setBonding(new Bonding()); } for (VdsNetworkInterface i : ifaces) { if (i.getName().equals(bond.getActiveSlave())) { nic.getBonding().setActiveSlave(slave(i.getId().toString())); break; } } } return nic; }
protected HostNic addSlaveLinks(HostNic nic, List<VdsNetworkInterface> ifaces) { if(nic.getBonding() == null) { nic.setBonding(new Bonding()); } nic.getBonding().setSlaves(new HostNics()); for (VdsNetworkInterface i : ifaces) { if (i.isPartOfBond(nic.getName())) { nic.getBonding().getSlaves().getHostNics().add(slave(i.getId().toString())); } } return nic; }
@Test public void testReattachingPreexistingNetworkAfterItsBeingDetached() { NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA); initNetworkIdToExistingAttachmentIdMap(attachment); NetworkOperation.DETACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, null, dataFromHostSetupNetworksModel); NetworkOperation.ATTACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, networkInterfaceModelOfNicA, dataFromHostSetupNetworksModel); assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1)); NetworkAttachment updatedNetworkAttachment = dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(); assertNetworkAttachment(updatedNetworkAttachment, attachment.getId(), networkA.getId(), nicA.getId()); assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0)); }
@Test public void testReattachingPreexistingNetworkToDifferentNicAfterItsBeingDetached() { NetworkAttachment attachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicA, logicalNetworkModelOfNetworkA); initNetworkIdToExistingAttachmentIdMap(attachment); NetworkOperation.DETACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, null, dataFromHostSetupNetworksModel); NetworkOperation.ATTACH_NETWORK.getTarget().executeNetworkCommand( logicalNetworkModelOfNetworkA, networkInterfaceModelOfNicB, dataFromHostSetupNetworksModel); assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0)); assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1)); assertNetworkAttachment(dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(), attachment.getId(), networkA.getId(), nicB.getId()); }
@Test public void massClearNetworkFromNicsTest() { VdsNetworkInterface nic1 = dao.get(FixturesTool.VDS_NETWORK_INTERFACE); VdsNetworkInterface nic2 = dao.get(FixturesTool.VDS_NETWORK_INTERFACE_WITHOUT_QOS); VdsNetworkInterface nic3 = dao.get(FixturesTool.VDS_NETWORK_INTERFACE2); assertNotNull(nic1.getNetworkName()); assertNotNull(nic2.getNetworkName()); assertNotNull(nic3.getNetworkName()); dao.massClearNetworkFromNics(Arrays.asList(nic1.getId(), nic2.getId())); nic1 = dao.get(nic1.getId()); nic2 = dao.get(nic2.getId()); nic3 = dao.get(nic3.getId()); assertNull(nic1.getNetworkName()); assertNull(nic2.getNetworkName()); assertNotNull(nic3.getNetworkName()); }
/** * Ensures that get works as expected. */ @Test public void testGet() { newVdsInterface.setVdsId(VDS_ID); dao.saveInterfaceForVds(newVdsInterface); dao.saveStatisticsForVds(newVdsInterface.getStatistics()); VdsNetworkInterface result = dao.get(newVdsInterface.getId()); assertEquals(newVdsInterface, result); }
/** * Ensures that the specified VDS's interfaces are deleted. */ @Test public void testRemoveInterfacesForVds() { List<VdsNetworkInterface> before = dao.getAllInterfacesForVds(VDS_ID); // ensure we have records before the test boolean found = false; for (VdsNetworkInterface iface : before) { found |= FixturesTool.VDS_NETWORK_INTERFACE.equals(iface.getId()); } assertTrue(found); assertNotNull(networkQoSDao.get(FixturesTool.VDS_NETWORK_INTERFACE)); dao.removeInterfaceFromVds(FixturesTool.VDS_NETWORK_INTERFACE); List<VdsNetworkInterface> after = dao.getAllInterfacesForVds(VDS_ID); for (VdsNetworkInterface iface : after) { assertNotSame(FixturesTool.VDS_NETWORK_INTERFACE, iface.getId()); } assertNull(networkQoSDao.get(FixturesTool.VDS_NETWORK_INTERFACE)); }
@Test public void testMasshUpdateStatisticsForVds() { List<VdsNetworkInterface> interfaces = dao.getAllInterfacesForVds(VDS_ID); List<VdsNetworkStatistics> statistics = new ArrayList<>(interfaces.size()); for (VdsNetworkInterface iface : interfaces) { VdsNetworkStatistics stats = iface.getStatistics(); stats.setReceiveDropRate(RandomUtils.instance().nextInt() * 1.0); stats.setStatus(RandomUtils.instance().nextEnum(InterfaceStatus.class)); statistics.add(stats); } dao.massUpdateStatisticsForVds(statistics); List<VdsNetworkInterface> after = dao.getAllInterfacesForVds(VDS_ID); for (VdsNetworkInterface iface : after) { boolean found = false; for (VdsNetworkStatistics stats : statistics) { if (iface.getId().equals(stats.getId())) { found = true; assertEquals(stats.getReceiveDropRate(), iface.getStatistics().getReceiveDropRate()); assertEquals(stats.getStatus(), iface.getStatistics().getStatus()); } } assertTrue(found); } }