etcdctl/ctlv3: use new snapshot package

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-04-12 10:32:32 -07:00
parent a2b1449431
commit 90e5af76f3
2 changed files with 18 additions and 14 deletions

View File

@ -148,6 +148,15 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
return cfg
}
func mustClientCfgFromCmd(cmd *cobra.Command) *clientv3.Config {
cc := clientConfigFromCmd(cmd)
cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg)
if err != nil {
ExitWithError(ExitBadArgs, err)
}
return cfg
}
func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
cfg := clientConfigFromCmd(cmd)
return cfg.mustClient()

View File

@ -20,7 +20,6 @@ import (
"path/filepath"
"strings"
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/snapshot"
"github.com/spf13/cobra"
@ -104,10 +103,11 @@ func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) {
if debug {
lg = zap.NewExample()
}
sp := snapshot.NewV3(mustClientFromCmd(cmd), lg)
sp := snapshot.NewV3(lg)
cfg := mustClientCfgFromCmd(cmd)
path := args[0]
if err := sp.Save(context.TODO(), path); err != nil {
if err := sp.Save(context.TODO(), *cfg, path); err != nil {
ExitWithError(ExitInterrupted, err)
}
fmt.Printf("Snapshot saved at %s\n", path)
@ -128,8 +128,7 @@ func snapshotStatusCommandFunc(cmd *cobra.Command, args []string) {
if debug {
lg = zap.NewExample()
}
sp := snapshot.NewV3(nil, lg)
sp := snapshot.NewV3(lg)
ds, err := sp.Status(args[0])
if err != nil {
ExitWithError(ExitError, err)
@ -143,11 +142,6 @@ func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitBadArgs, err)
}
urlmap, uerr := types.NewURLsMap(restoreCluster)
if uerr != nil {
ExitWithError(ExitBadArgs, uerr)
}
dataDir := restoreDataDir
if dataDir == "" {
dataDir = restoreName + ".etcd"
@ -166,15 +160,16 @@ func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) {
if debug {
lg = zap.NewExample()
}
sp := snapshot.NewV3(nil, lg)
sp := snapshot.NewV3(lg)
if err := sp.Restore(args[0], snapshot.RestoreConfig{
if err := sp.Restore(snapshot.RestoreConfig{
SnapshotPath: args[0],
Name: restoreName,
OutputDataDir: dataDir,
OutputWALDir: walDir,
InitialCluster: urlmap,
PeerURLs: strings.Split(restorePeerURLs, ","),
InitialCluster: restoreCluster,
InitialClusterToken: restoreClusterToken,
PeerURLs: types.MustNewURLs(strings.Split(restorePeerURLs, ",")),
SkipHashCheck: skipHashCheck,
}); err != nil {
ExitWithError(ExitError, err)