@Override public String getIpv4Address() { return nic.getIpv4Address(); }
@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; }
@Override public boolean test(VdsNetworkInterface iface) { return address != null && (ipAddressPredicate.test(iface.getIpv4Address()) || ipAddressPredicate.test(iface.getIpv6Address())); } }
@Override public String getIpv4Address() { return shouldTakeIpv4DataFromNic() ? nic.getIpv4Address() : super.getIpv4Address(); }
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; }
private static void mapIpv4ToModel(VdsNetworkInterface entity, HostNic model) { BootProtocol ipv4BootProtocol = Ipv4BootProtocolMapper.map(entity.getIpv4BootProtocol()); if(ipv4BootProtocol!=null){ model.setBootProtocol(ipv4BootProtocol); } if (entity.getIpv4Address() != null || entity.getIpv4Gateway() != null || entity.getIpv4Subnet() != null) { final Ip ipv4 = new Ip(); ipv4.setVersion(IpVersion.V4); if (entity.getIpv4Address() != null) { ipv4.setAddress(entity.getIpv4Address()); } if (entity.getIpv4Gateway() != null) { ipv4.setGateway(entity.getIpv4Gateway()); } if (entity.getIpv4Subnet() != null) { ipv4.setNetmask(entity.getIpv4Subnet()); } model.setIp(ipv4); } }
private HostInterfaceLineModel lineModelFromBond(VdsNetworkInterface nic) { HostInterfaceLineModel model = lineModelFromInterface(nic); model.setInterface(nic); model.setIsBonded(true); model.setBondName(nic.getName()); model.setIpv4Address(nic.getIpv4Address()); model.setIpv6Address(nic.getIpv6Address()); return model; }
@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; } }
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; }
syncNetmask), new ReportedConfiguration(ReportedConfigurationType.IPV4_ADDRESS, iface.getIpv4Address(), primaryAddress.getAddress(), syncAddress),
private void addReportedIpv4Configuration(ReportedConfigurations result) { if (!isIpv4PrimaryAddressExist()) { return; } Ipv4BootProtocol definedIpv4BootProtocol = getIpv4PrimaryAddress().getBootProtocol(); result.add(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol(), definedIpv4BootProtocol); if (definedIpv4BootProtocol == Ipv4BootProtocol.STATIC_IP && iface.getIpv4BootProtocol() == definedIpv4BootProtocol) { result.add(ReportedConfigurationType.IPV4_NETMASK, iface.getIpv4Subnet(), getIpv4PrimaryAddress().getNetmask(), isIpv4NetworkSubnetInSync()); result.add(ReportedConfigurationType.IPV4_ADDRESS, iface.getIpv4Address(), getIpv4PrimaryAddress().getAddress()); result.add(ReportedConfigurationType.IPV4_GATEWAY, iface.getIpv4Gateway(), getIpv4PrimaryAddress().getGateway(), isIpv4GatewayInSync()); } }
/** * validate the following: * <ul> * <li>an interface must have an address when the boot protocol is static * </ul> */ @Override public boolean isValid(VdsNetworkInterface iface, ConstraintValidatorContext context) { Ipv4BootProtocol bootProtocol = iface.getIpv4BootProtocol(); String address = iface.getIpv4Address(); if (bootProtocol != null && bootProtocol == STATIC_IP) { if (isNullOrEmpty(address)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("NETWORK_ADDR_MANDATORY_IN_STATIC_IP") .addNode("address").addConstraintViolation(); return false; } } if (!isEmpty(iface.getBondName()) && !validateSlave(iface)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("SLAVE_INTERFACE_IS_MISCONFIGURED").addConstraintViolation(); return false; } if (!validateLabel(iface)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("IMPROPER_INTERFACE_IS_LABELED").addConstraintViolation(); } return true; }
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; }
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); }
private MapSqlParameterSource createInterfaceParametersMapper(VdsNetworkInterface nic) { return getCustomMapSqlParameterSource() .addValue("addr", nic.getIpv4Address()) .addValue("ipv6_address", nic.getIpv6Address()) .addValue("bond_name", nic.getBondName())