Skip to content

Commit

Permalink
feat(psutil): add list commands for cpu gpu and memory
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jan 26, 2024
1 parent 0931277 commit f303113
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions operator/psutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func cmdPsutil() *cobra.Command {
},
}

cmd.AddCommand(cmdPsutilList())
cmd.AddCommand(cmdPsutilServe())

return cmd
Expand Down Expand Up @@ -72,6 +73,44 @@ func cmdPsutilServe() *cobra.Command {
return cmd
}

func cmdPsutilList() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "dump node hardware spec into stdout",
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
var res interface{}
var err error
switch args[0] {
case "cpu":
res, err = cpu.New()
case "gpu":
res, err = gpu.New()
case "memory":
res, err = memory.New()
default:
return fmt.Errorf("invalid command \"%s\"", args[0]) // nolint: goerr113
}

if err != nil {
return err
}

data, err := json.MarshalIndent(res, "", " ")
if err != nil {
return err
}

fmt.Printf("%s\n", string(data))

return nil
},
}

return cmd
}

func cpuInfoHandler(w http.ResponseWriter, r *http.Request) {
res, err := cpu.New()
if err != nil {
Expand Down

0 comments on commit f303113

Please sign in to comment.