diff options
author | Christian Breunig <christian@breunig.cc> | 2024-05-28 20:15:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-28 20:15:44 +0200 |
commit | f04776073d1e46cfd022e6daf8742e0968d50e4b (patch) | |
tree | faf2bd590e2ad890d7fb1de3e916647068e2409a /src/conf_mode | |
parent | 48e5266e2bca8d1d7a2ee4bacbe0e6628de3fa66 (diff) | |
parent | 74910564f82e2837cd7eb35ea21f07601e5f8f0d (diff) | |
download | vyos-1x-f04776073d1e46cfd022e6daf8742e0968d50e4b.tar.gz vyos-1x-f04776073d1e46cfd022e6daf8742e0968d50e4b.zip |
container: T6406: add CLI option for cpu-quota
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-x | src/conf_mode/container.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py index 91a10e891..ca09dff9f 100755 --- a/src/conf_mode/container.py +++ b/src/conf_mode/container.py @@ -16,6 +16,7 @@ import os +from decimal import Decimal from hashlib import sha256 from ipaddress import ip_address from ipaddress import ip_network @@ -127,6 +128,11 @@ def verify(container): f'locally. Please use "add container image {image}" to add it '\ f'to the system! Container "{name}" will not be started!') + if 'cpu_quota' in container_config: + cores = vyos.cpu.get_core_count() + if Decimal(container_config['cpu_quota']) > cores: + raise ConfigError(f'Cannot set limit to more cores than available "{name}"!') + if 'network' in container_config: if len(container_config['network']) > 1: raise ConfigError(f'Only one network can be specified for container "{name}"!') @@ -257,6 +263,7 @@ def verify(container): def generate_run_arguments(name, container_config): image = container_config['image'] + cpu_quota = container_config['cpu_quota'] memory = container_config['memory'] shared_memory = container_config['shared_memory'] restart = container_config['restart'] @@ -333,7 +340,7 @@ def generate_run_arguments(name, container_config): if 'allow_host_pid' in container_config: host_pid = '--pid host' - container_base_cmd = f'--detach --interactive --tty --replace {capabilities} ' \ + container_base_cmd = f'--detach --interactive --tty --replace {capabilities} --cpus {cpu_quota} ' \ f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \ f'--name {name} {hostname} {device} {port} {volume} {env_opt} {label} {uid} {host_pid}' |