| 2283 | |
| 2284 | #[cfg(test)] |
| 2285 | fn build_container_create_body( |
| 2286 | sandbox: &DriverSandbox, |
| 2287 | config: &DockerDriverRuntimeConfig, |
| 2288 | ) -> Result<ContainerCreateBody, Status> { |
| 2289 | let template = sandbox |
| 2290 | .spec |
| 2291 | .as_ref() |
| 2292 | .and_then(|spec| spec.template.as_ref()) |
| 2293 | .ok_or_else(|| Status::invalid_argument("sandbox.spec.template is required"))?; |
| 2294 | let driver_config = docker_driver_config(template, config.enable_bind_mounts)?; |
| 2295 | let gpu_requirements = sandbox |
| 2296 | .spec |
| 2297 | .as_ref() |
| 2298 | .and_then(|spec| driver_gpu_requirements(spec.resource_requirements.as_ref())); |
| 2299 | let cdi_devices = if let Some(cdi_devices) = driver_config.cdi_devices.as_ref() { |
| 2300 | validate_specific_gpu_device_request( |
| 2301 | gpu_requirements, |
| 2302 | cdi_devices, |
| 2303 | "driver_config.cdi_devices", |
| 2304 | ) |
| 2305 | .map_err(Status::invalid_argument)?; |
| 2306 | Some(cdi_devices.as_slice()) |
| 2307 | } else { |
| 2308 | None |
| 2309 | }; |
| 2310 | build_container_create_body_with_gpu_devices(sandbox, config, &driver_config, cdi_devices) |
| 2311 | } |
| 2312 | |
| 2313 | fn build_container_create_body_with_gpu_devices( |
| 2314 | sandbox: &DriverSandbox, |