aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain/filters
diff options
context:
space:
mode:
authorBoaz Shuster <boaz.shuster.github@gmail.com>2021-04-20 16:17:16 +0300
committerBoaz Shuster <boaz.shuster.github@gmail.com>2021-05-06 14:35:15 +0300
commitefdc7d84652bbdbf398c88d0287b0740f040a588 (patch)
tree25bc0f45eabf10fa80ff08ba49b73e2e04c6c395 /pkg/domain/filters
parent0b05ba808d5e2fc75ce10b23405bd5c05da2c331 (diff)
downloadpodman-efdc7d84652bbdbf398c88d0287b0740f040a588.tar.gz
podman-efdc7d84652bbdbf398c88d0287b0740f040a588.tar.bz2
podman-efdc7d84652bbdbf398c88d0287b0740f040a588.zip
Add restart-policy to container filters & --filter to podman start
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
Diffstat (limited to 'pkg/domain/filters')
-rw-r--r--pkg/domain/filters/containers.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/domain/filters/containers.go b/pkg/domain/filters/containers.go
index 9ac72e415..965a12468 100644
--- a/pkg/domain/filters/containers.go
+++ b/pkg/domain/filters/containers.go
@@ -1,6 +1,7 @@
package filters
import (
+ "fmt"
"strconv"
"strings"
"time"
@@ -226,6 +227,32 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
}
return false
}, nil
+ case "restart-policy":
+ invalidPolicyNames := []string{}
+ for _, policy := range filterValues {
+ if _, ok := define.RestartPolicyMap[policy]; !ok {
+ invalidPolicyNames = append(invalidPolicyNames, policy)
+ }
+ }
+ var filterValueError error = nil
+ if len(invalidPolicyNames) > 0 {
+ errPrefix := "invalid restart policy"
+ if len(invalidPolicyNames) > 1 {
+ errPrefix = "invalid restart policies"
+ }
+ filterValueError = fmt.Errorf("%s %s", strings.Join(invalidPolicyNames, ", "), errPrefix)
+ }
+ return func(c *libpod.Container) bool {
+ for _, policy := range filterValues {
+ if policy == "none" && c.RestartPolicy() == define.RestartPolicyNone {
+ return true
+ }
+ if c.RestartPolicy() == policy {
+ return true
+ }
+ }
+ return false
+ }, filterValueError
}
return nil, errors.Errorf("%s is an invalid filter", filter)
}