2022-05-31 06:53:54 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
|
|
"git.frostfs.info/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)
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := internalclient.NodeInfo(cmd.Context(), prm)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-05-31 06:53:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|