frostfs-node/cmd/internal/common/netmap.go
Evgenii Stratonikov bf06c4fb4b
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m25s
Build / Build Components (push) Successful in 1m48s
Pre-commit hooks / Pre-commit (push) Successful in 1m56s
Tests and linters / Run gofumpt (push) Successful in 3m48s
Tests and linters / Lint (push) Successful in 4m14s
Tests and linters / Staticcheck (push) Successful in 4m10s
Tests and linters / gopls check (push) Successful in 4m23s
Tests and linters / Tests (push) Successful in 4m33s
OCI image / Build container images (push) Successful in 5m3s
Tests and linters / Tests with -race (push) Successful in 5m20s
[#1689] Remove deprecated NodeInfo.IterateNetworkEndpoints()
Change-Id: Ic78f18aed11fab34ee3147ceea657296b89fe60c
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2025-04-15 14:47:22 +00:00

50 lines
1.2 KiB
Go

package common
import (
"encoding/hex"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
"github.com/spf13/cobra"
)
// PrettyPrintNodeInfo print information about network node with given indent and index.
// To avoid printing attribute list use short parameter.
func PrettyPrintNodeInfo(cmd *cobra.Command, node netmap.NodeInfo,
index int, indent string, short bool,
) {
var strState string
switch node.Status() {
default:
strState = "STATE_UNSUPPORTED"
case netmap.Online:
strState = "ONLINE"
case netmap.Offline:
strState = "OFFLINE"
case netmap.Maintenance:
strState = "MAINTENANCE"
}
cmd.Printf("%sNode %d: %s %s ", indent, index+1, hex.EncodeToString(node.PublicKey()), strState)
for endpoint := range node.NetworkEndpoints() {
cmd.Printf("%s ", endpoint)
}
cmd.Println()
if !short {
node.IterateAttributes(func(key, value string) {
cmd.Printf("%s\t%s: %s\n", indent, key, value)
})
}
}
// PrettyPrintNetMap print information about network map.
func PrettyPrintNetMap(cmd *cobra.Command, nm netmap.NetMap, short bool) {
cmd.Println("Epoch:", nm.Epoch())
nodes := nm.Nodes()
for i := range nodes {
PrettyPrintNodeInfo(cmd, nodes[i], i, "", short)
}
}