2022-05-31 06:53:54 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
internalclient "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/netmap"
|
2022-05-31 06:53:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-06-23 13:52:47 +00:00
|
|
|
const nodeInfoJSONFlag = commonflags.JSON
|
2022-05-31 06:53:54 +00:00
|
|
|
|
|
|
|
var nodeInfoCmd = &cobra.Command{
|
|
|
|
Use: "nodeinfo",
|
2022-09-28 08:46:23 +00:00
|
|
|
Short: "Get target node info",
|
|
|
|
Long: `Get target node info`,
|
2022-05-31 06:53:54 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
p := key.GetOrGenerate(cmd)
|
|
|
|
cli := internalclient.GetSDKClientByFlag(cmd, p, commonflags.RPC)
|
|
|
|
|
|
|
|
var prm internalclient.NodeInfoPrm
|
|
|
|
prm.SetClient(cli)
|
|
|
|
|
|
|
|
res, err := internalclient.NodeInfo(prm)
|
|
|
|
common.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
|
|
|
|
prettyPrintNodeInfo(cmd, res.NodeInfo())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initNodeInfoCmd() {
|
|
|
|
commonflags.Init(nodeInfoCmd)
|
|
|
|
commonflags.InitAPI(nodeInfoCmd)
|
2022-10-11 14:02:03 +00:00
|
|
|
nodeInfoCmd.Flags().Bool(nodeInfoJSONFlag, false, "Print node info in JSON format")
|
2022-05-31 06:53:54 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func prettyPrintNodeInfo(cmd *cobra.Command, i netmap.NodeInfo) {
|
2022-05-31 06:53:54 +00:00
|
|
|
isJSON, _ := cmd.Flags().GetBool(nodeInfoJSONFlag)
|
|
|
|
if isJSON {
|
|
|
|
common.PrettyPrintJSON(cmd, i, "node info")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("key:", hex.EncodeToString(i.PublicKey()))
|
2022-06-08 23:18:26 +00:00
|
|
|
|
|
|
|
var stateWord string
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
stateWord = "<undefined>"
|
|
|
|
case i.IsOnline():
|
|
|
|
stateWord = "online"
|
|
|
|
case i.IsOffline():
|
|
|
|
stateWord = "offline"
|
2022-10-13 12:06:19 +00:00
|
|
|
case i.IsMaintenance():
|
|
|
|
stateWord = "maintenance"
|
2022-06-08 23:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("state:", stateWord)
|
|
|
|
|
|
|
|
netmap.IterateNetworkEndpoints(i, func(s string) {
|
2022-05-31 06:53:54 +00:00
|
|
|
cmd.Println("address:", s)
|
|
|
|
})
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
i.IterateAttributes(func(key, value string) {
|
|
|
|
cmd.Printf("attribute: %s=%s\n", key, value)
|
|
|
|
})
|
2022-05-31 06:53:54 +00:00
|
|
|
}
|