diff options
author | Eli W. Hunter <42009212+elihunter173@users.noreply.github.com> | 2020-07-28 10:37:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-28 10:37:56 -0400 |
commit | 4b399f576e219c8b407aaba7049e87f11beac716 (patch) | |
tree | ba54302dcc94856382bd88a6af522969102b79d4 /src | |
parent | 6cd1d7f93bd6f150341582a1b54087cefffdbf87 (diff) |
Add nano_cpus and memory_swap to ContainerOptions (#231)
* Add nano_cpus to ContainerOptionsBuilder
* Add memory_swap to ContainerOptionsBuilder
Diffstat (limited to 'src')
-rw-r--r-- | src/builder.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/builder.rs b/src/builder.rs index 5541605..c14cbb7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -742,8 +742,40 @@ impl ContainerOptionsBuilder { self } - /// Sets an integer value representing the container's - /// relative CPU weight versus other containers. + /// Total memory limit (memory + swap) in bytes. Set to -1 (default) to enable unlimited swap. + pub fn memory_swap( + &mut self, + memory_swap: i64, + ) -> &mut Self { + self.params + .insert("HostConfig.MemorySwap", json!(memory_swap)); + self + } + + /// CPU quota in units of 10<sup>-9</sup> CPUs. Set to 0 (default) for there to be no limit. + /// + /// For example, setting `nano_cpus` to `500_000_000` results in the container being allocated + /// 50% of a single CPU, while `2_000_000_000` results in the container being allocated 2 CPUs. + pub fn nano_cpus( + &mut self, + nano_cpus: u64, + ) -> &mut Self { + self.params.insert("HostConfig.NanoCpus", json!(nano_cpus)); + self + } + + /// CPU quota in units of CPUs. This is a wrapper around `nano_cpus` to do the unit conversion. + /// + /// See [`nano_cpus`](#method.nano_cpus). + pub fn cpus( + &mut self, + cpus: f64, + ) -> &mut Self { + self.nano_cpus((1_000_000_000.0 * cpus) as u64) + } + + /// Sets an integer value representing the container's relative CPU weight versus other + /// containers. pub fn cpu_shares( &mut self, cpu_shares: u32, |