File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1215,8 +1215,9 @@ enum SandboxCommands {
12151215
12161216 /// Target a driver-specific GPU device. Docker and Podman use CDI device IDs
12171217 /// (for example "nvidia.com/gpu=0"); VM uses a PCI BDF or index.
1218- /// Only valid with --gpu. When omitted with --gpu, the driver uses its default GPU selection.
1219- #[ arg( long, requires = "gpu" ) ]
1218+ /// Specifying --gpu-device also requests GPU resources.
1219+ /// When omitted with --gpu, the driver uses its default GPU selection.
1220+ #[ arg( long) ]
12201221 gpu_device : Option < String > ,
12211222
12221223 /// CPU limit for the sandbox (for example: 500m, 1, 2.5).
@@ -4287,6 +4288,32 @@ mod tests {
42874288 }
42884289 }
42894290
4291+ #[ test]
4292+ fn sandbox_create_gpu_device_parses_without_gpu_flag ( ) {
4293+ let cli = Cli :: try_parse_from ( [
4294+ "openshell" ,
4295+ "sandbox" ,
4296+ "create" ,
4297+ "--gpu-device" ,
4298+ "nvidia.com/gpu=0" ,
4299+ ] )
4300+ . expect ( "sandbox create --gpu-device should parse without --gpu" ) ;
4301+
4302+ match cli. command {
4303+ Some ( Commands :: Sandbox {
4304+ command :
4305+ Some ( SandboxCommands :: Create {
4306+ gpu, gpu_device, ..
4307+ } ) ,
4308+ ..
4309+ } ) => {
4310+ assert ! ( !gpu) ;
4311+ assert_eq ! ( gpu_device. as_deref( ) , Some ( "nvidia.com/gpu=0" ) ) ;
4312+ }
4313+ other => panic ! ( "expected SandboxCommands::Create, got: {other:?}" ) ,
4314+ }
4315+ }
4316+
42904317 #[ test]
42914318 fn service_expose_accepts_positional_target_port_and_service ( ) {
42924319 let cli = Cli :: try_parse_from ( [
Original file line number Diff line number Diff line change @@ -1732,7 +1732,9 @@ pub async fn sandbox_create(
17321732 }
17331733 None => None ,
17341734 } ;
1735- let requested_gpu = gpu || image. as_deref ( ) . is_some_and ( image_requests_gpu) ;
1735+ let requested_gpu = gpu
1736+ || gpu_device. is_some_and ( |device_id| !device_id. is_empty ( ) )
1737+ || image. as_deref ( ) . is_some_and ( image_requests_gpu) ;
17361738
17371739 let providers_v2_enabled = gateway_providers_v2_enabled ( & mut client) . await ?;
17381740 let inferred_types: Vec < String > = if providers_v2_enabled {
Original file line number Diff line number Diff line change @@ -884,6 +884,50 @@ async fn sandbox_create_sends_cpu_and_memory_limits_only() {
884884 assert ! ( !resources. fields. contains_key( "requests" ) ) ;
885885}
886886
887+ #[ tokio:: test]
888+ async fn sandbox_create_sends_gpu_device_request_without_gpu_flag ( ) {
889+ let server = run_server ( ) . await ;
890+ let fake_ssh_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
891+ let xdg_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
892+ let _env = test_env ( & fake_ssh_dir, & xdg_dir) ;
893+ let tls = test_tls ( & server) ;
894+ install_fake_ssh ( & fake_ssh_dir) ;
895+
896+ run:: sandbox_create (
897+ & server. endpoint ,
898+ Some ( "gpu-device" ) ,
899+ None ,
900+ "openshell" ,
901+ None ,
902+ true ,
903+ false ,
904+ Some ( "nvidia.com/gpu=0" ) ,
905+ None ,
906+ None ,
907+ None ,
908+ & [ ] ,
909+ None ,
910+ None ,
911+ & [ "echo" . to_string ( ) , "OK" . to_string ( ) ] ,
912+ Some ( false ) ,
913+ Some ( false ) ,
914+ & HashMap :: new ( ) ,
915+ "manual" ,
916+ & tls,
917+ )
918+ . await
919+ . expect ( "sandbox create should succeed" ) ;
920+
921+ let requests = create_requests ( & server) . await ;
922+ let spec = requests[ 0 ]
923+ . spec
924+ . as_ref ( )
925+ . expect ( "sandbox spec should be sent" ) ;
926+
927+ assert ! ( spec. gpu) ;
928+ assert_eq ! ( spec. gpu_device, "nvidia.com/gpu=0" ) ;
929+ }
930+
887931#[ tokio:: test]
888932async fn sandbox_create_does_not_infer_command_providers_when_v2_enabled ( ) {
889933 let server = run_server ( ) . await ;
You can’t perform that action at this time.
0 commit comments