}
}
List<NetworkAddressData> addresses = instance.getNetwork().getAddressesList();
if (addresses != null && !addresses.isEmpty()) {
NetworkAddressData bestIpv4 = null;
NetworkAddressData bestIpv6 = null;
for (NetworkAddressData address : addresses) {
InetAddress inetAddress = InetAddresses.forString(address.getIp());
if (inetAddress instanceof Inet4Address) {
if (bestIpv4 == null) {
bestIpv4 = address;
} else {
log.warn("Cannot choose between IPv4 addresses");
}
} else if (inetAddress instanceof Inet6Address) {
if (bestIpv6 == null) {
bestIpv6 = address;
} else {
log.warn("Cannot choose between IPv6 addresses");
}
} else {
throw new IllegalStateException();
}
}
if (bestIpv4 != null) {
lxcConfig.ipv4Gateway = bestIpv4.getGateway();
lxcConfig.ipv4 = bestIpv4.getIp() + "/" + bestIpv4.getPrefixLength();
}
if (bestIpv6 != null) {
lxcConfig.ipv6Gateway = bestIpv6.getGateway();
lxcConfig.ipv6 = bestIpv6.getIp() + "/" + bestIpv6.getPrefixLength();
}
if (bestIpv6 != null && bestIpv6.hasMacAddress()) {
lxcConfig.hwaddr = bestIpv6.getMacAddress();
} else if (bestIpv4 != null && bestIpv4.hasMacAddress()) {
lxcConfig.hwaddr = bestIpv4.getMacAddress();
}
}