diff options
author | Karthik Elango <kelango@redhat.com> | 2022-06-28 15:31:20 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2022-07-26 13:25:36 -0400 |
commit | 6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8 (patch) | |
tree | 4219ba61a3cf8920dcde4fa1fe715ddd319932ab /pkg/domain/infra/tunnel/helpers.go | |
parent | a78be890ee0098c6a6809b562c4806da8fe344b5 (diff) | |
download | podman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.tar.gz podman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.tar.bz2 podman-6d84a9952f1e5be1a187bcc6d9bbc2532331cfc8.zip |
Podman stop --filter flag
Filter flag is added for podman stop and podman --remote stop. Filtering logic is implemented in
getContainersAndInputByContext(). Start filtering can be manipulated to use this logic as well to limit redundancy.
Signed-off-by: Karthik Elango <kelango@redhat.com>
Diffstat (limited to 'pkg/domain/infra/tunnel/helpers.go')
-rw-r--r-- | pkg/domain/infra/tunnel/helpers.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/domain/infra/tunnel/helpers.go b/pkg/domain/infra/tunnel/helpers.go index 24b2b619d..9ff1641f0 100644 --- a/pkg/domain/infra/tunnel/helpers.go +++ b/pkg/domain/infra/tunnel/helpers.go @@ -15,25 +15,29 @@ import ( // FIXME: the `ignore` parameter is very likely wrong here as it should rather // be used on *errors* from operations such as remove. func getContainersByContext(contextWithConnection context.Context, all, ignore bool, namesOrIDs []string) ([]entities.ListContainer, error) { - ctrs, _, err := getContainersAndInputByContext(contextWithConnection, all, ignore, namesOrIDs) + ctrs, _, err := getContainersAndInputByContext(contextWithConnection, all, ignore, namesOrIDs, nil) return ctrs, err } -func getContainersAndInputByContext(contextWithConnection context.Context, all, ignore bool, namesOrIDs []string) ([]entities.ListContainer, []string, error) { +func getContainersAndInputByContext(contextWithConnection context.Context, all, ignore bool, namesOrIDs []string, filters map[string][]string) ([]entities.ListContainer, []string, error) { if all && len(namesOrIDs) > 0 { return nil, nil, errors.New("cannot look up containers and all") } - options := new(containers.ListOptions).WithAll(true).WithSync(true) + options := new(containers.ListOptions).WithAll(true).WithSync(true).WithFilters(filters) allContainers, err := containers.List(contextWithConnection, options) if err != nil { return nil, nil, err } rawInputs := []string{} - if all { + switch { + case len(filters) > 0: + for i := range allContainers { + namesOrIDs = append(namesOrIDs, allContainers[i].ID) + } + case all: for i := range allContainers { rawInputs = append(rawInputs, allContainers[i].ID) } - return allContainers, rawInputs, err } |