Search in sources :

Example 1 with NetworkAddressInterface

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();
}
Also used : NetworkAddressInterface(com.yahoo.vespa.hosted.dockerapi.DockerNetworkCreator.NetworkAddressInterface) HashMap(java.util.HashMap) Network(com.github.dockerjava.api.model.Network) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

Network (com.github.dockerjava.api.model.Network)1 NetworkAddressInterface (com.yahoo.vespa.hosted.dockerapi.DockerNetworkCreator.NetworkAddressInterface)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1