@Override public Ipv4BootProtocol getIpv4BootProtocol() { return nic.getIpv4BootProtocol(); }
@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 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 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()); } }
@Test public void testReportConfigurationsOnHostWhenIpv4BootProtocolNotStatic() { initIpv4ConfigurationBootProtocolAddress(Ipv4BootProtocol.NONE, false); initIpv4ConfigurationBootProtocolNetmask(Ipv4BootProtocol.NONE, false); initIpv4ConfigurationBootProtocolGateway(Ipv4BootProtocol.NONE, false); NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = createTestedInstanceWithSameNonQosValues(); List<ReportedConfiguration> reportedConfigurationList = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost().getReportedConfigurationList(); IPv4Address primaryAddress = this.testedNetworkAttachment.getIpConfiguration().getIpv4PrimaryAddress(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( createBasicAndQosReportedConfigurations(), defaultRouteReportedConfiguration(false), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), primaryAddress.getBootProtocol().name(), true) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
@Test public void testReportConfigurationsOnHostWhenDefaultRouteDiffers() { //cannot use initIpv4ConfigurationBootProtocol because of 'randomized tests' technique. iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); //network has default route role NetworkInSyncWithVdsNetworkInterface testedInstance = createTestedInstanceWithSameNonQosValues(true); ReportedConfigurations reportedConfigurations = testedInstance.reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( combineReportedConfigurations(createBasicReportedConfigurations(), reportQos(true)), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), /*ipv4Address*/address.getBootProtocol().name(), true), new ReportedConfiguration(ReportedConfigurationType.DNS_CONFIGURATION, addressesAsString(sampleDnsResolverConfiguration.getNameServers()), "192.168.1.1,2001:0db8:85a3:0000:0000:8a2e:0370:7334", true), new ReportedConfiguration(ReportedConfigurationType.DEFAULT_ROUTE, false, true, false) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
@Test public void testReportConfigurationsOnHostWhenDnsConfigurationResolverOutOfSync() { iface.setIpv4DefaultRoute(true); //cannot use initIpv4ConfigurationBootProtocol because of 'randomized tests' technique. iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); network.setDnsResolverConfiguration(sampleDnsResolverConfiguration2); ReportedConfigurations reportedConfigurations = createTestedInstanceWithSameNonQosValues(true).reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( combineReportedConfigurations(createBasicReportedConfigurations(), reportQos(true)), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), /*ipv4Address*/address.getBootProtocol().name(), true), new ReportedConfiguration(ReportedConfigurationType.DNS_CONFIGURATION, addressesAsString(sampleDnsResolverConfiguration.getNameServers()), addressesAsString(network.getDnsResolverConfiguration().getNameServers()), false), new ReportedConfiguration(ReportedConfigurationType.DEFAULT_ROUTE, true, true, true) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
iface.getIpv4BootProtocol().name(), primaryAddress.getBootProtocol().name(), true),
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); } }
/** * 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; }
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); }
.addValue("subnet", nic.getIpv4Subnet()) .addValue("ipv6_prefix", nic.getIpv6Prefix()) .addValue("boot_protocol", nic.getIpv4BootProtocol()) .addValue("ipv6_boot_protocol", nic.getIpv6BootProtocol()) .addValue("type", nic.getType())