@@ -12,11 +12,19 @@ import (
1212 "github.com/threefoldtech/tfgrid-sdk-go/grid-cli/internal/filters"
1313 "github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
1414 "github.com/threefoldtech/tfgrid-sdk-go/grid-client/workloads"
15+ "github.com/threefoldtech/zos/pkg/gridtypes/zos"
1516)
1617
1718var ubuntuFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"
1819var ubuntuFlistEntrypoint = "/sbin/zinit init"
1920
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+
2028// deployVMCmd represents the deploy vm command
2129var deployVMCmd = & cobra.Command {
2230 Use : "vm" ,
@@ -66,6 +74,11 @@ var deployVMCmd = &cobra.Command{
6674 if err != nil {
6775 return err
6876 }
77+ gpus , err := cmd .Flags ().GetStringSlice ("gpus" )
78+ if err != nil {
79+ return err
80+ }
81+
6982 ipv4 , err := cmd .Flags ().GetBool ("ipv4" )
7083 if err != nil {
7184 return err
@@ -83,6 +96,7 @@ var deployVMCmd = &cobra.Command{
8396 EnvVars : map [string ]string {"SSH_KEY" : string (sshKey )},
8497 CPU : cpu ,
8598 Memory : memory * 1024 ,
99+ GPUs : convertGPUsToZosGPUs (gpus ),
86100 RootfsSize : rootfs * 1024 ,
87101 Flist : flist ,
88102 Entrypoint : entrypoint ,
@@ -104,6 +118,7 @@ var deployVMCmd = &cobra.Command{
104118 if err != nil {
105119 log .Fatal ().Err (err ).Send ()
106120 }
121+
107122 if node == 0 {
108123 nodes , err := deployer .FilterNodes (
109124 cmd .Context (),
@@ -158,6 +173,10 @@ func init() {
158173 deployVMCmd .Flags ().Int ("rootfs" , 2 , "root filesystem size in gb" )
159174 deployVMCmd .Flags ().Int ("disk" , 0 , "disk size in gb mounted on /data" )
160175 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+
161180 deployVMCmd .Flags ().String ("entrypoint" , ubuntuFlistEntrypoint , "entrypoint for vm" )
162181 // to ensure entrypoint is provided for custom flist
163182 deployVMCmd .MarkFlagsRequiredTogether ("flist" , "entrypoint" )
0 commit comments