forked from TrueCloudLab/frostfs-node
[#1889] Move netmap.go and exit.go from cli
to cmd/internal/common
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
5a9d6a09d8
commit
2b09564355
62 changed files with 269 additions and 247 deletions
49
cmd/internal/common/netmap.go
Normal file
49
cmd/internal/common/netmap.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/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 {
|
||||
default:
|
||||
strState = "STATE_UNSUPPORTED"
|
||||
case node.IsOnline():
|
||||
strState = "ONLINE"
|
||||
case node.IsOffline():
|
||||
strState = "OFFLINE"
|
||||
case node.IsMaintenance():
|
||||
strState = "MAINTENANCE"
|
||||
}
|
||||
|
||||
cmd.Printf("%sNode %d: %s %s ", indent, index+1, hex.EncodeToString(node.PublicKey()), strState)
|
||||
|
||||
netmap.IterateNetworkEndpoints(node, func(endpoint string) {
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue