Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Add Ipam.options()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxia committed Jul 29, 2017
1 parent ae5277c commit 73980f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/main/java/com/spotify/docker/client/messages/Ipam.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

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

import javax.annotation.Nullable;

Expand All @@ -44,6 +47,10 @@ public abstract class Ipam {
@JsonProperty("Config")
public abstract ImmutableList<IpamConfig> config();

@Nullable
@JsonProperty("Options")
public abstract ImmutableMap<String, String> options();

public static Builder builder() {
return new AutoValue_Ipam.Builder();
}
Expand All @@ -55,6 +62,8 @@ public abstract static class Builder {

public abstract Builder config(List<IpamConfig> config);

public abstract Builder options(Map<String, String> options);

/**
* @deprecated As of release 7.0.0, replaced by {@link #config(List)}.
*/
Expand All @@ -66,13 +75,23 @@ public Builder config(final String subnet, final String ipRange, final String ga
public abstract Ipam build();
}

public static Ipam create(final String driver, final List<IpamConfig> config) {
return builder()
.driver(driver)
.config(config)
.options(null)
.build();
}

@JsonCreator
public static Ipam create(
@JsonProperty("Driver") final String driver,
@JsonProperty("Config") final List<IpamConfig> config) {
@JsonProperty("Config") final List<IpamConfig> config,
@JsonProperty("Options") final Map<String, String> options) {
return builder()
.driver(driver)
.config(config)
.options(options)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.hamcrest.Matchers.nullValue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.spotify.docker.client.ObjectMapperProvider;

import org.junit.Test;
Expand All @@ -42,6 +43,7 @@ public void testDeserialize() throws Exception {
objectMapper.readValue(fixture("fixtures/1.29/ipam.json"), Ipam.class);
assertThat(ipam.driver(), equalTo("default"));
assertThat(ipam.config(), contains(IpamConfig.create("172.17.0.0/16", null, null)));
assertThat(ipam.options(), equalTo(ImmutableMap.of("foo", "bar")));
}

@Test
Expand Down
5 changes: 4 additions & 1 deletion src/test/resources/fixtures/1.29/ipam.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
{
"Subnet": "172.17.0.0/16"
}
]
],
"Options": {
"foo": "bar"
}
}

0 comments on commit 73980f0

Please sign in to comment.