protected ToStringBuilder appendAttributes(ToStringBuilder tsb) { return tsb.append("id", getId()) .append("name", getName()) .append("vdsId", getVdsId()) .append("networkName", getNetworkName()) .append("ipv4BootProtocol", getIpv4BootProtocol()) .append("ipv4Address", getIpv4Address()) .append("ipv4Subnet", getIpv4Subnet()) .append("ipv4Gateway", getIpv4Gateway()) .append("ipv6BootProtocol", getIpv6BootProtocol()) .append("ipv6Address", getIpv6Address()) .append("ipv6Prefix", getIpv6Prefix()) .append("ipv6Gateway", getIpv6Gateway()) .append("mtu", getMtu()) .append("bridged", isBridged()) .append("reportedSwitchType", getReportedSwitchType()) .append("type", getType()) .append("networkImplementationDetails", getNetworkImplementationDetails()) .append("qos", getQos()) .append("adPartnerMac", getAdPartnerMac()) .append("adAggregatorId", adAggregatorId); }
public static VdsNetworkInterface getEntitySpecific(int index) { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(GUIDS[index]); entity.setName(NAMES[index]); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity = setUpStatistics(entity, GUIDS[index]); entity.getStatistics().setStatus(NIC_STATUS); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return entity; }
@Override public boolean test(VdsNetworkInterface iface) { return address != null && (ipAddressPredicate.test(iface.getIpv4Address()) || ipAddressPredicate.test(iface.getIpv6Address())); } }
/** * Returns the underlying interface name of a given nic * * @return Base interface name if the nic is a vlan device. * Otherwise, the name of the nic */ public static String stripVlan(VdsNetworkInterface nic) { return isVlan(nic) ? nic.getBaseInterface() : nic.getName(); }
@Override public boolean isValid(List<VdsNetworkInterface> value, ConstraintValidatorContext context) { Collection<String> staticIps = new HashSet<>(); for (VdsNetworkInterface networkInterface : value) { String address = networkInterface.getIpv4Address(); if (networkInterface.getIpv4BootProtocol() == Ipv4BootProtocol.STATIC_IP && address != null && !address.isEmpty()) { if (staticIps.contains(networkInterface.getIpv4Address())) { return false; } else { staticIps.add(networkInterface.getIpv4Address()); } } } return true; }
private MapSqlParameterSource createInterfaceParametersMapper(VdsNetworkInterface nic) { return getCustomMapSqlParameterSource() .addValue("addr", nic.getIpv4Address()) .addValue("ipv6_address", nic.getIpv6Address()) .addValue("bond_name", nic.getBondName()) .addValue("bond_type", nic.getBondType()) .addValue("gateway", nic.getIpv4Gateway()) .addValue("ipv4_default_route", nic.isIpv4DefaultRoute()) .addValue("ipv6_gateway", nic.getIpv6Gateway()) .addValue("id", nic.getId()) .addValue("is_bond", nic.getBonded()) .addValue("bond_opts", nic.getBondOptions()) .addValue("mac_addr", nic.getMacAddress()) .addValue("name", nic.getName()) .addValue("network_name", nic.getNetworkName()) .addValue("speed", nic.getSpeed()) .addValue("subnet", nic.getIpv4Subnet()) .addValue("ipv6_prefix", nic.getIpv6Prefix()) .addValue("boot_protocol", nic.getIpv4BootProtocol()) .addValue("ipv6_boot_protocol", nic.getIpv6BootProtocol()) .addValue("type", nic.getType()) .addValue("vds_id", nic.getVdsId()) .addValue("vlan_id", nic.getVlanId()) .addValue("base_interface", nic.getBaseInterface()) .addValue("mtu", nic.getMtu()) .addValue("bridged", nic.isBridged()) .addValue("labels", SerializationFactory.getSerializer().serialize(nic.getLabels())) .addValue("ad_partner_mac", nic.getAdPartnerMac()) .addValue("ad_aggregator_id", nic.getAdAggregatorId()) .addValue("bond_active_slave", nic.isBond() ? ((Bond)nic).getActiveSlave() : null)
VdsNetworkInterface entity = createInterface(rs); entity.setSpeed((Integer) rs.getObject("speed")); entity.setMacAddress(rs.getString("mac_addr")); entity.setStatistics(HostNetworkStatisticsRowMapper.INSTANCE.mapRow(rs, rowNum)); entity.setType((Integer) rs.getObject("type")); entity.setIpv4Gateway(rs.getString("gateway")); entity.setIpv4DefaultRoute(rs.getBoolean("ipv4_default_route")); entity.setIpv6Gateway(rs.getString("ipv6_gateway")); entity.setIpv4Subnet(rs.getString("subnet")); entity.setIpv6Prefix(getInteger(rs, "ipv6_prefix")); entity.setIpv4Address(rs.getString("addr")); entity.setIpv6Address(rs.getString("ipv6_address")); entity.setNetworkName(rs.getString("network_name")); entity.setName(rs.getString("name")); entity.setVdsId(getGuid(rs, "vds_id")); entity.setVdsName(rs.getString("vds_name")); entity.setId(getGuidDefaultEmpty(rs, "id")); entity.setIpv4BootProtocol(Ipv4BootProtocol.forValue(rs.getInt("boot_protocol"))); entity.setIpv6BootProtocol(Ipv6BootProtocol.forValue(rs.getInt("ipv6_boot_protocol"))); entity.setReportedSwitchType(SwitchType.parse(rs.getString("reported_switch_type"))); entity.setMtu(rs.getInt("mtu")); entity.setBridged(rs.getBoolean("bridged")); entity.setQos(hostNetworkQosDao.get(entity.getId())); entity.setLabels(SerializationFactory.getDeserializer().deserialize(rs.getString("labels"), HashSet.class)); entity.setAdPartnerMac(rs.getString("ad_partner_mac")); entity.setAdAggregatorId(getInteger(rs, "ad_aggregator_id"));
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); existingVdsInterface = dao.get(FixturesTool.VDS_NETWORK_INTERFACE); newQos = new HostNetworkQos(); newQos.setOutAverageLinkshare(30); newQos.setOutAverageUpperlimit(30); newQos.setOutAverageRealtime(30); newVdsInterface = new VdsNetworkInterface(); newVdsInterface.setStatistics(new VdsNetworkStatistics()); newVdsInterface.setId(Guid.newGuid()); newVdsInterface.setName("eth77"); newVdsInterface.setNetworkName("enginet"); newVdsInterface.setSpeed(1000); newVdsInterface.setType(3); newVdsInterface.setMacAddress("01:C0:81:21:71:17"); newVdsInterface.setIpv4BootProtocol(Ipv4BootProtocol.STATIC_IP); newVdsInterface.setIpv4Address("192.168.122.177"); newVdsInterface.setIpv4Subnet("255.255.255.0"); newVdsInterface.setIpv4Gateway("192.168.122.1"); newVdsInterface.setIpv6BootProtocol(Ipv6BootProtocol.AUTOCONF); newVdsInterface.setIpv6Address("ipv6 address"); newVdsInterface.setIpv6Prefix(666); newVdsInterface.setIpv6Gateway("ipv6 gateway"); newVdsInterface.setMtu(1500); newVdsInterface.setQos(newQos); newVdsStatistics = newVdsInterface.getStatistics(); }
@Mapping(from = VdsNetworkInterface.class, to = HostNic.class) public static HostNic map(VdsNetworkInterface entity, HostNic template) { HostNic model = template != null ? template : new HostNic(); if (entity.getId() != null) { model.setId(entity.getId().toString()); if (entity.getNetworkName() != null) { model.setNetwork(new Network()); model.getNetwork().setName(entity.getNetworkName()); if (entity.getName() != null) { model.setName(entity.getName()); if (entity.getBaseInterface() != null) { model.setBaseInterface(entity.getBaseInterface()); if (entity.getVlanId() != null) { model.setVlan(new org.ovirt.engine.api.model.Vlan()); model.getVlan().setId(entity.getVlanId()); if (entity.getMacAddress() != null) { model.setMac(new Mac()); model.getMac().setAddress(entity.getMacAddress()); if (entity.getStatistics().getStatus()!=InterfaceStatus.NONE) { NicStatus nicStatus = mapNicStatus(entity.getStatistics().getStatus()); if (nicStatus != null) { model.setStatus(nicStatus); if(entity.getSpeed()!=null && entity.getSpeed()>0){
public static VdsNetworkInterface getMaster() { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(MASTER_GUID); entity.setName(MASTER_NAME); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity.setBonded(true); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return setUpStatistics(entity, MASTER_GUID); }
@Override public IPv4Address apply(VdsNetworkInterface nic) { IPv4Address ipv4Address = new IPv4Address(); if (nic.getIpv4BootProtocol() == Ipv4BootProtocol.STATIC_IP) { ipv4Address.setAddress(nic.getIpv4Address()); ipv4Address.setNetmask(nic.getIpv4Subnet()); ipv4Address.setGateway(nic.getIpv4Gateway()); } ipv4Address.setBootProtocol(nic.getIpv4BootProtocol()); return ipv4Address; } }
@Override public IpV6Address apply(VdsNetworkInterface nic) { IpV6Address ipv6Address = new IpV6Address(); if (nic.getIpv6BootProtocol() == Ipv6BootProtocol.STATIC_IP) { ipv6Address.setAddress(nic.getIpv6Address()); ipv6Address.setPrefix(nic.getIpv6Prefix()); ipv6Address.setGateway(nic.getIpv6Gateway()); } ipv6Address.setBootProtocol(nic.getIpv6BootProtocol()); return ipv6Address; } }
public static VdsNetworkInterface getSlave() { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(SLAVE_GUID); entity.setName(SLAVE_NAME); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity.setBondName(MASTER_NAME); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return setUpStatistics(entity, SLAVE_GUID); }
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); }
private HostInterface hostInterfaceFromNic(VdsNetworkInterface nic) { HostInterface hi = new HostInterface(); hi.setInterface(nic); hi.setName(nic.getName()); hi.setIpv4Address(nic.getIpv4Address()); hi.setIpv6Address(nic.getIpv6Address()); hi.setMAC(nic.getMacAddress()); hi.setSpeed(nic.getSpeed()); hi.setRxRate(nic.getStatistics().getReceiveRate()); hi.setRxTotal(nic.getStatistics().getReceivedBytes()); hi.setRxDrop(nic.getStatistics().getReceiveDropRate()); hi.setTxRate(nic.getStatistics().getTransmitRate()); hi.setTxTotal(nic.getStatistics().getTransmittedBytes()); hi.setTxDrop(nic.getStatistics().getTransmitDropRate()); hi.setStatus(nic.getStatistics().getStatus()); hi.getPropertyChangedEvent().addListener(this); return hi; }
private HostVLan hostVlanFromNic(VdsNetworkInterface nic) { HostVLan hv = new HostVLan(); hv.setInterface(nic); hv.setName(nic.getName()); hv.setNetworkName(nic.getNetworkName()); hv.setIpv4Address(nic.getIpv4Address()); hv.setIpv6Address(nic.getIpv6Address()); hv.getPropertyChangedEvent().addListener(this); return hv; }
private String getKey(VdsNetworkInterface nic) { return nic.getName(); } }
private void testUpdateInterface(Guid interface_id) { VdsNetworkInterface iface = dao.get(interface_id); iface.setName(iface.getName().toUpperCase()); iface.setQos(newQos); dao.updateInterfaceForVds(iface); VdsNetworkInterface ifaced = dao.get(interface_id); assertEquals(iface.getName(), ifaced.getName()); assertEquals(iface.getQos(), ifaced.getQos()); verifyIpv6Properties(iface, ifaced); }
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()); } } }
private HostInterfaceLineModel lineModelFromInterface(VdsNetworkInterface nic) { HostInterfaceLineModel model = new HostInterfaceLineModel(); model.setInterfaces(new ArrayList<HostInterface>()); model.setVLans(new ArrayList<HostVLan>()); model.setNetworkName(nic.getNetworkName()); model.setIsManagement(nic.getIsManagement()); model.setIpv4Address(nic.getIpv4Address()); model.setIpv6Address(nic.getIpv6Address()); return model; }