Skip to content

Commit 6527f4c

Browse files
committed
Merge pull request #105 from vjuranek/hostconfig
Allow to pass HostConfig when creating a container
2 parents 02d3911 + 356d10d commit 6527f4c

11 files changed

Lines changed: 280 additions & 128 deletions

File tree

src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.github.dockerjava.api.ConflictException;
44
import com.github.dockerjava.api.NotFoundException;
55
import com.github.dockerjava.api.model.ExposedPort;
6+
import com.github.dockerjava.api.model.HostConfig;
7+
import com.github.dockerjava.api.model.Links;
68
import com.github.dockerjava.api.model.Volume;
79

810
public interface CreateContainerCmd extends DockerCmd<CreateContainerResponse>{
@@ -94,6 +96,10 @@ public interface CreateContainerCmd extends DockerCmd<CreateContainerResponse>{
9496
public String[] getVolumesFrom();
9597

9698
public CreateContainerCmd withVolumesFrom(String... volumesFrom);
99+
100+
public HostConfig getHostConfig();
101+
102+
public CreateContainerCmd withHostConfig(HostConfig hostConfig);
97103

98104

99105
/**

src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -234,121 +234,5 @@ public String toString() {
234234
}
235235
}
236236

237-
@JsonIgnoreProperties(ignoreUnknown = true)
238-
public class HostConfig {
239-
240-
@JsonProperty("Binds")
241-
private String[] binds;
242-
243-
@JsonProperty("LxcConf")
244-
private LxcConf[] lxcConf;
245-
246-
@JsonProperty("PortBindings")
247-
private Ports portBindings;
248-
249-
@JsonProperty("PublishAllPorts")
250-
private boolean publishAllPorts;
251-
252-
@JsonProperty("Privileged")
253-
private boolean privileged;
254-
255-
@JsonProperty("Dns")
256-
private String[] dns;
257-
258-
@JsonProperty("DnsSearch")
259-
private String[] dnsSearch;
260-
261-
@JsonProperty("VolumesFrom")
262-
private String[] volumesFrom;
263-
264-
@JsonProperty("ContainerIDFile")
265-
private String containerIDFile;
266-
267-
// TODO: use Links class here?
268-
@JsonProperty("Links")
269-
private String[] links;
270-
271-
@JsonProperty("NetworkMode")
272-
private String networkMode;
273-
274-
@JsonProperty("Devices")
275-
private Device[] devices;
276-
277-
@JsonProperty("RestartPolicy")
278-
private RestartPolicy restartPolicy;
279-
280-
@JsonProperty("CapAdd")
281-
private String[] capAdd;
282-
283-
@JsonProperty("CapDrop")
284-
private String[] capDrop;
285-
286-
public String[] getBinds() {
287-
return binds;
288-
}
289-
290-
public LxcConf[] getLxcConf() {
291-
return lxcConf;
292-
}
293-
294-
public Ports getPortBindings() {
295-
return portBindings;
296-
}
297-
298-
public boolean isPublishAllPorts() {
299-
return publishAllPorts;
300-
}
301-
302-
public boolean isPrivileged() {
303-
return privileged;
304-
}
305-
306-
public String[] getDns() {
307-
return dns;
308-
}
309-
310-
public String[] getVolumesFrom() {
311-
return volumesFrom;
312-
}
313-
314-
public String getContainerIDFile() {
315-
return containerIDFile;
316-
}
317-
318-
public String[] getDnsSearch() {
319-
return dnsSearch;
320-
}
321-
322-
public String[] getLinks() {
323-
return links;
324-
}
325-
326-
public String getNetworkMode() {
327-
return networkMode;
328-
}
329-
330-
public Device[] getDevices() {
331-
return devices;
332-
}
333-
334-
public RestartPolicy getRestartPolicy() {
335-
return restartPolicy;
336-
}
337-
338-
public String[] getCapAdd() {
339-
return capAdd;
340-
}
341-
342-
public String[] getCapDrop() {
343-
return capDrop;
344-
}
345-
346-
@Override
347-
public String toString() {
348-
return ToStringBuilder.reflectionToString(this);
349-
}
350-
351-
}
352-
353237
}
354238

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import org.apache.commons.lang.builder.ToStringBuilder;
4+
5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class HostConfig {
10+
11+
@JsonProperty("Binds")
12+
private String[] binds;
13+
14+
@JsonProperty("Links")
15+
private Links links;
16+
17+
@JsonProperty("LxcConf")
18+
private LxcConf[] lxcConf;
19+
20+
@JsonProperty("PortBindings")
21+
private Ports portBindings;
22+
23+
@JsonProperty("PublishAllPorts")
24+
private boolean publishAllPorts;
25+
26+
@JsonProperty("Privileged")
27+
private boolean privileged;
28+
29+
@JsonProperty("Dns")
30+
private String[] dns;
31+
32+
@JsonProperty("DnsSearch")
33+
private String[] dnsSearch;
34+
35+
@JsonProperty("VolumesFrom")
36+
private String[] volumesFrom;
37+
38+
@JsonProperty("ContainerIDFile")
39+
private String containerIDFile;
40+
41+
@JsonProperty("CapAdd")
42+
private String[] capAdd;
43+
44+
@JsonProperty("CapDrop")
45+
private String[] capDrop;
46+
47+
@JsonProperty("RestartPolicy")
48+
private RestartPolicy restartPolicy;
49+
50+
@JsonProperty("NetworkMode")
51+
private String networkMode;
52+
53+
@JsonProperty("Devices")
54+
private Device[] devices;
55+
56+
public HostConfig() {
57+
}
58+
59+
public HostConfig(String[] binds, Links links, LxcConf[] lxcConf, Ports portBindings, boolean publishAllPorts,
60+
boolean privileged, String[] dns, String[] dnsSearch, String[] volumesFrom, String containerIDFile,
61+
String[] capAdd, String[] capDrop, RestartPolicy restartPolicy, String networkMode, Device[] devices) {
62+
this.binds = binds;
63+
this.links = links;
64+
this.lxcConf = lxcConf;
65+
this.portBindings = portBindings;
66+
this.publishAllPorts = publishAllPorts;
67+
this.privileged = privileged;
68+
this.dns = dns;
69+
this.dnsSearch = dnsSearch;
70+
this.volumesFrom = volumesFrom;
71+
this.containerIDFile = containerIDFile;
72+
this.capAdd = capAdd;
73+
this.capDrop = capDrop;
74+
this.restartPolicy = restartPolicy;
75+
this.networkMode = networkMode;
76+
this.devices = devices;
77+
}
78+
79+
public String[] getBinds() {
80+
return binds;
81+
}
82+
83+
public LxcConf[] getLxcConf() {
84+
return lxcConf;
85+
}
86+
87+
public Ports getPortBindings() {
88+
return portBindings;
89+
}
90+
91+
public boolean isPublishAllPorts() {
92+
return publishAllPorts;
93+
}
94+
95+
public boolean isPrivileged() {
96+
return privileged;
97+
}
98+
99+
public String[] getDns() {
100+
return dns;
101+
}
102+
103+
public String[] getVolumesFrom() {
104+
return volumesFrom;
105+
}
106+
107+
public String getContainerIDFile() {
108+
return containerIDFile;
109+
}
110+
111+
public String[] getDnsSearch() {
112+
return dnsSearch;
113+
}
114+
115+
public Links getLinks() {
116+
return links;
117+
}
118+
119+
public String getNetworkMode() {
120+
return networkMode;
121+
}
122+
123+
public Device[] getDevices() {
124+
return devices;
125+
}
126+
127+
public RestartPolicy getRestartPolicy() {
128+
return restartPolicy;
129+
}
130+
131+
public String[] getCapAdd() {
132+
return capAdd;
133+
}
134+
135+
public String[] getCapDrop() {
136+
return capDrop;
137+
}
138+
139+
public void setBinds(String[] binds) {
140+
this.binds = binds;
141+
}
142+
143+
public void setLinks(Links links) {
144+
this.links = links;
145+
}
146+
147+
public void setLxcConf(LxcConf[] lxcConf) {
148+
this.lxcConf = lxcConf;
149+
}
150+
151+
public void setPortBindings(Ports portBindings) {
152+
this.portBindings = portBindings;
153+
}
154+
155+
public void setPublishAllPorts(boolean publishAllPorts) {
156+
this.publishAllPorts = publishAllPorts;
157+
}
158+
159+
public void setPrivileged(boolean privileged) {
160+
this.privileged = privileged;
161+
}
162+
163+
public void setDns(String[] dns) {
164+
this.dns = dns;
165+
}
166+
167+
public void setDnsSearch(String[] dnsSearch) {
168+
this.dnsSearch = dnsSearch;
169+
}
170+
171+
public void setVolumesFrom(String[] volumesFrom) {
172+
this.volumesFrom = volumesFrom;
173+
}
174+
175+
public void setContainerIDFile(String containerIDFile) {
176+
this.containerIDFile = containerIDFile;
177+
}
178+
179+
public void setCapAdd(String[] capAdd) {
180+
this.capAdd = capAdd;
181+
}
182+
183+
public void setCapDrop(String[] capDrop) {
184+
this.capDrop = capDrop;
185+
}
186+
187+
public void setRestartPolicy(RestartPolicy restartPolicy) {
188+
this.restartPolicy = restartPolicy;
189+
}
190+
191+
public void setNetworkMode(String networkMode) {
192+
this.networkMode = networkMode;
193+
}
194+
195+
public void setDevices(Device[] devices) {
196+
this.devices = devices;
197+
}
198+
199+
@Override
200+
public String toString() {
201+
return ToStringBuilder.reflectionToString(this);
202+
}
203+
204+
}

src/main/java/com/github/dockerjava/api/model/Link.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String getAlias()
5353
/**
5454
* Parses a textual link specification (as used by the Docker CLI) to a {@link Link}.
5555
*
56-
* @param serialized the specification, e.g. <code>name:alias</code>
56+
* @param serialized the specification, e.g. <code>name:alias</code> or <code>/name1:/name2/alias</code>
5757
* @return a {@link Link} matching the specification
5858
* @throws IllegalArgumentException if the specification cannot be parsed
5959
*/
@@ -63,7 +63,9 @@ public static Link parse(final String serialized) throws IllegalArgumentExceptio
6363
final String[] parts = serialized.split(":");
6464
switch (parts.length) {
6565
case 2: {
66-
return new Link(parts[0], parts[1]);
66+
String[] nameSplit = parts[0].split("/");
67+
String[] aliasSplit = parts[1].split("/");
68+
return new Link(nameSplit[nameSplit.length - 1], aliasSplit[aliasSplit.length - 1]);
6769
}
6870
default: {
6971
throw new IllegalArgumentException();

src/main/java/com/github/dockerjava/api/model/Links.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public Links deserialize(final JsonParser jsonParser, final DeserializationConte
6161
final List<Link> binds = new ArrayList<Link>();
6262
final ObjectCodec oc = jsonParser.getCodec();
6363
final JsonNode node = oc.readTree(jsonParser);
64-
for (final Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
64+
for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) {
6565

66-
final Map.Entry<String, JsonNode> field = it.next();
67-
if (!field.getValue().equals(NullNode.getInstance())) {
68-
binds.add(Link.parse(field.getKey()));
66+
final JsonNode element = it.next();
67+
if (!element.equals(NullNode.getInstance())) {
68+
binds.add(Link.parse(element.asText()));
6969
}
7070
}
7171
return new Links(binds.toArray(new Link[0]));

src/main/java/com/github/dockerjava/api/model/PortBinding.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.apache.commons.lang.builder.EqualsBuilder;
55
import org.apache.commons.lang.builder.HashCodeBuilder;
66

7-
import com.github.dockerjava.api.command.InspectContainerResponse.HostConfig;
87
import com.github.dockerjava.api.command.InspectContainerResponse.NetworkSettings;
98
import com.github.dockerjava.api.model.Ports.Binding;
109

src/main/java/com/github/dockerjava/api/model/Ports.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2424
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2525
import com.fasterxml.jackson.databind.node.NullNode;
26-
import com.github.dockerjava.api.command.InspectContainerResponse.HostConfig;
2726
import com.github.dockerjava.api.command.InspectContainerResponse.NetworkSettings;
2827

2928
/**

0 commit comments

Comments
 (0)