Search in sources :

Example 1 with IDockerNetworkConfig

use of org.eclipse.linuxtools.docker.core.IDockerNetworkConfig in project linuxtools by eclipse.

the class DockerConnection method createNetwork.

@Override
public IDockerNetworkCreation createNetwork(IDockerNetworkConfig cfg) throws DockerException, InterruptedException {
    try {
        Ipam.Builder ipamBuilder = Ipam.builder().driver(cfg.ipam().driver());
        List<IDockerIpamConfig> ipamCfgs = cfg.ipam().config();
        for (IDockerIpamConfig ipamCfg : ipamCfgs) {
            ipamBuilder = ipamBuilder.config(ipamCfg.subnet(), ipamCfg.ipRange(), ipamCfg.gateway());
        }
        Ipam ipam = ipamBuilder.build();
        NetworkConfig.Builder networkConfigBuilder = NetworkConfig.builder().name(cfg.name()).driver(cfg.driver()).ipam(ipam);
        networkConfigBuilder.options(cfg.options());
        NetworkConfig networkConfig = networkConfigBuilder.build();
        com.spotify.docker.client.messages.NetworkCreation creation = client.createNetwork(networkConfig);
        return new DockerNetworkCreation(creation);
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) NetworkConfig(com.spotify.docker.client.messages.NetworkConfig) IDockerNetworkConfig(org.eclipse.linuxtools.docker.core.IDockerNetworkConfig) IDockerNetworkCreation(org.eclipse.linuxtools.docker.core.IDockerNetworkCreation) Ipam(com.spotify.docker.client.messages.Ipam) IDockerIpamConfig(org.eclipse.linuxtools.docker.core.IDockerIpamConfig)

Aggregations

Ipam (com.spotify.docker.client.messages.Ipam)1 NetworkConfig (com.spotify.docker.client.messages.NetworkConfig)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 IDockerIpamConfig (org.eclipse.linuxtools.docker.core.IDockerIpamConfig)1 IDockerNetworkConfig (org.eclipse.linuxtools.docker.core.IDockerNetworkConfig)1 IDockerNetworkCreation (org.eclipse.linuxtools.docker.core.IDockerNetworkCreation)1