frostfs-node/cmd/frostfs-cli/modules/netmap/nodeinfo.go
Dmitrii Stepanov 3441fff05d
All checks were successful
DCO action / DCO (pull_request) Successful in 52s
Tests and linters / Run gofumpt (pull_request) Successful in 1m14s
Vulncheck / Vulncheck (pull_request) Successful in 2m3s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m12s
Build / Build Components (pull_request) Successful in 2m15s
Tests and linters / gopls check (pull_request) Successful in 2m41s
Tests and linters / Staticcheck (pull_request) Successful in 2m44s
Tests and linters / Lint (pull_request) Successful in 3m22s
Tests and linters / Tests (pull_request) Successful in 4m11s
Tests and linters / Tests with -race (pull_request) Successful in 5m42s
[#1382] cli: Replace deprecated methods
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-09-18 14:35:48 +03:00

72 lines
1.9 KiB
Go

package netmap
import (
"encoding/hex"
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"
"github.com/spf13/cobra"
)
const nodeInfoJSONFlag = commonflags.JSON
var nodeInfoCmd = &cobra.Command{
Use: "nodeinfo",
Short: "Get target node info",
Long: `Get target node info`,
Run: func(cmd *cobra.Command, _ []string) {
p := key.GetOrGenerate(cmd)
cli := internalclient.GetSDKClientByFlag(cmd, p, commonflags.RPC)
prm := internalclient.NodeInfoPrm{
Client: cli,
}
res, err := internalclient.NodeInfo(cmd.Context(), prm)
commonCmd.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 i.Status() {
default:
stateWord = "<undefined>"
case netmap.Online:
stateWord = "online"
case netmap.Offline:
stateWord = "offline"
case netmap.Maintenance:
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)
})
}