use of com.yahoo.vespa.hosted.dockerapi.DockerNetworkCreator.NetworkAddressInterface in project vespa by vespa-engine.
the class DockerImpl method setupDockerNetworkIfNeeded.
private void setupDockerNetworkIfNeeded() throws IOException {
if (!dockerClient.listNetworksCmd().withNameFilter(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty())
return;
// Use IPv6 address if there is a mix of IP4 and IPv6 by taking the longest address.
List<InetAddress> hostAddresses = Arrays.asList(InetAddress.getAllByName(com.yahoo.net.HostName.getLocalhost()));
InetAddress hostAddress = Collections.max(hostAddresses, (o1, o2) -> o1.getAddress().length - o2.getAddress().length);
NetworkAddressInterface networkAddressInterface = DockerNetworkCreator.getInterfaceForAddress(hostAddress);
boolean isIPv6 = networkAddressInterface.interfaceAddress.getAddress() instanceof Inet6Address;
Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet(hostAddress.getHostAddress() + "/" + networkAddressInterface.interfaceAddress.getNetworkPrefixLength()).withGateway(DockerNetworkCreator.getDefaultGatewayLinux(isIPv6).getHostAddress()));
Map<String, String> dockerNetworkOptions = new HashMap<>();
dockerNetworkOptions.put("parent", networkAddressInterface.networkInterface.getDisplayName());
dockerNetworkOptions.put("macvlan_mode", "bridge");
dockerClient.createNetworkCmd().withName(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).withDriver("macvlan").withEnableIpv6(isIPv6).withIpam(ipam).withOptions(dockerNetworkOptions).exec();
}
Aggregations