本文整理汇总了Java中com.github.dockerjava.api.model.Network类的典型用法代码示例。如果您正苦于以下问题:Java Network类的具体用法?Java Network怎么用?Java Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Network类属于com.github.dockerjava.api.model包,在下文中一共展示了Network类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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: execute
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Override
protected List<Network> execute(ListNetworksCmd command) {
WebTarget webTarget = getBaseResource().path("/networks");
if (command.getFilters() != null && !command.getFilters().isEmpty()) {
webTarget = webTarget
.queryParam("filters", urlPathSegmentEscaper().escape(FiltersEncoder.jsonEncode(command.getFilters())));
}
LOGGER.trace("GET: {}", webTarget);
List<Network> networks = webTarget.request().accept(MediaType.APPLICATION_JSON)
.get(new GenericType<List<Network>>() {
});
LOGGER.trace("Response: {}", networks);
return networks;
}
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:ListNetworksCmdExec.java
示例3: inspectNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Test
public void inspectNetwork() throws DockerException {
assumeNotSwarm("no network in swarm", dockerRule);
List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();
Network expected = findNetwork(networks, "bridge");
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(expected.getId()).exec();
assertThat(network.getName(), equalTo(expected.getName()));
assertThat(network.getScope(), equalTo(expected.getScope()));
assertThat(network.getDriver(), equalTo(expected.getDriver()));
assertThat(network.getIpam().getConfig().get(0).getSubnet(), equalTo(expected.getIpam().getConfig().get(0).getSubnet()));
assertThat(network.getIpam().getDriver(), equalTo(expected.getIpam().getDriver()));
}
开发者ID:docker-java,项目名称:docker-java,代码行数:17,代码来源:InspectNetworkCmdIT.java
示例4: testUpdateServiceReplicate
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Test
public void testUpdateServiceReplicate() {
DockerClient docker1 = startDockerInDocker();
docker1.initializeSwarmCmd(new SwarmSpec()).exec();
//create network
String networkId = docker1.createNetworkCmd().withName("networkname").withDriver("overlay")
.withIpam(new Network.Ipam().withDriver("default")).exec().getId();
TaskSpec taskSpec = new TaskSpec().withContainerSpec(
new ContainerSpec().withImage("busybox").withArgs(Arrays.asList("sleep", "3600")));
ServiceSpec serviceSpec = new ServiceSpec()
.withMode(new ServiceModeConfig().withReplicated(new ServiceReplicatedModeOptions().withReplicas(1)))
.withTaskTemplate(taskSpec)
.withNetworks(Lists.newArrayList(new NetworkAttachmentConfig().withTarget(networkId)))
.withName("worker");
String serviceId = docker1.createServiceCmd(serviceSpec).exec().getId();
//list the service
List<Service> services = docker1.listServicesCmd().withIdFilter(Arrays.asList(serviceId)).exec();
assertThat(services.size(), is(1));
Service service = services.get(0);
ServiceSpec updateServiceSpec = service.getSpec()
.withMode(new ServiceModeConfig().withReplicated(new ServiceReplicatedModeOptions().withReplicas(2)));
docker1.updateServiceCmd(service.getId(), updateServiceSpec).withVersion(service.getVersion().getIndex()).exec();
//verify the replicate
Service updateService = docker1.listServicesCmd().withIdFilter(Arrays.asList(serviceId)).exec().get(0);
assertThat(updateService.getSpec().getMode().getReplicated().getReplicas(), is(2L));
}
开发者ID:docker-java,项目名称:docker-java,代码行数:27,代码来源:UpdateSwarmServiceIT.java
示例5: removeNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例6: createNetworkWithIpamConfig
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例7: forceDisconnectFromNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例8: createNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例9: createDockerTestNetworkIfNeeded
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
public static void createDockerTestNetworkIfNeeded(DockerImpl docker) {
if (! docker.dockerClient.listNetworksCmd().withNameFilter(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return;
Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config()
.withSubnet("172.18.0.0/16")
.withGateway("172.18.0.1"));
docker.dockerClient.createNetworkCmd()
.withName(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).withDriver("bridge").withIpam(ipam).exec();
}
开发者ID:vespa-engine,项目名称:vespa,代码行数:10,代码来源:DockerTestUtils.java
示例10: setupDockerNetworkIfNeeded
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
private void setupDockerNetworkIfNeeded() throws IOException {
if (!dockerClient.listNetworksCmd().withNameFilter(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return;
// Use IPv6 address if there is a mix of IP4 and IPv6 by taking the longest address.
List<InetAddress> hostAddresses = Arrays.asList(InetAddress.getAllByName(com.yahoo.net.HostName.getLocalhost()));
InetAddress hostAddress = Collections.max(hostAddresses,
(o1, o2) -> o1.getAddress().length - o2.getAddress().length);
NetworkAddressInterface networkAddressInterface = DockerNetworkCreator.getInterfaceForAddress(hostAddress);
boolean isIPv6 = networkAddressInterface.interfaceAddress.getAddress() instanceof Inet6Address;
Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config()
.withSubnet(hostAddress.getHostAddress() + "/" + networkAddressInterface.interfaceAddress.getNetworkPrefixLength())
.withGateway(DockerNetworkCreator.getDefaultGatewayLinux(isIPv6).getHostAddress()));
Map<String, String> dockerNetworkOptions = new HashMap<>();
dockerNetworkOptions.put("parent", networkAddressInterface.networkInterface.getDisplayName());
dockerNetworkOptions.put("macvlan_mode", "bridge");
dockerClient.createNetworkCmd()
.withName(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME)
.withDriver("macvlan")
.withEnableIpv6(isIPv6)
.withIpam(ipam)
.withOptions(dockerNetworkOptions)
.exec();
}
开发者ID:vespa-engine,项目名称:vespa,代码行数:28,代码来源:DockerImpl.java
示例11: execute
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Override
protected Network execute(InspectNetworkCmd command) {
WebTarget webResource = getBaseResource().path("/networks/{id}").resolveTemplate("id",
command.getNetworkId());
LOGGER.debug("GET: {}", webResource);
return webResource.request().accept(MediaType.APPLICATION_JSON).get(Network.class);
}
开发者ID:docker-java,项目名称:docker-java,代码行数:10,代码来源:InspectNetworkCmdExec.java
示例12: execute
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Override
protected List<Network> execute(ListNetworksCmd command) {
WebTarget webTarget = getBaseResource().path("/networks");
if (command.getFilters() != null && !command.getFilters().isEmpty()) {
webTarget = webTarget.queryParam("filters", FiltersEncoder.jsonEncode(command.getFilters()));
}
LOGGER.trace("GET: {}", webTarget);
return webTarget.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<List<Network>>() {
});
}
开发者ID:docker-java,项目名称:docker-java,代码行数:14,代码来源:ListNetworksCmdExec.java
示例13: execute
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Override
protected Network execute(InspectNetworkCmd command) {
WebTarget webResource = getBaseResource().path("/networks/{id}").resolveTemplate("id", command.getNetworkId());
LOGGER.trace("GET: {}", webResource);
return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<Network>() {
});
}
开发者ID:docker-java,项目名称:docker-java,代码行数:9,代码来源:InspectNetworkCmdExec.java
示例14: findNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
public static Network findNetwork(List<Network> networks, String name) {
for (Network network : networks) {
if (StringUtils.equals(network.getName(), name)) {
return network;
}
}
throw new AssertionError("No network found.");
}
开发者ID:docker-java,项目名称:docker-java,代码行数:11,代码来源:TestUtils.java
示例15: listNetworks
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Test
public void listNetworks() throws DockerException {
assumeNotSwarm("Swarm has no network", dockerRule);
List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();
Network network = TestUtils.findNetwork(networks, "bridge");
assertThat(network.getName(), equalTo("bridge"));
assertThat(network.getScope(), equalTo("local"));
assertThat(network.getDriver(), equalTo("bridge"));
assertThat(network.getIpam().getDriver(), equalTo("default"));
}
开发者ID:docker-java,项目名称:docker-java,代码行数:14,代码来源:ListNetworksCmdIT.java
示例16: createContainerWithCustomIp
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例17: createNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例18: createAttachableNetwork
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例19: createNetworkWithLabel
import com.github.dockerjava.api.model.Network; //导入依赖的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
示例20: network_should_be_used_provided_ipam
import com.github.dockerjava.api.model.Network; //导入依赖的package包/类
@Test
public void network_should_be_used_provided_ipam() {
final Network app_net = dockerClient.inspectNetworkCmd().withNetworkId("app_net").exec();
assertThat(app_net.getIpam().getDriver()).isEqualTo("default");
assertThat(app_net.getIpam().getConfig()).extracting("subnet", "gateway")
.contains(Tuple.tuple("172.16.238.0/24", "172.16.238.1"),
Tuple.tuple("2001:3984:3989::/64", "2001:3984:3989::1"));
}
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:9,代码来源:PingPongIT.java
注:本文中的com.github.dockerjava.api.model.Network类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论