X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.model.ContainerNetwork;
import com.github.dockerjava.core.RemoteApiVersion;

import javax.annotation.CheckForNull;
Expand All @@ -18,10 +19,15 @@ public interface ConnectToNetworkCmd extends SyncDockerCmd<Void> {
@CheckForNull
String getContainerId();

@CheckForNull
ContainerNetwork getContainerConfig();

ConnectToNetworkCmd withNetworkId(@Nonnull String networkId);

ConnectToNetworkCmd withContainerId(@Nonnull String containerId);

ConnectToNetworkCmd withContainerNetwork(@Nonnull ContainerNetwork endpointConfig);

interface Exec extends DockerCmdSyncExec<ConnectToNetworkCmd, Void> {
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.github.dockerjava.api.command;

import java.util.List;
import java.util.Map;

import javax.annotation.CheckForNull;

import com.github.dockerjava.api.exception.ConflictException;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Bind;
Expand All @@ -21,8 +16,15 @@
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.api.model.VolumesFrom;

import javax.annotation.CheckForNull;
import java.util.List;
import java.util.Map;

public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerResponse> {

@CheckForNull
List<String> getAliases();

@CheckForNull
Bind[] getBinds();

Expand Down Expand Up @@ -92,6 +94,12 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
@CheckForNull
String getImage();

@CheckForNull
String getIpv4Address();

@CheckForNull
String getIpv6Address();

@CheckForNull
Map<String, String> getLabels();

Expand Down Expand Up @@ -185,6 +193,18 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons
@CheckForNull
Boolean isTty();

/**
* Add network-scoped alias for the container
* @param aliases on ore more aliases
*/
CreateContainerCmd withAliases(String... aliases);

/**
* Add network-scoped alias for the container
* @param aliases on ore more aliases
*/
CreateContainerCmd withAliases(List<String> aliases);

CreateContainerCmd withAttachStderr(Boolean attachStderr);

CreateContainerCmd withAttachStdin(Boolean attachStdin);
Expand Down Expand Up @@ -304,6 +324,10 @@ public interface CreateContainerCmd extends SyncDockerCmd<CreateContainerRespons

CreateContainerCmd withImage(String image);

CreateContainerCmd withIpv4Address(String ipv4Address);

CreateContainerCmd withIpv6Address(String ipv6Address);

CreateContainerCmd withLabels(Map<String, String> labels);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.dockerjava.api.command;

import java.util.Map;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import com.github.dockerjava.api.model.Network;
import com.github.dockerjava.api.model.Network.Ipam;
import com.github.dockerjava.core.RemoteApiVersion;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.Map;

/**
* Create a network.
*
Expand All @@ -25,18 +24,36 @@ public interface CreateNetworkCmd extends SyncDockerCmd<CreateNetworkResponse> {
@CheckForNull
Network.Ipam getIpam();

@CheckForNull
Map<String, String> getOptions();

@CheckForNull
Boolean getCheckDuplicate();

@CheckForNull
Boolean getInternal();

@CheckForNull
Boolean getEnableIPv6();

/** The new network's name. Required. */
CreateNetworkCmd withName(@Nonnull String name);

/** Optional custom IP scheme for the network. */
CreateNetworkCmd withIpamConfig(Ipam.Config config);

/** Name of the network driver to use. Defaults to <code>bridge</code>. */
CreateNetworkCmd withDriver(String driver);

/** Ipam config, such es subnet, gateway and ip range of the network */
CreateNetworkCmd withIpam(Ipam ipam);

/** Driver specific options */
CreateNetworkCmd withOptions(Map<String, String> options);

CreateNetworkCmd withCheckDuplicate(boolean checkForDuplicate);

CreateNetworkCmd withInternal(boolean internal);

CreateNetworkCmd withEnableIpv6(boolean enableIpv6);

interface Exec extends DockerCmdSyncExec<CreateNetworkCmd, CreateNetworkResponse> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ public interface DisconnectFromNetworkCmd extends SyncDockerCmd<Void> {
@CheckForNull
String getContainerId();

@CheckForNull
Boolean getForce();

DisconnectFromNetworkCmd withNetworkId(@Nonnull String networkId);

DisconnectFromNetworkCmd withContainerId(@Nonnull String containerId);

DisconnectFromNetworkCmd withForce(@Nonnull Boolean force);

interface Exec extends DockerCmdSyncExec<DisconnectFromNetworkCmd, Void> {
}
}
73 changes: 63 additions & 10 deletions src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.dockerjava.core.RemoteApiVersion;
Expand All @@ -8,9 +9,14 @@
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.annotation.CheckForNull;
import java.util.Arrays;
import java.util.List;

/**
* Types taken form
* {@see https://github.com/docker/engine-api/blob/release/1.10/types/network/network.go}
* Docker named it EndpointSettings
*
* @see ContainerNetworkSettings
* @author Kanstantsin Shautsou
*/
Expand All @@ -20,16 +26,16 @@ public class ContainerNetwork {
* FIXME verify
*/
@JsonProperty("IPAMConfig")
private Network.Ipam.Config ipamConfig;
private Ipam ipamConfig;

/**
* FIXME verify
*/
@JsonProperty("Links")
private List<String> links;
private Links links;

/**
* FIXME no docs, unknown field.
* Add network-scoped alias for the container
* Type picked from `docker/vendor/src/github.com/docker/engine-api/types/network/network.go`
*
* @since {@link RemoteApiVersion#VERSION_1_22}
Expand Down Expand Up @@ -80,6 +86,14 @@ public ContainerNetwork withAliases(List<String> aliases) {
return this;
}

/**
* @see #aliases
*/
public ContainerNetwork withAliases(String... aliases) {
this.aliases = Arrays.asList(aliases);
return this;
}

/**
* @see #endpointId
*/
Expand Down Expand Up @@ -155,7 +169,7 @@ public String getIpAddress() {
/**
* @see #ipAddress
*/
public ContainerNetwork withIpAddress(String ipAddress) {
public ContainerNetwork withIpv4Address(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
Expand All @@ -164,14 +178,14 @@ public ContainerNetwork withIpAddress(String ipAddress) {
* @see #ipamConfig
*/
@CheckForNull
public Network.Ipam.Config getIpamConfig() {
public Ipam getIpamConfig() {
return ipamConfig;
}

/**
* @see #ipamConfig
*/
public ContainerNetwork withIpamConfig(Network.Ipam.Config ipamConfig) {
public ContainerNetwork withIpamConfig(Ipam ipamConfig) {
this.ipamConfig = ipamConfig;
return this;
}
Expand Down Expand Up @@ -212,15 +226,24 @@ public ContainerNetwork withIpV6Gateway(String ipV6Gateway) {
* @see #links
*/
@CheckForNull
public List<String> getLinks() {
return links;
@JsonIgnore
public Link[] getLinks() {
return links == null ? new Link[0] : links.getLinks();
}

/**
* @see #links
*/
public ContainerNetwork withLinks(List<Link> links) {
this.links = new Links(links);
return this;
}

/**
* @see #links
*/
public ContainerNetwork withLinks(List<String> links) {
this.links = links;
public ContainerNetwork withLinks(Link... links) {
this.links = new Links(links);
return this;
}

Expand Down Expand Up @@ -270,4 +293,34 @@ public boolean equals(Object o) {
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

/**
* Docker named it EndpointIPAMConfig
*/
public static class Ipam {

@JsonProperty("IPv4Address")
private String ipv4Address;

@JsonProperty("IPv6Address")
private String ipv6Address;

public String getIpv4Address() {
return ipv4Address;
}

public String getIpv6Address() {
return ipv6Address;
}

public Ipam withIpv4Address(String ipv4Address) {
this.ipv4Address = ipv4Address;
return this;
}

public Ipam withIpv6Address(String ipv6Address) {
this.ipv6Address = ipv6Address;
return this;
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.annotation.CheckForNull;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -21,6 +22,8 @@
@JsonInclude(Include.NON_NULL)
public class HostConfig {

private static final List<String> PREDEFINED_NETWORKS = Arrays.asList("bridge", "host", "none");

@JsonProperty("Binds")
private Binds binds;

Expand Down Expand Up @@ -410,6 +413,15 @@ public String getVolumeDriver() {
return volumeDriver;
}

/**
* Parse the network mode as specified at
* {@see https://github.com/docker/engine-api/blob/master/types/container/hostconfig_unix.go}
*/
@JsonIgnore
public boolean isUserDefinedNetwork() {
return networkMode != null && !PREDEFINED_NETWORKS.contains(networkMode) && !networkMode.startsWith("container:");
}

@JsonIgnore
public void setBinds(Bind... binds) {
this.binds = new Binds(binds);
Expand Down
Loading
X Tutup