• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java CreateNetworkResponse类的典型用法和代码示例

java 3次浏览

本文整理汇总了Java中com.github.dockerjava.api.command.CreateNetworkResponse的典型用法代码示例。如果您正苦于以下问题:Java CreateNetworkResponse类的具体用法?Java CreateNetworkResponse怎么用?Java CreateNetworkResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

CreateNetworkResponse类属于com.github.dockerjava.api.command包,在下文中一共展示了CreateNetworkResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createNetwork

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
/**
 * 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);
    }
}
 

开发者ID:hawkular,
项目名称:hawkular-apm,
代码行数:30,
代码来源:AbstractDockerBasedEnvironment.java

示例2: removeNetwork

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void removeNetwork() throws DockerException {
    assumeNotSwarm("Swarm has no network", dockerRule);

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd()
            .withName("test-network")
            .exec();

    LOG.info("Removing network: {}", network.getId());
    dockerRule.getClient().removeNetworkCmd(network.getId()).exec();

    List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();

    Matcher matcher = not(hasItem(hasField("id", startsWith(network.getId()))));
    assertThat(networks, matcher);

}
 

开发者ID:docker-java
项目名称:docker-java
代码行数:18,
代码来源:RemoveNetworkCmdIT.java

示例3: createContainerWithNetworkID

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createContainerWithNetworkID() {
    assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_24));

    String networkName = "net-" + UUID.randomUUID().toString();
    Map<String, String> labels = new HashMap<>();
    labels.put("com.example.label", "test");
    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName)
            .withLabels(labels).withAttachable(true).exec();
    String networkId = createNetworkResponse.getId();
    CreateContainerResponse createContainerResponse = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withLabels(labels).withCmd("true").exec();
    String containerId = createContainerResponse.getId();
    dockerRule.getClient().connectToNetworkCmd().withContainerId(containerId).withNetworkId(networkId).exec();
    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(containerId).exec();
    ContainerNetwork containerNetwork = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
    if (containerNetwork == null) {
        // swarm node used network id
        containerNetwork = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkId);
    }
    assertThat(containerNetwork, notNullValue());
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:22,
代码来源:CreateContainerCmdIT.java

示例4: createNetworkWithIpamConfig

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createNetworkWithIpamConfig() throws DockerException {
    assumeNotSwarm("no network in swarm", dockerRule);

    String networkName = "networkIpam" + dockerRule.getKind();
    String subnet = getFactoryType() == FactoryType.JERSEY ? "10.67.79.0/24" : "10.67.90.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());
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:18,
代码来源:CreateNetworkCmdIT.java

示例5: forceDisconnectFromNetwork

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void forceDisconnectFromNetwork() throws InterruptedException {
    assumeNotSwarm("no network in swarm", dockerRule);

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName("testNetwork2" + dockerRule.getKind()).exec();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
            .withNetworkMode("testNetwork2" + dockerRule.getKind())
            .withCmd("sleep", "9999")
            .exec();

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    dockerRule.getClient().disconnectFromNetworkCmd()
            .withNetworkId(network.getId())
            .withContainerId(container.getId())
            .withForce(true)
            .exec();

    Network updatedNetwork = dockerRule.getClient().inspectNetworkCmd().withNetworkId(network.getId()).exec();
    assertFalse(updatedNetwork.getContainers().containsKey(container.getId()));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:23,
代码来源:DisconnectFromNetworkCmdIT.java

示例6: createNetwork

点赞 3

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
public String createNetwork(String id, Network network) {
    this.readWriteLock.readLock().lock();
    try {
        final CreateNetworkCmd createNetworkCmd = this.dockerClient.createNetworkCmd().withName(id);

        if (network.getDriver() != null) {
            createNetworkCmd.withDriver(network.getDriver());
        }

        if (network.getIpam() != null) {
            createNetworkCmd.withIpam(new com.github.dockerjava.api.model.Network.Ipam().withConfig(
                createIpamConfig(network)));
        }

        if (network.getOptions() != null && !network.getOptions().isEmpty()) {
            createNetworkCmd.withOptions(network.getOptions());
        }

        final CreateNetworkResponse exec = createNetworkCmd.exec();
        return exec.getId();
    } finally {
        this.readWriteLock.readLock().unlock();
    }
}
 

开发者ID:arquillian,
项目名称:arquillian-cube,
代码行数:25,
代码来源:DockerClientExecutor.java

示例7: createNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
public static String createNetwork(String subnet) {
  CreateNetworkResponse createNetworkResponse =
      dockerClient
          .createNetworkCmd()
          .withName(subnet)
          .withCheckDuplicate(true)
          .withIpam(new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet(subnet)))
          .exec();
  return createNetworkResponse.getId();
}
 

开发者ID:scalecube,
项目名称:docker-utils,
代码行数:11,
代码来源:Containers.java

示例8: execute

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Override
protected CreateNetworkResponse execute(CreateNetworkCmd command) {
    WebTarget webResource = getBaseResource().path("/networks/create");

    LOGGER.trace("POST: {}", webResource);
    return webResource.request().accept(MediaType.APPLICATION_JSON)
            .post(entity(command, MediaType.APPLICATION_JSON), CreateNetworkResponse.class);
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:9,
代码来源:CreateNetworkCmdExec.java

示例9: execute

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Override
protected CreateNetworkResponse execute(CreateNetworkCmd command) {
    WebTarget webResource = getBaseResource().path("/networks/create");

    LOGGER.trace("POST: {}", webResource);
    return webResource.request().accept(MediaType.APPLICATION_JSON)
            .post(command, new TypeReference<CreateNetworkResponse>() {
            });
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:10,
代码来源:CreateNetworkCmdExec.java

示例10: createContainerWithCustomIp

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createContainerWithCustomIp() throws DockerException {
    String containerName1 = "containerCustomIplink_" + dockerRule.getKind();
    String networkName = "customIpNet" + dockerRule.getKind();
    String subnetPrefix = getFactoryType() == JERSEY ? "10.100.104" : "10.100.105";

    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
            .withIpam(new Network.Ipam()
                    .withConfig(new Network.Ipam.Config()
                            .withSubnet(subnetPrefix + ".0/24")))
            .withDriver("bridge")
            .withName(networkName)
            .exec();

    assertNotNull(createNetworkResponse.getId());

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withNetworkMode(networkName)
            .withCmd("sleep", "9999")
            .withName(containerName1)
            .withIpv4Address(subnetPrefix +".100")
            .exec();

    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient()
            .inspectContainerCmd(container.getId())
            .exec();

    ContainerNetwork customIpNet = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
    assertNotNull(customIpNet);
    assertThat(customIpNet.getGateway(), is(subnetPrefix + ".1"));
    assertThat(customIpNet.getIpAddress(), is(subnetPrefix + ".100"));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:37,
代码来源:CreateContainerCmdIT.java

示例11: createContainerWithAlias

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createContainerWithAlias() throws DockerException {
    String containerName1 = "containerAlias_" + dockerRule.getKind();
    String networkName = "aliasNet" + dockerRule.getKind();

    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
            .withName(networkName)
            .withDriver("bridge")
            .exec();

    assertNotNull(createNetworkResponse.getId());

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withNetworkMode(networkName)
            .withCmd("sleep", "9999")
            .withName(containerName1)
            .withAliases("server" + dockerRule.getKind())
            .exec();

    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId())
            .exec();

    ContainerNetwork aliasNet = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
    assertThat(aliasNet.getAliases(), hasItem("server" + dockerRule.getKind()));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:30,
代码来源:CreateContainerCmdIT.java

示例12: createNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createNetwork() throws DockerException {
    assumeNotSwarm("no network in swarm", dockerRule);

    String networkName = "createNetwork" + dockerRule.getKind();

    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).exec();

    assertNotNull(createNetworkResponse.getId());

    Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    assertThat(network.getName(), is(networkName));
    assertThat(network.getDriver(), is("bridge"));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:15,
代码来源:CreateNetworkCmdIT.java

示例13: createAttachableNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createAttachableNetwork() throws DockerException {
    assumeThat("API version should be > 1.24", dockerRule, isGreaterOrEqual(VERSION_1_25));

    String networkName = "createAttachableNetwork" + dockerRule.getKind();
    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
            .withName(networkName)
            .withAttachable(true)
            .exec();
    assertNotNull(createNetworkResponse.getId());
    Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    assertThat(network, notNullValue());
    assertTrue(network.isAttachable());
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:15,
代码来源:CreateNetworkCmdIT.java

示例14: createNetworkWithLabel

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createNetworkWithLabel() throws DockerException {
    assumeNotSwarm("no network in swarm?", dockerRule);
    assumeThat("API version should be >= 1.21", dockerRule, isGreaterOrEqual(VERSION_1_21));

    String networkName = "createNetworkWithLabel" + dockerRule.getKind();
    Map<String, String> labels = new HashMap<>();
    labels.put("com.example.usage" + dockerRule.getKind(), "test");
    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd().withName(networkName).withLabels(labels).exec();
    assertNotNull(createNetworkResponse.getId());
    Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
    assertEquals(network.getLabels(), labels);
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:14,
代码来源:CreateNetworkCmdIT.java

示例15: createCreateNetworkCmdExec

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Override
public CreateNetworkCmd.Exec createCreateNetworkCmdExec() {

    return new CreateNetworkCmd.Exec() {
        @Override
        public CreateNetworkResponse exec(CreateNetworkCmd command) {
            CreateNetworkResponse result = delegate.createCreateNetworkCmdExec().exec(command);
            networkIds.add(result.getId());
            return result;
        }
    };
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:13,
代码来源:TestDockerCmdExecFactory.java

示例16: CreateNetworkCmdImpl

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
public CreateNetworkCmdImpl(DockerCmdSyncExec<CreateNetworkCmd, CreateNetworkResponse> execution) {
    super(execution);
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:4,
代码来源:CreateNetworkCmdImpl.java

示例17: createContainerWithLinkInCustomNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void createContainerWithLinkInCustomNetwork() throws DockerException {
    String containerName1 = "containerCustomlink_" + dockerRule.getKind();
    String containerName2 = "containerCustom2link_" + dockerRule.getKind();
    String networkName = "linkNetcustom" + dockerRule.getKind();

    CreateNetworkResponse createNetworkResponse = dockerRule.getClient().createNetworkCmd()
            .withName(networkName)
            .withDriver("bridge")
            .exec();

    assertNotNull(createNetworkResponse.getId());

    CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withNetworkMode(networkName)
            .withCmd("sleep", "9999")
            .withName(containerName1)
            .exec();

    assertThat(container1.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container1.getId()).exec();

    InspectContainerResponse inspectContainerResponse1 = dockerRule.getClient().inspectContainerCmd(container1.getId())
            .exec();
    LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
    assertThat(inspectContainerResponse1.getState().getRunning(), is(true));

    CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withNetworkMode(networkName)
            .withName(containerName2)
            .withCmd("env")
            .withLinks(new Link(containerName1, containerName1 + "Link"))
            .exec();

    LOG.info("Created container {}", container2.toString());
    assertThat(container2.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse2 = dockerRule.getClient().inspectContainerCmd(container2.getId())
            .exec();

    ContainerNetwork linkNet = inspectContainerResponse2.getNetworkSettings().getNetworks().get(networkName);
    assertNotNull(linkNet);
    assertThat(linkNet.getLinks(), equalTo(new Link[]{new Link(containerName1, containerName1 + "Link")}));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:46,
代码来源:CreateContainerCmdIT.java

示例18: connectToNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void connectToNetwork() throws InterruptedException {
    assumeNotSwarm("no network in swarm", dockerRule);
    String networkName = "connectToNetwork" + dockerRule.getKind();

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999").exec();
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName(networkName).exec();

    dockerRule.getClient().connectToNetworkCmd().withNetworkId(network.getId()).withContainerId(container.getId()).exec();

    Network updatedNetwork = dockerRule.getClient().inspectNetworkCmd().withNetworkId(network.getId()).exec();

    assertTrue(updatedNetwork.getContainers().containsKey(container.getId()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertNotNull(inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:21,
代码来源:ConnectToNetworkCmdIT.java

示例19: connectToNetworkWithContainerNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void connectToNetworkWithContainerNetwork() throws InterruptedException {
    assumeNotSwarm("no network in swarm", dockerRule);

    final String subnetPrefix = getFactoryType() == JERSEY ?  "10.100.102" : "10.100.103";
    final String networkName = "ContainerWithNetwork" + dockerRule.getKind();
    final String containerIp = subnetPrefix + ".100";

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
            .withCmd("sleep", "9999")
            .exec();

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    try {
        dockerRule.getClient().removeNetworkCmd(networkName).exec();
    } catch (DockerException ignore) {
    }

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd()
            .withName(networkName)
            .withIpam(new Network.Ipam()
                    .withConfig(new Network.Ipam.Config()
                            .withSubnet(subnetPrefix + ".0/24")))
            .exec();

    dockerRule.getClient().connectToNetworkCmd()
            .withNetworkId(network.getId())
            .withContainerId(container.getId())
            .withContainerNetwork(new ContainerNetwork()
                    .withAliases("aliasName" + dockerRule.getKind())
                    .withIpamConfig(new ContainerNetwork.Ipam()
                            .withIpv4Address(containerIp)))
            .exec();

    Network updatedNetwork = dockerRule.getClient().inspectNetworkCmd().withNetworkId(network.getId()).exec();

    Network.ContainerNetworkConfig containerNetworkConfig = updatedNetwork.getContainers().get(container.getId());
    assertNotNull(containerNetworkConfig);
    assertThat(containerNetworkConfig.getIpv4Address(), is(containerIp + "/24"));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    ContainerNetwork testNetwork = inspectContainerResponse.getNetworkSettings().getNetworks().get(networkName);
    assertNotNull(testNetwork);
    assertThat(testNetwork.getAliases(), hasItem("aliasName" + dockerRule.getKind()));
    assertThat(testNetwork.getGateway(), is(subnetPrefix + ".1"));
    assertThat(testNetwork.getIpAddress(), is(containerIp));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:50,
代码来源:ConnectToNetworkCmdIT.java

示例20: disconnectFromNetwork

点赞 2

import com.github.dockerjava.api.command.CreateNetworkResponse; //导入依赖的package包/类
@Test
public void disconnectFromNetwork() throws InterruptedException {
    assumeNotSwarm("no network in swarm", dockerRule);

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName("disconnectNetwork" + dockerRule.getKind()).exec();

    dockerRule.getClient().connectToNetworkCmd().withNetworkId(network.getId()).withContainerId(container.getId()).exec();

    Network updatedNetwork = dockerRule.getClient().inspectNetworkCmd().withNetworkId(network.getId()).exec();

    assertTrue(updatedNetwork.getContainers().containsKey(container.getId()));

    dockerRule.getClient().disconnectFromNetworkCmd().withNetworkId(network.getId()).withContainerId(container.getId()).exec();

    updatedNetwork = dockerRule.getClient().inspectNetworkCmd().withNetworkId(network.getId()).exec();

    assertFalse(updatedNetwork.getContainers().containsKey(container.getId()));
}
 

开发者ID:docker-java,
项目名称:docker-java,
代码行数:22,
代码来源:DisconnectFromNetworkCmdIT.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)