From 36fd6c663c6030fb283f540f2d7c31dab878aeef Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 17:36:26 +0300 Subject: [PATCH] [#932] adm: Move `dump/restore/list-containers` to package `container` Signed-off-by: Anton Nikiforov --- .../morph/{ => container}/container.go | 2 +- .../internal/modules/morph/container/root.go | 68 +++++++++++++++++++ .../internal/modules/morph/root.go | 62 ++--------------- 3 files changed, 74 insertions(+), 58 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => container}/container.go (99%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/container/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/container.go b/cmd/frostfs-adm/internal/modules/morph/container/container.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/container.go rename to cmd/frostfs-adm/internal/modules/morph/container/container.go index b18fa79ed..46d4921fe 100644 --- a/cmd/frostfs-adm/internal/modules/morph/container.go +++ b/cmd/frostfs-adm/internal/modules/morph/container/container.go @@ -1,4 +1,4 @@ -package morph +package container import ( "encoding/json" diff --git a/cmd/frostfs-adm/internal/modules/morph/container/root.go b/cmd/frostfs-adm/internal/modules/morph/container/root.go new file mode 100644 index 000000000..4cae8cf4f --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/container/root.go @@ -0,0 +1,68 @@ +package container + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +const ( + containerDumpFlag = "dump" + containerContractFlag = "container-contract" + containerIDsFlag = "cid" +) + +var ( + DumpCmd = &cobra.Command{ + Use: "dump-containers", + Short: "Dump FrostFS containers to file", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: dumpContainers, + } + + RestoreCmd = &cobra.Command{ + Use: "restore-containers", + Short: "Restore FrostFS containers from file", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: restoreContainers, + } + + ListCmd = &cobra.Command{ + Use: "list-containers", + Short: "List FrostFS containers", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: listContainers, + } +) + +func initListContainersCmd() { + ListCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + ListCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)") +} + +func initRestoreContainersCmd() { + RestoreCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) + RestoreCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + RestoreCmd.Flags().String(containerDumpFlag, "", "File to restore containers from") + RestoreCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to restore") +} + +func initDumpContainersCmd() { + DumpCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + DumpCmd.Flags().String(containerDumpFlag, "", "File where to save dumped containers") + DumpCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)") + DumpCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to dump") +} + +func init() { + initDumpContainersCmd() + initRestoreContainersCmd() + initListContainersCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index f0e47bc74..98e72fa51 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -4,6 +4,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/ape" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/balance" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/config" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/container" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/notary" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" @@ -31,10 +32,7 @@ const ( homomorphicHashDisabledCLIFlag = "homomorphic-disabled" - withdrawFeeCLIFlag = "withdraw-fee" - containerDumpFlag = "dump" - containerContractFlag = "container-contract" - containerIDsFlag = "cid" + withdrawFeeCLIFlag = "withdraw-fee" walletAddressFlag = "wallet-address" ) @@ -138,34 +136,6 @@ var ( RunE: updateContracts, } - dumpContainersCmd = &cobra.Command{ - Use: "dump-containers", - Short: "Dump FrostFS containers to file", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: dumpContainers, - } - - restoreContainersCmd = &cobra.Command{ - Use: "restore-containers", - Short: "Restore FrostFS containers from file", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: restoreContainers, - } - - listContainersCmd = &cobra.Command{ - Use: "list-containers", - Short: "List FrostFS containers", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: listContainers, - } - netmapCandidatesCmd = &cobra.Command{ Use: "netmap-candidates", Short: "List netmap candidates nodes", @@ -191,9 +161,9 @@ func init() { RootCmd.AddCommand(config.DumpCmd) RootCmd.AddCommand(balance.DumpCmd) initUpdateContractsCmd() - initDumpContainersCmd() - initRestoreContainersCmd() - initListContainersCmd() + RootCmd.AddCommand(container.ListCmd) + RootCmd.AddCommand(container.RestoreCmd) + RootCmd.AddCommand(container.DumpCmd) initRefillGasCmd() RootCmd.AddCommand(notary.DepositCmd) initNetmapCandidatesCmd() @@ -220,28 +190,6 @@ func initRefillGasCmd() { refillGasCmd.MarkFlagsMutuallyExclusive(walletAddressFlag, util.StorageWalletFlag) } -func initListContainersCmd() { - RootCmd.AddCommand(listContainersCmd) - listContainersCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - listContainersCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)") -} - -func initRestoreContainersCmd() { - RootCmd.AddCommand(restoreContainersCmd) - restoreContainersCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) - restoreContainersCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - restoreContainersCmd.Flags().String(containerDumpFlag, "", "File to restore containers from") - restoreContainersCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to restore") -} - -func initDumpContainersCmd() { - RootCmd.AddCommand(dumpContainersCmd) - dumpContainersCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - dumpContainersCmd.Flags().String(containerDumpFlag, "", "File where to save dumped containers") - dumpContainersCmd.Flags().String(containerContractFlag, "", "Container contract hash (for networks without NNS)") - dumpContainersCmd.Flags().StringSlice(containerIDsFlag, nil, "Containers to dump") -} - func initUpdateContractsCmd() { RootCmd.AddCommand(updateContractsCmd) updateContractsCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc)