MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / ensure_image_downloaded

Method ensure_image_downloaded

verifier/src/verification.rs:342–378  ·  view source on GitHub ↗

Helper method to ensure image is downloaded and return image paths

(&self, vm_config: &VmConfig)

Source from the content-addressed store, hash-verified

340
341 /// Helper method to ensure image is downloaded and return image paths
342 async fn ensure_image_downloaded(&self, vm_config: &VmConfig) -> Result<ImagePaths> {
343 let hex_os_image_hash = hex::encode(&vm_config.os_image_hash);
344
345 // Get image directory
346 let image_dir = Path::new(&self.image_cache_dir)
347 .join("images")
348 .join(&hex_os_image_hash);
349
350 let metadata_path = image_dir.join("metadata.json");
351 if !metadata_path.exists() {
352 info!("Image {hex_os_image_hash} not found, downloading");
353 tokio::time::timeout(
354 self.download_timeout,
355 self.download_image(&hex_os_image_hash, &image_dir),
356 )
357 .await
358 .context("Download image timeout")?
359 .with_context(|| format!("Failed to download image {hex_os_image_hash}"))?;
360 }
361
362 let image_info =
363 fs_err::read_to_string(metadata_path).context("Failed to read image metadata")?;
364 let image_info: dstack_types::ImageInfo =
365 serde_json::from_str(&image_info).context("Failed to parse image metadata")?;
366
367 let fw_path = image_dir.join(&image_info.bios);
368 let kernel_path = image_dir.join(&image_info.kernel);
369 let initrd_path = image_dir.join(&image_info.initrd);
370 let kernel_cmdline = image_info.cmdline + " initrd=initrd";
371
372 Ok(ImagePaths {
373 fw_path,
374 kernel_path,
375 initrd_path,
376 kernel_cmdline,
377 })
378 }
379
380 /// Compute expected TDX measurements for a given VM configuration.
381 ///

Calls 2

encodeFunction · 0.85
download_imageMethod · 0.80

Tested by

no test coverage detected