(self, request: UpdateVmRequest)
| 375 | } |
| 376 | |
| 377 | async fn update_vm(self, request: UpdateVmRequest) -> Result<Id> { |
| 378 | let new_id = if !request.compose_file.is_empty() { |
| 379 | // check the compose file is valid |
| 380 | let _app_compose: AppCompose = |
| 381 | serde_json::from_str(&request.compose_file).context("Invalid compose file")?; |
| 382 | let compose_file_path = self.compose_file_path(&request.id); |
| 383 | if !compose_file_path.exists() { |
| 384 | bail!("The instance {} not found", request.id); |
| 385 | } |
| 386 | fs::write(compose_file_path, &request.compose_file) |
| 387 | .context("Failed to write compose file")?; |
| 388 | |
| 389 | app_id_of(&request.compose_file) |
| 390 | } else { |
| 391 | Default::default() |
| 392 | }; |
| 393 | if !request.encrypted_env.is_empty() { |
| 394 | let encrypted_env_path = self.encrypted_env_path(&request.id); |
| 395 | fs::write(encrypted_env_path, &request.encrypted_env) |
| 396 | .context("Failed to write encrypted env")?; |
| 397 | } |
| 398 | if !request.user_config.is_empty() { |
| 399 | let user_config_path = self.user_config_path(&request.id); |
| 400 | fs::write(user_config_path, &request.user_config) |
| 401 | .context("Failed to write user config")?; |
| 402 | } |
| 403 | let vm_work_dir = self.app.work_dir(&request.id); |
| 404 | let mut manifest = vm_work_dir.manifest().context("Failed to read manifest")?; |
| 405 | self.apply_resource_updates( |
| 406 | &request.id, |
| 407 | &mut manifest, |
| 408 | &vm_work_dir, |
| 409 | request.vcpu, |
| 410 | request.memory, |
| 411 | request.disk_size, |
| 412 | request.image.as_deref(), |
| 413 | ) |
| 414 | .await?; |
| 415 | if let Some(gpus) = request.gpus { |
| 416 | manifest.gpus = Some(self.resolve_gpus(&gpus)?); |
| 417 | } |
| 418 | if let Some(no_tee) = request.no_tee { |
| 419 | manifest.no_tee = no_tee; |
| 420 | } |
| 421 | if request.update_ports { |
| 422 | manifest.port_map = request |
| 423 | .ports |
| 424 | .iter() |
| 425 | .map(|p| { |
| 426 | Ok(PortMapping { |
| 427 | address: p.host_address.parse().context("Invalid host address")?, |
| 428 | protocol: p.protocol.parse().context("Invalid protocol")?, |
| 429 | from: p.host_port.try_into().context("Invalid host port")?, |
| 430 | to: p.vm_port.try_into().context("Invalid vm port")?, |
| 431 | }) |
| 432 | }) |
| 433 | .collect::<Result<Vec<_>>>()?; |
| 434 | } |
no test coverage detected