MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / build_resource_limits

Function build_resource_limits

crates/openshell-driver-podman/src/container.rs:452–477  ·  view source on GitHub ↗

Parse resource limits from the sandbox template, falling back to defaults.

(sandbox: &DriverSandbox, config: &PodmanComputeConfig)

Source from the content-addressed store, hash-verified

450
451/// Parse resource limits from the sandbox template, falling back to defaults.
452fn build_resource_limits(sandbox: &DriverSandbox, config: &PodmanComputeConfig) -> ResourceLimits {
453 let resources = sandbox
454 .spec
455 .as_ref()
456 .and_then(|s| s.template.as_ref())
457 .and_then(|t| t.resources.as_ref());
458
459 let cpu_micros = resources
460 .filter(|r| !r.cpu_limit.is_empty())
461 .and_then(|r| parse_cpu_to_microseconds(&r.cpu_limit))
462 .unwrap_or(DEFAULT_CPU_QUOTA);
463
464 let mem_bytes = resources
465 .filter(|r| !r.memory_limit.is_empty())
466 .and_then(|r| parse_memory_to_bytes(&r.memory_limit))
467 .unwrap_or(DEFAULT_MEMORY_LIMIT);
468
469 ResourceLimits {
470 cpu: CpuLimits {
471 quota: cpu_micros,
472 period: DEFAULT_CPU_PERIOD,
473 },
474 memory: MemoryLimits { limit: mem_bytes },
475 pids_limit: podman_pids_limit(config.sandbox_pids_limit),
476 }
477}
478
479fn podman_pids_limit(value: i64) -> Option<i64> {
480 if value > 0 { Some(value) } else { None }

Calls 4

parse_memory_to_bytesFunction · 0.85
podman_pids_limitFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected