Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26108 from mlaventure/data-mngt
New Data Management commands
- Loading branch information
Showing
49 changed files
with
1,962 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package container | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/net/context" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/cli" | ||
"github.com/docker/docker/cli/command" | ||
units "github.com/docker/go-units" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type pruneOptions struct { | ||
force bool | ||
} | ||
|
||
// NewPruneCommand returns a new cobra prune command for containers | ||
func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { | ||
var opts pruneOptions | ||
|
||
cmd := &cobra.Command{ | ||
Use: "prune", | ||
Short: "Remove all stopped containers", | ||
Args: cli.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
spaceReclaimed, output, err := runPrune(dockerCli, opts) | ||
if err != nil { | ||
return err | ||
} | ||
if output != "" { | ||
fmt.Fprintln(dockerCli.Out(), output) | ||
} | ||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) | ||
return nil | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") | ||
|
||
return cmd | ||
} | ||
|
||
const warning = `WARNING! This will remove all stopped containers. | ||
Are you sure you want to continue? [y/N] ` | ||
|
||
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { | ||
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { | ||
return | ||
} | ||
|
||
report, err := dockerCli.Client().ContainersPrune(context.Background(), types.ContainersPruneConfig{}) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if len(report.ContainersDeleted) > 0 { | ||
output = "Deleted Containers:" | ||
for _, id := range report.ContainersDeleted { | ||
output += id + "\n" | ||
} | ||
spaceReclaimed = report.SpaceReclaimed | ||
} | ||
|
||
return | ||
} | ||
|
||
// RunPrune call the Container Prune API | ||
// This returns the amount of space reclaimed and a detailed output string | ||
func RunPrune(dockerCli *command.DockerCli) (uint64, string, error) { | ||
return runPrune(dockerCli, pruneOptions{force: true}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cli/command/system/events_utils.go → cli/command/events_utils.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package system | ||
package command | ||
|
||
import ( | ||
"sync" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.