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

Method ensure_prepared_local_image_disk

crates/openshell-driver-vm/src/driver.rs:2132–2202  ·  view source on GitHub ↗
(
        &self,
        sandbox_id: &str,
        image_ref: &str,
        docker: &Docker,
        image_identity: &str,
        bootstrap_root_disk: &Path,
    )

Source from the content-addressed store, hash-verified

2130 }
2131
2132 async fn ensure_prepared_local_image_disk(
2133 &self,
2134 sandbox_id: &str,
2135 image_ref: &str,
2136 docker: &Docker,
2137 image_identity: &str,
2138 bootstrap_root_disk: &Path,
2139 ) -> Result<PreparedImageDisk, Status> {
2140 let cache_identity = prepared_image_cache_identity(image_identity);
2141 let image_path = image_cache_rootfs_image(&self.config.state_dir, &cache_identity);
2142
2143 if tokio::fs::metadata(&image_path).await.is_ok() {
2144 self.publish_prepared_cache_hit(sandbox_id, image_ref, "local_docker", &cache_identity);
2145 return Ok(PreparedImageDisk {
2146 image_identity: cache_identity,
2147 disk_path: image_path,
2148 });
2149 }
2150
2151 self.publish_prepared_cache_miss(sandbox_id, image_ref, "local_docker", &cache_identity);
2152 let _cache_guard = self.image_cache_lock.lock().await;
2153 if tokio::fs::metadata(&image_path).await.is_ok() {
2154 self.publish_prepared_cache_hit(sandbox_id, image_ref, "local_docker", &cache_identity);
2155 return Ok(PreparedImageDisk {
2156 image_identity: cache_identity,
2157 disk_path: image_path,
2158 });
2159 }
2160
2161 let staging_dir = image_cache_staging_dir(&self.config.state_dir, &cache_identity);
2162 let rootfs_archive = staging_dir.join(IMAGE_EXPORT_ROOTFS_ARCHIVE);
2163 self.reset_image_staging_dir(&staging_dir).await?;
2164
2165 self.publish_vm_progress(
2166 sandbox_id,
2167 "ExportingRootfs",
2168 format!("Exporting rootfs from local image \"{image_ref}\""),
2169 HashMap::from([
2170 ("image_ref".to_string(), image_ref.to_string()),
2171 ("image_source".to_string(), "local_docker".to_string()),
2172 ("image_identity".to_string(), cache_identity.clone()),
2173 ]),
2174 );
2175 if let Err(err) =
2176 export_local_image_rootfs_to_path(docker, image_ref, &rootfs_archive).await
2177 {
2178 let _ = tokio::fs::remove_dir_all(&staging_dir).await;
2179 return Err(err);
2180 }
2181
2182 let payload = GuestImagePayload {
2183 image_ref: image_ref.to_string(),
2184 image_identity: cache_identity.clone(),
2185 source: GuestImagePayloadSource::LocalDocker { rootfs_archive },
2186 };
2187 self.build_prepared_image_disk(
2188 sandbox_id,
2189 image_ref,

Callers 1

Tested by

no test coverage detected