| 311 | } |
| 312 | |
| 313 | func validateCreateConfig(config *tui.CreateConfig, templates []api.TemplateEntry, snapshots []api.Snapshot, diskSizeWasSet bool, specs *utils.SpecStore) error { |
| 314 | config.GPUType = strings.ToLower(config.GPUType) |
| 315 | |
| 316 | // Normalize GPU type |
| 317 | canonical, ok := specs.NormalizeGPUType(config.GPUType) |
| 318 | if !ok { |
| 319 | availableGPUs := specs.GPUOptions() |
| 320 | return usageErr("supported GPU types: %s", strings.Join(availableGPUs, ", ")) |
| 321 | } |
| 322 | config.GPUType = canonical |
| 323 | |
| 324 | // Validate GPU count |
| 325 | if config.NumGPUs == 0 { |
| 326 | config.NumGPUs = 1 |
| 327 | } |
| 328 | |
| 329 | allowedVCPUs := specs.VCPUOptions(config.GPUType, config.NumGPUs) |
| 330 | if allowedVCPUs == nil { |
| 331 | allowedCounts := specs.GPUCounts(config.GPUType) |
| 332 | return usageErr("GPU count %d is not valid for %s. Allowed: %v", config.NumGPUs, config.GPUType, allowedCounts) |
| 333 | } |
| 334 | |
| 335 | if config.VCPUs == 0 && len(allowedVCPUs) == 1 { |
| 336 | config.VCPUs = allowedVCPUs[0] |
| 337 | } |
| 338 | if config.VCPUs == 0 { |
| 339 | return usageErr("--vcpus is required for %d GPU instance(s) (options for %s: %v)", config.NumGPUs, config.GPUType, allowedVCPUs) |
| 340 | } |
| 341 | if !slices.Contains(allowedVCPUs, config.VCPUs) { |
| 342 | return usageErr("vcpus must be one of %v for %s with %d GPU(s)", allowedVCPUs, config.GPUType, config.NumGPUs) |
| 343 | } |
| 344 | |
| 345 | if !specs.IsSpecAvailable(config.GPUType, config.NumGPUs) { |
| 346 | return usageErr("GPU configuration %s x%d is currently unavailable", config.GPUType, config.NumGPUs) |
| 347 | } |
| 348 | |
| 349 | if config.Template == "" { |
| 350 | return usageErr("template is required (use --template or --snapshot flag)") |
| 351 | } |
| 352 | |
| 353 | // Check if template is actually a snapshot |
| 354 | var selectedSnapshot *api.Snapshot |
| 355 | templateFound := false |
| 356 | |
| 357 | // First check templates |
| 358 | for _, t := range templates { |
| 359 | if t.Key == config.Template || strings.EqualFold(t.Template.DisplayName, config.Template) { |
| 360 | config.Template = t.Key |
| 361 | templateFound = true |
| 362 | break |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // If not found in templates, check snapshots |
| 367 | if !templateFound { |
| 368 | for _, s := range snapshots { |
| 369 | if s.Name == config.Template { |
| 370 | selectedSnapshot = &s |