module

Krikri::PluginHelpers::DockerResources

DockerResources - pure logic for parsing docker_container's memory/cpu resource-limit params. No I/O here - docker_container.cr does the actual API calls.

Constants

SIZE_RANGES = {"P" => 1_i64 << 50, "T" => 1_i64 << 40, "G" => 1_i64 << 30, "M" => 1_i64 << 20, "K" => 1_i64 << 10, "B" => 1_i64}

Binary (1024-based) size suffixes, matching real Ansible's own human_to_bytes (SIZE_RANGES in ansible/module_utils/common/text/formatters.py) - K/M/G/T/P are KiB/MiB/GiB/TiB/PiB despite the non-"i" spelling, not decimal 1000-based units.

Class methods

cpus_to_nano_cpus(cpus : Float64) : Int64

Matches real Ansible's own _preprocess_cpus: cpus: is a float number of CPUs, converted to Docker's own NanoCpus (nanocpus = cpus * 1e9, rounded).

Source
human_to_bytes(value : String) : Int64

Matches real Ansible's own human_to_bytes: a bare number with no unit suffix is returned as-is (already bytes); a number followed by a unit letter (only the first letter matters - "MB"/ "M" are equivalent, matching the real function's own unit[0].upper()) is converted. Raises with the real function's own error message shape on anything unparseable.

Source
memory_swap_to_bytes(value : String) : Int64

memory_swap: alone among the byte-size params also accepts the literal strings "unlimited"/"-1" for unlimited swap (real Ansible's own documented convention, matching _preprocess_convert_to_bytes(..., unlimited_value=-1)).

Source