Java Code Examples for com.github.dockerjava.api.model.Network#Ipam

The following examples show how to use com.github.dockerjava.api.model.Network#Ipam . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDockerBasedEnvironment.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
/**
 * Create network which is used as default in docker-compose.yml
 * This should be run before {@link DockerComposeExecutor#run(TestEnvironment)}
 */
@Override
public void createNetwork() {
    removeNetwork();

    String apmNetwork = apmBindAddress.substring(0, apmBindAddress.lastIndexOf(".")) + ".0/24";

    log.info(String.format("Creating network %s:", apmNetwork));

    Network.Ipam ipam = new Network.Ipam()
            .withConfig(new Network.Ipam.Config()
                    .withSubnet(apmNetwork)
                    .withGateway(apmBindAddress));

    CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
            .withName(Constants.HOST_ADDED_TO_ETC_HOSTS)
            .withIpam(ipam)
            .exec();

    try {
        network = dockerClient.inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    } catch (DockerException ex) {
        log.severe(String.format("Could not create network: %s", createNetworkResponse));
        throw new EnvironmentException("Could not create network: " + createNetworkResponse, ex);
    }
}
 
Example 2
Source File: CreateNetworkCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createNetworkWithIpamConfig() throws DockerException {
    assumeNotSwarm("no network in swarm", dockerRule);

    String networkName = "networkIpam" + dockerRule.getKind();
    String subnet = "10.67." + (79 + getFactoryType().ordinal()) + ".0/24";

    Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet(subnet));
    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).withIpam(ipam).exec();

    assertNotNull(createNetworkResponse.getId());

    Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    assertEquals(network.getName(), networkName);
    assertEquals("bridge", network.getDriver());
    assertEquals(subnet, network.getIpam().getConfig().iterator().next().getSubnet());
}
 
Example 3
Source File: CreateNetworkCmd.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@CheckForNull
Network.Ipam getIpam();
 
Example 4
Source File: CreateNetworkCmdImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public Network.Ipam getIpam() {
    return ipam;
}