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

Add --cpus options to a container #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -175,6 +175,10 @@ 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 +273,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 +322,7 @@ static HostConfig create(
.memorySwap(memorySwap)
.memorySwappiness(memorySwappiness)
.memoryReservation(memoryReservation)
.cpus(cpus)
.nanoCpus(nanoCpus)
.cpuPeriod(cpuPeriod)
.cpuShares(cpuShares)
Expand Down Expand Up @@ -566,6 +572,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