forked from TrueCloudLab/frostfs-node
[#398] cmd/cli: Add netinfo command to netmap section
Add `netinfo` sub-cmd of `netmap` cmd that read recent information about NeoFS network. Info is read via NeoFS API NetmapService.NetworkInfo RPC. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9073e198b9
commit
cb9e6ea6fa
1 changed files with 26 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||||
|
@ -36,6 +37,7 @@ func init() {
|
||||||
getEpochCmd,
|
getEpochCmd,
|
||||||
localNodeInfoCmd,
|
localNodeInfoCmd,
|
||||||
snapshotCmd,
|
snapshotCmd,
|
||||||
|
netInfoCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
localNodeInfoCmd.Flags().BoolVar(&nodeInfoJSON, "json", false, "print node info in JSON format")
|
localNodeInfoCmd.Flags().BoolVar(&nodeInfoJSON, "json", false, "print node info in JSON format")
|
||||||
|
@ -127,6 +129,30 @@ var snapshotCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var netInfoCmd = &cobra.Command{
|
||||||
|
Use: "netinfo",
|
||||||
|
Short: "Get information about NeoFS network",
|
||||||
|
Long: "Get information about NeoFS network",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
cli, err := getSDKClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
netInfo, err := cli.NetworkInfo(context.Background(), globalCallOptions()...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("rpc error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Epoch: %d\n", netInfo.CurrentEpoch())
|
||||||
|
|
||||||
|
magic := netInfo.MagicNumber()
|
||||||
|
cmd.Printf("Network magic: [%s] %d\n", netmode.Magic(magic), magic)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func prettyPrintNodeInfo(i *netmap.NodeInfo, jsonEncoding bool) {
|
func prettyPrintNodeInfo(i *netmap.NodeInfo, jsonEncoding bool) {
|
||||||
if jsonEncoding {
|
if jsonEncoding {
|
||||||
printJSONMarshaler(i, "node info")
|
printJSONMarshaler(i, "node info")
|
||||||
|
|
Loading…
Reference in a new issue