diff options
author | Brent Baude <bbaude@redhat.com> | 2020-04-09 16:11:38 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-04-09 16:59:33 -0500 |
commit | 7d0e0a7129e18ca7295cf4b0fbec22d0df78d3dd (patch) | |
tree | 29102563982befd9a07106ab93a8ebab43b983f4 /pkg/domain/infra/abi/containers.go | |
parent | 3a4bd395164c97bf4b8b1fcb97f2475ca188866e (diff) | |
download | podman-7d0e0a7129e18ca7295cf4b0fbec22d0df78d3dd.tar.gz podman-7d0e0a7129e18ca7295cf4b0fbec22d0df78d3dd.tar.bz2 podman-7d0e0a7129e18ca7295cf4b0fbec22d0df78d3dd.zip |
v2podman container cleanup
add the ability to clean up after a container has attempted to run. this is also important for podman run --rm --rmi.
also included are fixes and tweaks to various code bits to correct regressions on output.
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi/containers.go')
-rw-r--r-- | pkg/domain/infra/abi/containers.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 1aabb2a6b..7f8ec210b 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -757,3 +757,40 @@ func (ic *ContainerEngine) ContainerLogs(ctx context.Context, containers []strin return nil } + +func (ic *ContainerEngine) ContainerCleanup(ctx context.Context, namesOrIds []string, options entities.ContainerCleanupOptions) ([]*entities.ContainerCleanupReport, error) { + var reports []*entities.ContainerCleanupReport + ctrs, err := getContainersByContext(options.All, options.Latest, namesOrIds, ic.Libpod) + if err != nil { + return nil, err + } + for _, ctr := range ctrs { + var err error + report := entities.ContainerCleanupReport{Id: ctr.ID()} + if options.Remove { + err = ic.Libpod.RemoveContainer(ctx, ctr, false, true) + if err != nil { + report.RmErr = errors.Wrapf(err, "failed to cleanup and remove container %v", ctr.ID()) + } + } else { + err := ctr.Cleanup(ctx) + if err != nil { + report.CleanErr = errors.Wrapf(err, "failed to cleanup container %v", ctr.ID()) + } + } + + if options.RemoveImage { + _, imageName := ctr.Image() + ctrImage, err := ic.Libpod.ImageRuntime().NewFromLocal(imageName) + if err != nil { + report.RmiErr = err + reports = append(reports, &report) + continue + } + _, err = ic.Libpod.RemoveImage(ctx, ctrImage, false) + report.RmiErr = err + } + reports = append(reports, &report) + } + return reports, nil +} |