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

Method ensure_image_available

crates/openshell-driver-docker/src/lib.rs:1311–1346  ·  view source on GitHub ↗
(&self, sandbox_id: &str, image: &str)

Source from the content-addressed store, hash-verified

1309 }
1310
1311 async fn ensure_image_available(&self, sandbox_id: &str, image: &str) -> Result<(), Status> {
1312 let policy = self.config.image_pull_policy.trim().to_ascii_lowercase();
1313 match policy.as_str() {
1314 "" | "ifnotpresent" => {
1315 if self.docker.inspect_image(image).await.is_ok() {
1316 self.publish_docker_progress(
1317 sandbox_id,
1318 "ImagePresent",
1319 format!("Docker image \"{image}\" is already present"),
1320 HashMap::from([("image_ref".to_string(), image.to_string())]),
1321 );
1322 return Ok(());
1323 }
1324 self.pull_image(sandbox_id, image).await
1325 }
1326 "always" => self.pull_image(sandbox_id, image).await,
1327 "never" => match self.docker.inspect_image(image).await {
1328 Ok(_) => {
1329 self.publish_docker_progress(
1330 sandbox_id,
1331 "ImagePresent",
1332 format!("Docker image \"{image}\" is already present"),
1333 HashMap::from([("image_ref".to_string(), image.to_string())]),
1334 );
1335 Ok(())
1336 }
1337 Err(err) if is_not_found_error(&err) => Err(Status::failed_precondition(format!(
1338 "docker image '{image}' is not present locally and image_pull_policy=Never"
1339 ))),
1340 Err(err) => Err(internal_status("inspect Docker image", err)),
1341 },
1342 other => Err(Status::failed_precondition(format!(
1343 "unsupported docker image_pull_policy '{other}'; expected Always, IfNotPresent, or Never",
1344 ))),
1345 }
1346 }
1347
1348 async fn pull_image(&self, sandbox_id: &str, image: &str) -> Result<(), Status> {
1349 self.publish_docker_progress(

Callers 1

Calls 5

is_not_found_errorFunction · 0.85
internal_statusFunction · 0.85
as_strMethod · 0.45
pull_imageMethod · 0.45

Tested by

no test coverage detected