forked from TrueCloudLab/frostfs-node
[#651] cmd/cli: Replace netmap snapshot from netmap section to control
There is a need to have all `Control` service-related commands in `control` section. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
8eadf18e01
commit
61f48a2736
2 changed files with 48 additions and 50 deletions
|
@ -60,6 +60,7 @@ func init() {
|
|||
healthCheckCmd,
|
||||
setNetmapStatusCmd,
|
||||
dropObjectsCmd,
|
||||
snapshotCmd,
|
||||
)
|
||||
|
||||
setNetmapStatusCmd.Flags().StringVarP(&netmapStatus, netmapStatusFlag, "", "",
|
||||
|
@ -77,6 +78,9 @@ func init() {
|
|||
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
|
||||
|
||||
healthCheckCmd.Flags().BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
||||
|
||||
snapshotCmd.Flags().BoolVar(&netmapSnapshotJSON, "json", false,
|
||||
"print netmap structure in JSON format")
|
||||
}
|
||||
|
||||
func healthCheck(cmd *cobra.Command, _ []string) {
|
||||
|
@ -279,3 +283,47 @@ var dropObjectsCmd = &cobra.Command{
|
|||
cmd.Println("Objects were successfully marked to be removed.")
|
||||
},
|
||||
}
|
||||
|
||||
var snapshotCmd = &cobra.Command{
|
||||
Use: "netmap-snapshot",
|
||||
Short: "Get network map snapshot",
|
||||
Long: "Get network map snapshot",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
key, err := getKey()
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
req := new(control.NetmapSnapshotRequest)
|
||||
req.SetBody(new(control.NetmapSnapshotRequest_Body))
|
||||
|
||||
if err := controlSvc.SignMessage(key, req); err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
cli, err := getSDKClient(key)
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := control.NetmapSnapshot(cli.Raw(), req)
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
sign := resp.GetSignature()
|
||||
|
||||
if err := signature.VerifyDataWithSource(resp, func() ([]byte, []byte) {
|
||||
return sign.GetKey(), sign.GetSign()
|
||||
}); err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ import (
|
|||
"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"
|
||||
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -33,14 +31,10 @@ func init() {
|
|||
netmapCmd.AddCommand(
|
||||
getEpochCmd,
|
||||
localNodeInfoCmd,
|
||||
snapshotCmd,
|
||||
netInfoCmd,
|
||||
)
|
||||
|
||||
localNodeInfoCmd.Flags().BoolVar(&nodeInfoJSON, "json", false, "print node info in JSON format")
|
||||
|
||||
snapshotCmd.Flags().BoolVar(&netmapSnapshotJSON, "json", false,
|
||||
"print netmap structure in JSON format")
|
||||
}
|
||||
|
||||
var getEpochCmd = &cobra.Command{
|
||||
|
@ -97,50 +91,6 @@ var localNodeInfoCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
var snapshotCmd = &cobra.Command{
|
||||
Use: "snapshot",
|
||||
Short: "Get network map snapshot",
|
||||
Long: "Get network map snapshot",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
key, err := getKey()
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
req := new(control.NetmapSnapshotRequest)
|
||||
req.SetBody(new(control.NetmapSnapshotRequest_Body))
|
||||
|
||||
if err := controlSvc.SignMessage(key, req); err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
cli, err := getSDKClient(key)
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := control.NetmapSnapshot(cli.Raw(), req)
|
||||
if err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
sign := resp.GetSignature()
|
||||
|
||||
if err := signature.VerifyDataWithSource(resp, func() ([]byte, []byte) {
|
||||
return sign.GetKey(), sign.GetSign()
|
||||
}); err != nil {
|
||||
cmd.PrintErrln(err)
|
||||
return
|
||||
}
|
||||
|
||||
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON)
|
||||
},
|
||||
}
|
||||
|
||||
var netInfoCmd = &cobra.Command{
|
||||
Use: "netinfo",
|
||||
Short: "Get information about NeoFS network",
|
||||
|
|
Loading…
Reference in a new issue