package storagegroup import ( "bytes" internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client" "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" objectCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/object" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" storagegroupSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/storagegroup" "github.com/spf13/cobra" ) var sgID string var sgGetCmd = &cobra.Command{ Use: "get", Short: "Get storage group from FrostFS", Long: "Get storage group from FrostFS", Run: getSG, } func initSGGetCmd() { commonflags.Init(sgGetCmd) flags := sgGetCmd.Flags() flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage) _ = sgGetCmd.MarkFlagRequired(commonflags.CIDFlag) flags.StringVarP(&sgID, sgIDFlag, "", "", "Storage group identifier") _ = sgGetCmd.MarkFlagRequired(sgIDFlag) flags.Bool(sgRawFlag, false, "Set raw request option") } func getSG(cmd *cobra.Command, _ []string) { var cnr cid.ID var obj oid.ID addr := readObjectAddress(cmd, &cnr, &obj) pk := key.GetOrGenerate(cmd) buf := bytes.NewBuffer(nil) cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC) var prm internalclient.GetObjectPrm objectCli.Prepare(cmd, &prm) prm.SetClient(cli) raw, _ := cmd.Flags().GetBool(sgRawFlag) prm.SetRawFlag(raw) prm.SetAddress(addr) prm.SetPayloadWriter(buf) res, err := internalclient.GetObject(prm) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) rawObj := res.Header() rawObj.SetPayload(buf.Bytes()) var sg storagegroupSDK.StorageGroup err = storagegroupSDK.ReadFromObject(&sg, *rawObj) commonCmd.ExitOnErr(cmd, "could not read storage group from the obj: %w", err) cmd.Printf("The last active epoch: %d\n", sg.ExpirationEpoch()) cmd.Printf("Group size: %d\n", sg.ValidationDataSize()) common.PrintChecksum(cmd, "Group hash", sg.ValidationDataHash) if members := sg.Members(); len(members) > 0 { cmd.Println("Members:") for i := range members { cmd.Printf("\t%s\n", members[i].String()) } } }