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

Function parse_cpu_limit

crates/openshell-driver-docker/src/lib.rs:2685–2716  ·  view source on GitHub ↗
(value: &str)

Source from the content-addressed store, hash-verified

2683
2684#[allow(clippy::cast_possible_truncation)]
2685fn parse_cpu_limit(value: &str) -> Result<Option<i64>, Status> {
2686 let value = value.trim();
2687 if value.is_empty() {
2688 return Ok(None);
2689 }
2690 if let Some(millicores) = value.strip_suffix('m') {
2691 let millicores = millicores.parse::<i64>().map_err(|_| {
2692 Status::failed_precondition(format!(
2693 "invalid docker cpu_limit '{value}'; expected an integer or millicore quantity",
2694 ))
2695 })?;
2696 if millicores <= 0 {
2697 return Err(Status::failed_precondition(
2698 "docker cpu_limit must be greater than zero",
2699 ));
2700 }
2701 return Ok(Some(millicores.saturating_mul(1_000_000)));
2702 }
2703
2704 let cores = value.parse::<f64>().map_err(|_| {
2705 Status::failed_precondition(format!(
2706 "invalid docker cpu_limit '{value}'; expected an integer or millicore quantity",
2707 ))
2708 })?;
2709 if !cores.is_finite() || cores <= 0.0 {
2710 return Err(Status::failed_precondition(
2711 "docker cpu_limit must be greater than zero",
2712 ));
2713 }
2714
2715 Ok(Some((cores * 1_000_000_000.0).round() as i64))
2716}
2717
2718#[allow(clippy::cast_possible_truncation)]
2719fn parse_memory_limit(value: &str) -> Result<Option<i64>, Status> {

Callers 1

docker_resource_limitsFunction · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected