2020-08-30 18:28:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var infoCmd = &cli.Command{
|
|
|
|
Name: "info",
|
|
|
|
Usage: "Print worker info",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := lcli.GetWorkerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
ver, err := api.Version(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting version: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Worker version: ", ver)
|
|
|
|
fmt.Print("CLI version: ")
|
|
|
|
cli.VersionPrinter(cctx)
|
|
|
|
fmt.Println()
|
|
|
|
|
2020-10-27 16:28:44 +00:00
|
|
|
sess, err := api.ProcessSession(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting session: %w", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Session: %s\n", sess)
|
|
|
|
|
|
|
|
enabled, err := api.Enabled(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("checking worker status: %w", err)
|
|
|
|
}
|
2020-11-11 02:39:13 +00:00
|
|
|
fmt.Printf("Enabled: %t\n", enabled)
|
2020-10-27 16:28:44 +00:00
|
|
|
|
2020-08-30 18:28:58 +00:00
|
|
|
info, err := api.Info(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Hostname: %s\n", info.Hostname)
|
|
|
|
fmt.Printf("CPUs: %d; GPUs: %v\n", info.Resources.CPUs, info.Resources.GPUs)
|
|
|
|
fmt.Printf("RAM: %s; Swap: %s\n", types.SizeStr(types.NewInt(info.Resources.MemPhysical)), types.SizeStr(types.NewInt(info.Resources.MemSwap)))
|
|
|
|
fmt.Printf("Reserved memory: %s\n", types.SizeStr(types.NewInt(info.Resources.MemReserved)))
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
paths, err := api.Paths(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting path info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, path := range paths {
|
|
|
|
fmt.Printf("%s:\n", path.ID)
|
|
|
|
fmt.Printf("\tWeight: %d; Use: ", path.Weight)
|
|
|
|
if path.CanSeal || path.CanStore {
|
|
|
|
if path.CanSeal {
|
|
|
|
fmt.Print("Seal ")
|
|
|
|
}
|
|
|
|
if path.CanStore {
|
|
|
|
fmt.Print("Store")
|
|
|
|
}
|
|
|
|
fmt.Println("")
|
|
|
|
} else {
|
|
|
|
fmt.Print("Use: ReadOnly")
|
|
|
|
}
|
|
|
|
fmt.Printf("\tLocal: %s\n", path.LocalPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|