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

Function sandbox_delete

crates/openshell-cli/src/run.rs:3627–3685  ·  view source on GitHub ↗

Delete a sandbox by name, or all sandboxes when `all` is true.

(
    server: &str,
    names: &[String],
    all: bool,
    tls: &TlsOptions,
    gateway: &str,
)

Source from the content-addressed store, hash-verified

3625
3626/// Delete a sandbox by name, or all sandboxes when `all` is true.
3627pub async fn sandbox_delete(
3628 server: &str,
3629 names: &[String],
3630 all: bool,
3631 tls: &TlsOptions,
3632 gateway: &str,
3633) -> Result<()> {
3634 let mut client = grpc_client(server, tls).await?;
3635
3636 let names_to_delete: Vec<String> = if all {
3637 // Fetch all sandboxes (use a large page size).
3638 let response = client
3639 .list_sandboxes(ListSandboxesRequest {
3640 limit: 1000,
3641 offset: 0,
3642 label_selector: String::new(),
3643 })
3644 .await
3645 .into_diagnostic()?;
3646 let sandboxes = response.into_inner().sandboxes;
3647 if sandboxes.is_empty() {
3648 println!("No sandboxes to delete.");
3649 return Ok(());
3650 }
3651 sandboxes
3652 .into_iter()
3653 .map(|s| s.object_name().to_string())
3654 .collect()
3655 } else {
3656 names.to_vec()
3657 };
3658
3659 for name in &names_to_delete {
3660 // Stop any background port forwards for this sandbox before deleting.
3661 if let Ok(stopped) = stop_forwards_for_sandbox(name) {
3662 for port in stopped {
3663 eprintln!(
3664 "{} Stopped forward of port {port} for sandbox {name}",
3665 "✓".green().bold(),
3666 );
3667 }
3668 }
3669
3670 let response = client
3671 .delete_sandbox(DeleteSandboxRequest { name: name.clone() })
3672 .await
3673 .into_diagnostic()?;
3674
3675 let deleted = response.into_inner().deleted;
3676 if deleted {
3677 clear_last_sandbox_if_matches(gateway, name);
3678 println!("{} Deleted sandbox {name}", "✓".green().bold());
3679 } else {
3680 println!("{} Sandbox {name} not found", "!".yellow());
3681 }
3682 }
3683
3684 Ok(())

Callers 2

mainFunction · 0.85

Calls 7

grpc_clientFunction · 0.85
object_nameMethod · 0.80
list_sandboxesMethod · 0.45
is_emptyMethod · 0.45
delete_sandboxMethod · 0.45

Tested by

no test coverage detected