-
Notifications
You must be signed in to change notification settings - Fork 38
/
nodeinfo.go
72 lines (57 loc) · 1.72 KB
/
nodeinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package netmap
import (
"encoding/hex"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/spf13/cobra"
)
const nodeInfoJSONFlag = commonflags.JSON
var nodeInfoCmd = &cobra.Command{
Use: "nodeinfo",
Short: "Get target node info",
Long: `Get target node info`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()
cli := internalclient.GetSDKClientByFlag(ctx, cmd, commonflags.RPC)
var prm internalclient.NodeInfoPrm
prm.SetClient(cli)
res, err := internalclient.NodeInfo(ctx, prm)
common.ExitOnErr(cmd, "rpc error: %w", err)
prettyPrintNodeInfo(cmd, res.NodeInfo())
},
}
func initNodeInfoCmd() {
commonflags.Init(nodeInfoCmd)
commonflags.InitAPI(nodeInfoCmd)
nodeInfoCmd.Flags().Bool(nodeInfoJSONFlag, false, "Print node info in JSON format")
}
func prettyPrintNodeInfo(cmd *cobra.Command, i netmap.NodeInfo) {
isJSON, _ := cmd.Flags().GetBool(nodeInfoJSONFlag)
if isJSON {
common.PrettyPrintJSON(cmd, i, "node info")
return
}
cmd.Println("key:", hex.EncodeToString(i.PublicKey()))
var stateWord string
switch {
default:
stateWord = "<undefined>"
case i.IsOnline():
stateWord = "online"
case i.IsOffline():
stateWord = "offline"
case i.IsMaintenance():
stateWord = "maintenance"
}
cmd.Println("state:", stateWord)
netmap.IterateNetworkEndpoints(i, func(s string) {
cmd.Println("address:", s)
})
i.IterateAttributes(func(key, value string) {
cmd.Printf("attribute: %s=%s\n", key, value)
})
}