| 397 | } |
| 398 | |
| 399 | function configGpu(form: { attachAllGpus: boolean; selectedGpus: string[] }, isUpdate: boolean = false): VmmTypes.IGpuConfig | undefined { |
| 400 | if (form.attachAllGpus) { |
| 401 | return { attach_mode: 'all' }; |
| 402 | } |
| 403 | // For updates, always return a config when GPUs are being explicitly updated |
| 404 | // Empty array means no GPUs should be attached |
| 405 | if (isUpdate) { |
| 406 | return { |
| 407 | attach_mode: 'listed', |
| 408 | gpus: (form.selectedGpus || []).map((slot: string) => ({ slot })), |
| 409 | }; |
| 410 | } |
| 411 | // For creation, return undefined if no GPUs are selected |
| 412 | if (form.selectedGpus && form.selectedGpus.length > 0) { |
| 413 | return { |
| 414 | attach_mode: 'listed', |
| 415 | gpus: form.selectedGpus.map((slot: string) => ({ slot })), |
| 416 | }; |
| 417 | } |
| 418 | return undefined; |
| 419 | } |
| 420 | |
| 421 | type CreateVmPayloadSource = { |
| 422 | name: string; |