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

Function build_sandbox_resource_limits

crates/openshell-cli/src/run.rs:1603–1638  ·  view source on GitHub ↗
(
    cpu: Option<&str>,
    memory: Option<&str>,
)

Source from the content-addressed store, hash-verified

1601}
1602
1603fn build_sandbox_resource_limits(
1604 cpu: Option<&str>,
1605 memory: Option<&str>,
1606) -> Result<Option<prost_types::Struct>> {
1607 use prost_types::{Struct, Value, value::Kind};
1608
1609 fn string_value(value: String) -> Value {
1610 Value {
1611 kind: Some(Kind::StringValue(value)),
1612 }
1613 }
1614
1615 let mut limits = std::collections::BTreeMap::new();
1616 if let Some(cpu) = cpu {
1617 limits.insert("cpu".to_string(), string_value(validate_cpu_quantity(cpu)?));
1618 }
1619 if let Some(memory) = memory {
1620 limits.insert(
1621 "memory".to_string(),
1622 string_value(validate_memory_quantity(memory)?),
1623 );
1624 }
1625
1626 if limits.is_empty() {
1627 return Ok(None);
1628 }
1629
1630 let mut fields = std::collections::BTreeMap::new();
1631 fields.insert(
1632 "limits".to_string(),
1633 Value {
1634 kind: Some(Kind::StructValue(Struct { fields: limits })),
1635 },
1636 );
1637 Ok(Some(Struct { fields }))
1638}
1639
1640fn parse_driver_config_json(value: &str) -> Result<prost_types::Struct> {
1641 let parsed: serde_json::Value = serde_json::from_str(value)

Callers 2

sandbox_createFunction · 0.85

Calls 4

validate_cpu_quantityFunction · 0.85
validate_memory_quantityFunction · 0.85
string_valueFunction · 0.70
is_emptyMethod · 0.45