frostfs-node/cmd/frostfs-cli/modules/netmap/netinfo.go
Alexander Chuprov afeaf01cea
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m18s
DCO action / DCO (pull_request) Successful in 3m20s
Build / Build Components (1.21) (pull_request) Successful in 5m0s
Build / Build Components (1.22) (pull_request) Successful in 5m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 6m19s
Tests and linters / Staticcheck (pull_request) Successful in 6m46s
Tests and linters / gopls check (pull_request) Successful in 6m45s
Tests and linters / Lint (pull_request) Successful in 7m39s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m2s
Tests and linters / Tests (1.22) (pull_request) Successful in 9m3s
Tests and linters / Tests with -race (pull_request) Successful in 10m28s
[#1236] cli: Fix netinfo output for empty unknown parameters
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2024-07-09 12:25:29 +03:00

66 lines
2.3 KiB
Go

package netmap
import (
"encoding/hex"
"time"
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
"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"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/spf13/cobra"
)
var netInfoCmd = &cobra.Command{
Use: "netinfo",
Short: "Get information about FrostFS network",
Long: "Get information about FrostFS network",
Run: func(cmd *cobra.Command, _ []string) {
p := key.GetOrGenerate(cmd)
cli := internalclient.GetSDKClientByFlag(cmd, p, commonflags.RPC)
prm := internalclient.NetworkInfoPrm{
Client: cli,
}
res, err := internalclient.NetworkInfo(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
netInfo := res.NetworkInfo()
cmd.Printf("Epoch: %d\n", netInfo.CurrentEpoch())
magic := netInfo.MagicNumber()
cmd.Printf("Network magic: [%s] %d\n", netmode.Magic(magic), magic)
cmd.Printf("Time per block: %s\n", time.Duration(netInfo.MsPerBlock())*time.Millisecond)
const format = " %s: %v\n"
cmd.Println("FrostFS network configuration (system)")
cmd.Printf(format, "Container fee", netInfo.ContainerFee())
cmd.Printf(format, "Epoch duration", netInfo.EpochDuration())
cmd.Printf(format, "Inner Ring candidate fee", netInfo.IRCandidateFee())
cmd.Printf(format, "Maximum object size", netInfo.MaxObjectSize())
cmd.Printf(format, "Maximum count of data shards", netInfo.MaxECDataCount())
cmd.Printf(format, "Maximum count of parity shards", netInfo.MaxECParityCount())
cmd.Printf(format, "Withdrawal fee", netInfo.WithdrawalFee())
cmd.Printf(format, "Homomorphic hashing disabled", netInfo.HomomorphicHashingDisabled())
cmd.Printf(format, "Maintenance mode allowed", netInfo.MaintenanceModeAllowed())
cmd.Println("FrostFS network configuration (other)")
netInfo.IterateRawNetworkParameters(func(name string, rawValue []byte) {
value := hex.EncodeToString(rawValue)
if value == "" {
value = `""`
}
cmd.Printf(format, name, value)
})
},
}
func initNetInfoCmd() {
commonflags.Init(netInfoCmd)
commonflags.InitAPI(netInfoCmd)
}