From 4b399f576e219c8b407aaba7049e87f11beac716 Mon Sep 17 00:00:00 2001 From: "Eli W. Hunter" <42009212+elihunter173@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:37:56 -0400 Subject: Add nano_cpus and memory_swap to ContainerOptions (#231) * Add nano_cpus to ContainerOptionsBuilder * Add memory_swap to ContainerOptionsBuilder --- src/builder.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/builder.rs') 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-9 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, -- cgit v1.2.3