Skip to content

Commit a8270d9

Browse files
authored
Merge pull request #213 from threefoldtech/development_cli_gpu
Adding deploying vm with GPU option
2 parents 0c2a461 + 68afbc9 commit a8270d9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

grid-cli/cmd/deploy_vm.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1718
var ubuntuFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"
1819
var 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
2129
var 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")

grid-cli/docs/vm.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,26 @@ tf-grid-cli deploy vm [flags]
2626
- memory: memory size in GB (default 1).
2727
- rootfs: root filesystem size in GB (default 2).
2828
- ygg: assign yggdrasil ip for VM (default true).
29+
- gpus: assign a list of gpus' ids to the VM. note: setting this without the node option will fail.
2930

3031
Example:
3132

33+
- Deploying VM without GPU
34+
3235
```console
3336
$ tf-grid-cli deploy vm --name examplevm --ssh ~/.ssh/id_rsa.pub --cpu 2 --memory 4 --disk 10
3437
12:06PM INF deploying network
3538
12:06PM INF deploying vm
3639
12:07PM INF vm yggdrasil ip: 300:e9c4:9048:57cf:7da2:ac99:99db:8821
3740
```
41+
- Deploying VM with GPU
42+
43+
```console
44+
$ tf-grid-cli deploy vm --name examplevm --ssh ~/.ssh/id_rsa.pub --cpu 2 --memory 4 --disk 10 --gpus '0000:0e:00.0/1882/543f' --gpus '0000:0e:00.0/1887/593f' --node 12
45+
12:06PM INF deploying network
46+
12:06PM INF deploying vm
47+
12:07PM INF vm yggdrasil ip: 300:e9c4:9048:57cf:7da2:ac99:99db:8821
48+
```
3849

3950
## Get
4051

0 commit comments

Comments
 (0)