(
&self,
sandbox_id: &str,
sandbox_name: &str,
)
| 1029 | } |
| 1030 | |
| 1031 | pub async fn delete_sandbox( |
| 1032 | &self, |
| 1033 | sandbox_id: &str, |
| 1034 | sandbox_name: &str, |
| 1035 | ) -> Result<DeleteSandboxResponse, Status> { |
| 1036 | if !sandbox_id.is_empty() { |
| 1037 | validate_sandbox_id(sandbox_id)?; |
| 1038 | } |
| 1039 | |
| 1040 | let record_id = { |
| 1041 | let registry = self.registry.lock().await; |
| 1042 | if let Some((id, _record)) = registry.get_key_value(sandbox_id) { |
| 1043 | Some(id.clone()) |
| 1044 | } else { |
| 1045 | registry |
| 1046 | .iter() |
| 1047 | .find(|(_, record)| record.snapshot.name == sandbox_name) |
| 1048 | .map(|(id, _)| id.clone()) |
| 1049 | } |
| 1050 | }; |
| 1051 | |
| 1052 | let Some(record_id) = record_id else { |
| 1053 | return Ok(DeleteSandboxResponse { deleted: false }); |
| 1054 | }; |
| 1055 | |
| 1056 | let ( |
| 1057 | state_dir, |
| 1058 | process, |
| 1059 | gpu_bdf, |
| 1060 | qemu_network_allocated, |
| 1061 | provisioning_task, |
| 1062 | sandbox_snapshot, |
| 1063 | ) = { |
| 1064 | let mut registry = self.registry.lock().await; |
| 1065 | let Some(record) = registry.get_mut(&record_id) else { |
| 1066 | return Ok(DeleteSandboxResponse { deleted: false }); |
| 1067 | }; |
| 1068 | record.deleting = true; |
| 1069 | ( |
| 1070 | record.state_dir.clone(), |
| 1071 | record.process.clone(), |
| 1072 | record.gpu_bdf.clone(), |
| 1073 | record.qemu_network_allocated, |
| 1074 | record.provisioning_task.take(), |
| 1075 | record.snapshot.clone(), |
| 1076 | ) |
| 1077 | }; |
| 1078 | |
| 1079 | if let Some(snapshot) = self |
| 1080 | .set_snapshot_condition(&record_id, deleting_condition(), true) |
| 1081 | .await |
| 1082 | { |
| 1083 | self.publish_snapshot(snapshot); |
| 1084 | } |
| 1085 | |
| 1086 | if let Some(task) = provisioning_task { |
| 1087 | task.abort(); |
| 1088 | } |
no test coverage detected