@@ -3,45 +3,61 @@ package flag
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "slices"
7
+ "strings"
6
8
7
9
"github.com/superfly/flyctl/api"
8
10
)
9
11
12
+ var validGPUKinds = []string {"a100-pcie-40gb" , "a100-sxm4-80gb" }
13
+
10
14
// Returns a MachineGuest based on the flags provided overwriting a default VM
11
15
func GetMachineGuest (ctx context.Context , guest * api.MachineGuest ) (* api.MachineGuest , error ) {
16
+ defaultVMSize := api .DefaultVMSize
17
+ if IsSpecified (ctx , "vm-gpu-kind" ) {
18
+ defaultVMSize = api .DefaultGPUVMSize
19
+ }
20
+
12
21
if guest == nil {
13
22
guest = & api.MachineGuest {}
14
- guest .SetSize (api . DefaultVMSize )
23
+ guest .SetSize (defaultVMSize )
15
24
}
16
25
17
26
if IsSpecified (ctx , "vm-size" ) {
18
27
if err := guest .SetSize (GetString (ctx , "vm-size" )); err != nil {
19
28
return nil , err
20
29
}
21
30
}
31
+
22
32
if IsSpecified (ctx , "vm-cpus" ) {
23
33
guest .CPUs = GetInt (ctx , "vm-cpus" )
24
34
if guest .CPUs == 0 {
25
- return nil , fmt .Errorf ("cannot have zero cpus " )
35
+ return nil , fmt .Errorf ("--vm-cpus cannot be zero" )
26
36
}
27
37
}
28
38
29
39
if IsSpecified (ctx , "vm-memory" ) {
30
40
guest .MemoryMB = GetInt (ctx , "vm-memory" )
31
41
if guest .MemoryMB == 0 {
32
- return nil , fmt .Errorf ("memory cannot be zero" )
42
+ return nil , fmt .Errorf ("--vm- memory cannot be zero" )
33
43
}
34
44
}
35
45
36
- if IsSpecified (ctx , "vm-cpukind " ) {
37
- guest .CPUKind = GetString (ctx , "vm-cpukind " )
46
+ if IsSpecified (ctx , "vm-cpu-kind " ) {
47
+ guest .CPUKind = GetString (ctx , "vm-cpu-kind " )
38
48
if k := guest .CPUKind ; k != "shared" && k != "performance" {
39
- return nil , fmt .Errorf ("cpukind must be set to 'shared' or 'performance'" )
49
+ return nil , fmt .Errorf ("--vm-cpu-kind must be set to 'shared' or 'performance'" )
40
50
}
41
51
}
42
- if IsSpecified (ctx , "vm-gpus" ) {
43
- guest .GPUs = GetInt (ctx , "vm-gpus" )
52
+
53
+ if IsSpecified (ctx , "vm-gpu-kind" ) {
54
+ m := GetString (ctx , "vm-gpu-kind" )
55
+ if ! slices .Contains (validGPUKinds , m ) {
56
+ return nil , fmt .Errorf ("--vm-gpu-kind must be set to one of: %v" , strings .Join (validGPUKinds , ", " ))
57
+ }
58
+ guest .GPUKind = m
44
59
}
60
+
45
61
return guest , nil
46
62
}
47
63
@@ -57,16 +73,18 @@ var VMSizeFlags = Set{
57
73
Aliases : []string {"cpus" },
58
74
},
59
75
String {
60
- Name : "vm-cpukind " ,
76
+ Name : "vm-cpu-kind " ,
61
77
Description : "The kind of CPU to use ('shared' or 'performance')" ,
78
+ Aliases : []string {"vm-cpukind" },
62
79
},
63
80
Int {
64
81
Name : "vm-memory" ,
65
82
Description : "Memory (in megabytes) to attribute to the VM" ,
66
83
Aliases : []string {"memory" },
67
84
},
68
- Int {
69
- Name : "vm-gpus" ,
70
- Description : "Number of GPUs" ,
85
+ String {
86
+ Name : "vm-gpu-kind" ,
87
+ Description : fmt .Sprintf ("If set, the GPU model to attach (%v)" , strings .Join (validGPUKinds , ", " )),
88
+ Aliases : []string {"vm-gpukind" },
71
89
},
72
90
}
0 commit comments