summaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerNetworking.java
blob: 7678ad8169ad48faf542f90d9f6d6f03869eeb80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.docker;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

import com.yahoo.config.provision.NodeType;

/**
 * The types of network setup for the Docker containers.
 *
 * @author hakon
 */
public enum DockerNetworking {
    /** Each container has an associated macvlan bridge. */
    MACVLAN("vespa-macvlan"),

    /** Network Prefix-Translated networking. */
    NPT("vespa-bridge"),

    /** A host running a single container in the host network namespace. */
    HOST_NETWORK("host");

    private final String dockerNetworkMode;
    DockerNetworking(String dockerNetworkMode) {
        this.dockerNetworkMode = dockerNetworkMode;
    }

    public String getDockerNetworkMode() {
        return dockerNetworkMode;
    }

    public static DockerNetworking from(String cloud, NodeType nodeType, boolean hostAdmin) {
        if (cloud.equals("AWS")) {
            return DockerNetworking.NPT;
        } else if (nodeType == NodeType.confighost || nodeType == NodeType.proxyhost) {
            return DockerNetworking.HOST_NETWORK;
        } else if (hostAdmin) {
            return DockerNetworking.NPT;
        } else {
            return DockerNetworking.MACVLAN;
        }
    }
}