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

Commit

Permalink
Add cpus options for host config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsvinha committed Jun 3, 2018
1 parent 4877a1e commit 8e89a83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public abstract class HostConfig {
@JsonProperty("CpusetMems")
public abstract String cpusetMems();

@Nullable

@JsonProperty("Cpus")
public abstract Float cpus();

@Nullable
@JsonProperty("CpuQuota")
public abstract Long cpuQuota();
Expand Down Expand Up @@ -269,6 +274,7 @@ static HostConfig create(
@JsonProperty("MemorySwap") final Long memorySwap,
@JsonProperty("MemorySwappiness") final Integer memorySwappiness,
@JsonProperty("MemoryReservation") final Long memoryReservation,
@JsonProperty("Cpus") final Float cpus,
@JsonProperty("NanoCpus") final Long nanoCpus,
@JsonProperty("CpuPeriod") final Long cpuPeriod,
@JsonProperty("CpuShares") final Long cpuShares,
Expand Down Expand Up @@ -317,6 +323,7 @@ static HostConfig create(
.memorySwap(memorySwap)
.memorySwappiness(memorySwappiness)
.memoryReservation(memoryReservation)
.cpus(cpus)
.nanoCpus(nanoCpus)
.cpuPeriod(cpuPeriod)
.cpuShares(cpuShares)
Expand Down Expand Up @@ -566,6 +573,8 @@ private static <T> ImmutableList<T> copyWithoutDuplicates(final List<T> input) {

public abstract Builder memoryReservation(Long memoryReservation);

public abstract Builder cpus(Float cpus);

public abstract Builder nanoCpus(Long nanoCpus);

public abstract Builder cpuPeriod(Long cpuPeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,30 @@ public void testNanoCpus() throws Exception {
assertThat(hostConfig.nanoCpus(), is(nanoCpus.longValue()));
}

@Test
public void testCpus() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);

final HostConfig hostConfig = HostConfig.builder()
.cpus((float)1.5)
.build();
final ContainerConfig containerConfig = ContainerConfig.builder()
.hostConfig(hostConfig)
.build();

server.enqueue(new MockResponse());

dockerClient.createContainer(containerConfig);

final RecordedRequest recordedRequest = takeRequestImmediately();

final JsonNode requestJson = toJson(recordedRequest.getBody());
final JsonNode cpus = requestJson.get("HostConfig").get("Cpus");

assertThat(hostConfig.cpus(), is(cpus.floatValue()));
assertThat(hostConfig.cpus(), is((float)1.5));
}

@Test
public void testInspectNode() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
Expand Down

0 comments on commit 8e89a83

Please sign in to comment.