Search in sources :

Example 6 with NetworkCreation

use of com.spotify.docker.client.messages.NetworkCreation in project docker-client by spotify.

the class DefaultDockerClientTest method testNetworks.

@Test
public void testNetworks() throws Exception {
    requireDockerApiVersionAtLeast("1.21", "createNetwork and listNetworks");
    assumeFalse(CIRCLECI);
    final String networkName = randomName();
    final IpamConfig ipamConfig = IpamConfig.create("192.168.0.0/24", "192.168.0.0/24", "192.168.0.1");
    final Ipam ipam = Ipam.builder().driver("default").config(singletonList(ipamConfig)).build();
    final Map<String, String> labels = ImmutableMap.of("name", "starship", "foo", "bar");
    final NetworkConfig networkConfig = NetworkConfig.builder().name(networkName).driver("bridge").checkDuplicate(true).ipam(ipam).internal(false).enableIPv6(false).labels(labels).build();
    final NetworkCreation networkCreation = sut.createNetwork(networkConfig);
    assertThat(networkCreation.id(), is(notNullValue()));
    assertThat(networkCreation.warnings(), is(nullValue()));
    final List<Network> networks = sut.listNetworks();
    assertTrue(networks.size() > 0);
    Network network = null;
    for (final Network n : networks) {
        if (n.name().equals(networkName)) {
            network = n;
        }
    }
    assertThat(network, is(notNullValue()));
    // noinspection ConstantConditions
    assertThat(network.id(), is(notNullValue()));
    assertThat(sut.inspectNetwork(network.id()).name(), is(networkName));
    assertThat(network.ipam(), equalTo(ipam));
    if (dockerApiVersionAtLeast("1.23")) {
        assertThat(network.internal(), is(false));
        assertThat(network.enableIPv6(), is(false));
        assertThat(network.labels(), is(labels));
    }
    sut.removeNetwork(network.id());
    exception.expect(NetworkNotFoundException.class);
    sut.inspectNetwork(network.id());
}
Also used : Ipam(com.spotify.docker.client.messages.Ipam) AttachedNetwork(com.spotify.docker.client.messages.AttachedNetwork) Network(com.spotify.docker.client.messages.Network) NetworkConfig(com.spotify.docker.client.messages.NetworkConfig) IpamConfig(com.spotify.docker.client.messages.IpamConfig) EndpointIpamConfig(com.spotify.docker.client.messages.EndpointConfig.EndpointIpamConfig) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkCreation(com.spotify.docker.client.messages.NetworkCreation) Test(org.junit.Test)

Aggregations

NetworkCreation (com.spotify.docker.client.messages.NetworkCreation)6 Test (org.junit.Test)5 NetworkConfig (com.spotify.docker.client.messages.NetworkConfig)4 Long.toHexString (java.lang.Long.toHexString)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)4 AttachedNetwork (com.spotify.docker.client.messages.AttachedNetwork)3 Network (com.spotify.docker.client.messages.Network)3 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)2 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)2 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)2 EndpointIpamConfig (com.spotify.docker.client.messages.EndpointConfig.EndpointIpamConfig)2 Ipam (com.spotify.docker.client.messages.Ipam)2 IpamConfig (com.spotify.docker.client.messages.IpamConfig)2 Predicate (com.google.common.base.Predicate)1 EndpointConfig (com.spotify.docker.client.messages.EndpointConfig)1 NetworkConnection (com.spotify.docker.client.messages.NetworkConnection)1 ServiceCreateResponse (com.spotify.docker.client.messages.ServiceCreateResponse)1 NetworkAttachmentConfig (com.spotify.docker.client.messages.swarm.NetworkAttachmentConfig)1 ReplicatedService (com.spotify.docker.client.messages.swarm.ReplicatedService)1