From 4cb31a38bcaabf255cb779be10bb23e0840460e4 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sat, 22 Dec 2018 23:32:19 +1300 Subject: Support for setting CPU shares/memory for image builder (#134) * Support for setting CPU shares/memory for image builder * Support for setting the number of CPU shares allocated to a container --- src/builder.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/builder.rs') diff --git a/src/builder.rs b/src/builder.rs index 9aaeb99..fbebeb7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -220,9 +220,23 @@ impl BuildOptionsBuilder { self } - // todo: memory + pub fn memory( + &mut self, + memory: u64, + ) -> &mut Self { + self.params.insert("memory", memory.to_string()); + self + } + + pub fn cpu_shares( + &mut self, + cpu_shares: u32, + ) -> &mut Self { + self.params.insert("cpushares", cpu_shares.to_string()); + self + } + // todo: memswap - // todo: cpushares // todo: cpusetcpus // todo: cpuperiod // todo: cpuquota @@ -481,6 +495,17 @@ impl ContainerOptionsBuilder { self } + /// Sets an integer value representing the container's + /// relative CPU weight versus other containers. + pub fn cpu_shares( + &mut self, + cpu_shares: u32, + ) -> &mut Self { + self.params + .insert("HostConfig.CpuShares", json!(cpu_shares)); + self + } + pub fn labels( &mut self, labels: &HashMap<&str, &str>, -- cgit v1.2.3