2016-05-12 10:52:00 -04:00
|
|
|
package checkpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2016-09-19 12:01:16 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-05-12 10:52:00 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-19 12:01:16 -04:00
|
|
|
type removeOptions struct {
|
|
|
|
checkpointDir string
|
|
|
|
}
|
|
|
|
|
2017-05-03 17:58:52 -04:00
|
|
|
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-19 12:01:16 -04:00
|
|
|
var opts removeOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2016-11-08 03:15:09 -05:00
|
|
|
Use: "rm [OPTIONS] CONTAINER CHECKPOINT",
|
2016-05-12 10:52:00 -04:00
|
|
|
Aliases: []string{"remove"},
|
|
|
|
Short: "Remove a checkpoint",
|
|
|
|
Args: cli.ExactArgs(2),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-09-19 12:01:16 -04:00
|
|
|
return runRemove(dockerCli, args[0], args[1], opts)
|
2016-05-12 10:52:00 -04:00
|
|
|
},
|
|
|
|
}
|
2016-09-19 12:01:16 -04:00
|
|
|
|
|
|
|
flags := cmd.Flags()
|
2016-11-08 03:15:09 -05:00
|
|
|
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory")
|
2016-09-19 12:01:16 -04:00
|
|
|
|
|
|
|
return cmd
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|
|
|
|
|
2017-05-03 17:58:52 -04:00
|
|
|
func runRemove(dockerCli command.Cli, container string, checkpoint string, opts removeOptions) error {
|
2016-05-12 10:52:00 -04:00
|
|
|
client := dockerCli.Client()
|
2016-09-19 12:01:16 -04:00
|
|
|
|
|
|
|
removeOpts := types.CheckpointDeleteOptions{
|
|
|
|
CheckpointID: checkpoint,
|
|
|
|
CheckpointDir: opts.checkpointDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
return client.CheckpointDelete(context.Background(), container, removeOpts)
|
2016-05-12 10:52:00 -04:00
|
|
|
}
|