@Test public void testUnmappedEntityValue() { for (Ipv4BootProtocol value : Ipv4BootProtocol.values()) { assertThat(String.format("%s.%s is not mapped", Ipv6BootProtocol.class.getName(), value), Ipv4BootProtocolMapper.map(value), Matchers.notNullValue()); } }
public static Ipv4BootProtocol map(BootProtocol bootProtocol) { if (bootProtocol == null) { return null; } switch (bootProtocol) { case DHCP: return Ipv4BootProtocol.DHCP; case STATIC: return Ipv4BootProtocol.STATIC_IP; case NONE: return Ipv4BootProtocol.NONE; default: throw new WebApplicationException( Response.status(Status.BAD_REQUEST) .entity( fault("Invalid value", String.format("Boot protocol = '%s' is not applicable for IPv4.", bootProtocol))) .build()); } }
@Test public void testUnmappedModelValue() { for ( BootProtocol value : EnumSet.complementOf( EnumSet.of(BootProtocol.AUTOCONF, BootProtocol.POLY_DHCP_AUTOCONF) ) ) { assertThat(String.format("%s.%s is not mapped", BootProtocol.class.getName(), value), Ipv4BootProtocolMapper.map(value), Matchers.notNullValue()); } } }
@Test public void testMapAutoconf() { assertThrows(WebApplicationException.class, () -> Ipv4BootProtocolMapper.map(BootProtocol.AUTOCONF)); }
private static void populateModelWithIpv4Details(VmInitNetwork entity, NicConfiguration model) { if (entity.getBootProtocol() != null) { model.setBootProtocol(Ipv4BootProtocolMapper.map(entity.getBootProtocol())); } model.setIp(createIpModel(new VmInitNetworkIpv4InfoFetcher(entity))); }
private static IpAddressAssignment mapIpv4Address(IPv4Address iPv4Address) { IpAddressAssignment ipAddressAssignment = new IpAddressAssignment(); Ip ip = new Ip(); ip.setVersion(IpVersion.V4); if (iPv4Address.getAddress() != null) { ip.setAddress(iPv4Address.getAddress()); } if (iPv4Address.getGateway() != null) { ip.setGateway(iPv4Address.getGateway()); } if (iPv4Address.getNetmask() != null) { ip.setNetmask(iPv4Address.getNetmask()); } ipAddressAssignment.setIp(ip); BootProtocol assignmentMethod = Ipv4BootProtocolMapper.map(iPv4Address.getBootProtocol()); ipAddressAssignment.setAssignmentMethod(assignmentMethod == null ? null : assignmentMethod); return ipAddressAssignment; }
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 static void mapIpv4FromModel(HostNic model, VdsNetworkInterface entity) { if (model.isSetIp()) { if (model.getIp().isSetAddress()) { entity.setIpv4Address(model.getIp().getAddress()); } if (model.getIp().isSetGateway()) { entity.setIpv4Gateway(model.getIp().getGateway()); } if (model.getIp().isSetNetmask()) { entity.setIpv4Subnet(model.getIp().getNetmask()); } } if (model.isSetBootProtocol()) { Ipv4BootProtocol ipv4BootProtocol = Ipv4BootProtocolMapper.map(model.getBootProtocol()); if (ipv4BootProtocol != null) { entity.setIpv4BootProtocol(ipv4BootProtocol); } } }
private static IPv4Address mapIpv4AddressAssignment(IpAddressAssignment ipAddressAssignment) { IPv4Address iPv4Address = new IPv4Address(); if (ipAddressAssignment.isSetAssignmentMethod()) { Ipv4BootProtocol assignmentMethod = Ipv4BootProtocolMapper.map(ipAddressAssignment.getAssignmentMethod()); iPv4Address.setBootProtocol(assignmentMethod); } if (ipAddressAssignment.isSetIp()) { if (ipAddressAssignment.getIp().isSetAddress()) { iPv4Address.setAddress(ipAddressAssignment.getIp().getAddress()); } if (ipAddressAssignment.getIp().isSetGateway()) { iPv4Address.setGateway(ipAddressAssignment.getIp().getGateway()); } if (ipAddressAssignment.getIp().isSetNetmask()) { iPv4Address.setNetmask(ipAddressAssignment.getIp().getNetmask()); } } return iPv4Address; }
Ipv4BootProtocol protocol = Ipv4BootProtocolMapper.map(iface.getBootProtocol()); vmInitInterface.setBootProtocol(protocol); if (protocol != Ipv4BootProtocol.DHCP && iface.isSetNetwork() && iface.getNetwork().isSetIp()) {
public void verifyModelSpecific(HostNic model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(NAMES[index], model.getName()); assertNotNull(model.getNetwork()); assertEquals(NETWORK_NAME, model.getNetwork().getName()); assertEquals(calcSpeed(NIC_SPEED), model.getSpeed()); assertNotNull(model.getStatus()); assertEquals(HostNicMapper.mapNicStatus(NIC_STATUS), model.getStatus()); assertEquals(Ipv4BootProtocolMapper.map(IPV4_BOOT_PROTOCOL), model.getBootProtocol()); assertEquals(Ipv6BootProtocolMapper.map(IPV6_BOOT_PROTOCOL), model.getIpv6BootProtocol()); }
entity.setBootProtocol(Ipv4BootProtocolMapper.map(model.getBootProtocol()));