forked from TrueCloudLab/frostfs-node
Airat Arifullin
c42db4e761
* Support healthcheck API call * Support move API call * Support remove API call * Support getSubtree API call * Support getOpLog API call Signed-off-by: Airat Arifullin a.arifullin@yadro.com
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package tree
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
"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"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var removeCmd = &cobra.Command{
|
|
Use: "remove",
|
|
Short: "Remove node",
|
|
Run: remove,
|
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
|
commonflags.Bind(cmd)
|
|
},
|
|
}
|
|
|
|
func initRemoveCmd() {
|
|
commonflags.Init(removeCmd)
|
|
initCTID(removeCmd)
|
|
|
|
ff := removeCmd.Flags()
|
|
ff.Uint64(nodeIDFlagKey, 0, "Node ID.")
|
|
|
|
_ = getSubtreeCmd.MarkFlagRequired(nodeIDFlagKey)
|
|
|
|
_ = cobra.MarkFlagRequired(ff, commonflags.RPC)
|
|
}
|
|
|
|
func remove(cmd *cobra.Command, _ []string) {
|
|
pk := key.GetOrGenerate(cmd)
|
|
cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
|
|
var cnr cid.ID
|
|
err := cnr.DecodeString(cidString)
|
|
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
|
|
|
ctx := cmd.Context()
|
|
|
|
cli, err := _client(ctx)
|
|
commonCmd.ExitOnErr(cmd, "client: %w", err)
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
cnr.Encode(rawCID)
|
|
|
|
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
|
|
|
nid, _ := cmd.Flags().GetUint64(nodeIDFlagKey)
|
|
|
|
var bt []byte
|
|
if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil {
|
|
bt = t.Marshal()
|
|
}
|
|
req := &tree.RemoveRequest{
|
|
Body: &tree.RemoveRequest_Body{
|
|
ContainerId: rawCID,
|
|
TreeId: tid,
|
|
NodeId: nid,
|
|
BearerToken: bt,
|
|
},
|
|
}
|
|
|
|
commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk))
|
|
|
|
_, err = cli.Remove(ctx, req)
|
|
commonCmd.ExitOnErr(cmd, "rpc call: %w", err)
|
|
cmd.Println("Success.")
|
|
}
|