@@ -12,11 +12,19 @@ import (
12
12
"github.com/threefoldtech/tfgrid-sdk-go/grid-cli/internal/filters"
13
13
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
14
14
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/workloads"
15
+ "github.com/threefoldtech/zos/pkg/gridtypes/zos"
15
16
)
16
17
17
18
var ubuntuFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"
18
19
var ubuntuFlistEntrypoint = "/sbin/zinit init"
19
20
21
+ func convertGPUsToZosGPUs (gpus []string ) (zosGPUs []zos.GPU ) {
22
+ for _ , g := range gpus {
23
+ zosGPUs = append (zosGPUs , zos .GPU (g ))
24
+ }
25
+ return
26
+ }
27
+
20
28
// deployVMCmd represents the deploy vm command
21
29
var deployVMCmd = & cobra.Command {
22
30
Use : "vm" ,
@@ -66,6 +74,11 @@ var deployVMCmd = &cobra.Command{
66
74
if err != nil {
67
75
return err
68
76
}
77
+ gpus , err := cmd .Flags ().GetStringSlice ("gpus" )
78
+ if err != nil {
79
+ return err
80
+ }
81
+
69
82
ipv4 , err := cmd .Flags ().GetBool ("ipv4" )
70
83
if err != nil {
71
84
return err
@@ -83,6 +96,7 @@ var deployVMCmd = &cobra.Command{
83
96
EnvVars : map [string ]string {"SSH_KEY" : string (sshKey )},
84
97
CPU : cpu ,
85
98
Memory : memory * 1024 ,
99
+ GPUs : convertGPUsToZosGPUs (gpus ),
86
100
RootfsSize : rootfs * 1024 ,
87
101
Flist : flist ,
88
102
Entrypoint : entrypoint ,
@@ -104,6 +118,7 @@ var deployVMCmd = &cobra.Command{
104
118
if err != nil {
105
119
log .Fatal ().Err (err ).Send ()
106
120
}
121
+
107
122
if node == 0 {
108
123
nodes , err := deployer .FilterNodes (
109
124
cmd .Context (),
@@ -158,6 +173,10 @@ func init() {
158
173
deployVMCmd .Flags ().Int ("rootfs" , 2 , "root filesystem size in gb" )
159
174
deployVMCmd .Flags ().Int ("disk" , 0 , "disk size in gb mounted on /data" )
160
175
deployVMCmd .Flags ().String ("flist" , ubuntuFlist , "flist for vm" )
176
+ deployVMCmd .Flags ().StringSlice ("gpus" , []string {}, "gpus for vm" )
177
+ // to ensure node is provided for gpus
178
+ deployVMCmd .MarkFlagsRequiredTogether ("gpus" , "node" )
179
+
161
180
deployVMCmd .Flags ().String ("entrypoint" , ubuntuFlistEntrypoint , "entrypoint for vm" )
162
181
// to ensure entrypoint is provided for custom flist
163
182
deployVMCmd .MarkFlagsRequiredTogether ("flist" , "entrypoint" )
0 commit comments