[#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:
Leonard Lyubich 2021-02-19 11:03:34 +03:00 committed by Alex Vanin
parent 9073e198b9
commit cb9e6ea6fa

View file

@ -6,6 +6,7 @@ import (
"fmt"
"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/util/signature"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
@ -36,6 +37,7 @@ func init() {
getEpochCmd,
localNodeInfoCmd,
snapshotCmd,
netInfoCmd,
)
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) {
if jsonEncoding {
printJSONMarshaler(i, "node info")