@@ -6,12 +6,16 @@ import (
6
6
"time"
7
7
8
8
"github.com/urfave/cli"
9
+ corev1 "k8s.io/api/core/v1"
9
10
10
11
apiv1 "github.com/leptonai/gpud/api/v1"
11
12
client "github.com/leptonai/gpud/client/v1"
12
13
"github.com/leptonai/gpud/pkg/config"
14
+ pkgcpu "github.com/leptonai/gpud/pkg/cpu"
13
15
gpudstate "github.com/leptonai/gpud/pkg/gpud-state"
14
16
"github.com/leptonai/gpud/pkg/login"
17
+ pkgmemory "github.com/leptonai/gpud/pkg/memory"
18
+ nvidiaquery "github.com/leptonai/gpud/pkg/nvidia-query"
15
19
"github.com/leptonai/gpud/pkg/server"
16
20
"github.com/leptonai/gpud/pkg/sqlite"
17
21
)
@@ -59,9 +63,32 @@ func cmdLogin(cliContext *cli.Context) error {
59
63
60
64
endpoint := cliContext .String ("endpoint" )
61
65
66
+ req := apiv1.LoginRequest {
67
+ Token : token ,
68
+ ResourceSpec : map [string ]string {},
69
+ }
70
+
71
+ cpu , err := pkgcpu .GetSystemResourceLogicalCores ()
72
+ if err != nil {
73
+ return fmt .Errorf ("failed to get system resource logical cores: %w" , err )
74
+ }
75
+ req .ResourceSpec [string (corev1 .ResourceCPU )] = cpu
76
+
77
+ memory , err := pkgmemory .GetSystemResourceMemoryTotal ()
78
+ if err != nil {
79
+ return fmt .Errorf ("failed to get system resource memory total: %w" , err )
80
+ }
81
+ req .ResourceSpec [string (corev1 .ResourceMemory )] = memory
82
+
83
+ gpuCnt , err := nvidiaquery .GetSystemResourceGPUCount ()
84
+ if err != nil {
85
+ return fmt .Errorf ("failed to get system resource gpu count: %w" , err )
86
+ }
87
+ req .ResourceSpec ["nvidia.com/gpu" ] = gpuCnt
88
+
62
89
// machine ID has not been assigned yet
63
90
// thus request one and blocks until the login request is processed
64
- loginResp , err := login .SendRequest (rootCtx , endpoint , apiv1. LoginRequest { Token : token } )
91
+ loginResp , err := login .SendRequest (rootCtx , endpoint , req )
65
92
if err != nil {
66
93
return err
67
94
}
0 commit comments