use of org.onap.aai.domain.yang.L3InterfaceIpv6AddressList in project so by onap.
the class HeatBridgeImpl method updateLInterfaceIps.
protected void updateLInterfaceIps(final Port port, final LInterface lIf) {
for (IP ip : port.getFixedIps()) {
String ipAddress = ip.getIpAddress();
if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) {
Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
IPAddressString cidr = new IPAddressString(subnet.getCidr());
L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList();
lInterfaceIp.setIsFloating(false);
lInterfaceIp.setL3InterfaceIpv4Address(ipAddress);
lInterfaceIp.setNeutronNetworkId(port.getNetworkId());
lInterfaceIp.setNeutronSubnetId(ip.getSubnetId());
lInterfaceIp.setL3InterfaceIpv4PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv4AddressList(ipAddress)), Optional.of(lInterfaceIp));
} else if (InetAddressValidator.getInstance().isValidInet6Address(ipAddress)) {
Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
IPAddressString cidr = new IPAddressString(subnet.getCidr());
L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList();
ipv6.setIsFloating(false);
ipv6.setL3InterfaceIpv6Address(ipAddress);
ipv6.setNeutronNetworkId(port.getNetworkId());
ipv6.setNeutronSubnetId(ip.getSubnetId());
ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv6AddressList(ipAddress)), Optional.of(ipv6));
}
}
}
use of org.onap.aai.domain.yang.L3InterfaceIpv6AddressList in project so by onap.
the class HeatBridgeImplTest method testUpdateLInterfaceIps.
@Test
public void testUpdateLInterfaceIps() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
Port port = mock(Port.class);
when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
when(port.getDeviceId()).thenReturn("test-device-id");
IP ip = mock(IP.class);
Set<IP> ipSet = new HashSet<>();
ipSet.add(ip);
when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
when(ip.getSubnetId()).thenReturn("testSubnetId");
when(port.getFixedIps()).thenAnswer(x -> ipSet);
Subnet subnet = mock(Subnet.class);
when(subnet.getCidr()).thenReturn("169.254.100.0/24");
when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
LInterface lIf = new LInterface();
lIf.setInterfaceName("test-port-name");
// Act
heatbridge.updateLInterfaceIps(port, lIf);
L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList();
ipv6.setIsFloating(false);
ipv6.setL3InterfaceIpv6Address("2606:ae00:2e60:100::226");
ipv6.setNeutronNetworkId(port.getNetworkId());
ipv6.setNeutronSubnetId(ip.getSubnetId());
ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong("24"));
ArgumentCaptor<Optional> argument = ArgumentCaptor.forClass(Optional.class);
// Assert
verify(transaction).createIfNotExists(eq(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("CloudOwner", "RegionOne").tenant("7320ec4a5b9d4589ba7c4412ccfd290f").vserver("test-device-id").lInterface("test-port-name").l3InterfaceIpv6AddressList("2606:ae00:2e60:100::226"))), argument.capture());
assertTrue(argument.getValue().isPresent());
assertThat((L3InterfaceIpv6AddressList) argument.getValue().get(), sameBeanAs(ipv6));
}
Aggregations