aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain
diff options
context:
space:
mode:
authorToshiki Sonoda <sonoda.toshiki@fujitsu.com>2022-07-20 19:30:11 +0900
committerToshiki Sonoda <sonoda.toshiki@fujitsu.com>2022-07-20 19:30:11 +0900
commit9b152ef20e9cadf61547897ae21071098256bf79 (patch)
treec44dcb3afbf32da6a7400716595d171bb9467410 /pkg/domain
parent8c9eff5b12eebe318be1f905562be6a236285caa (diff)
downloadpodman-9b152ef20e9cadf61547897ae21071098256bf79.tar.gz
podman-9b152ef20e9cadf61547897ae21071098256bf79.tar.bz2
podman-9b152ef20e9cadf61547897ae21071098256bf79.zip
Add pause/unpause --latest, --cidfile, --filter
--latest : pause/unpause the latest container. --filter : pause/unpause the filtered container. --cidfile : Read container ID from the specified file and pause/unpause the container. Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Diffstat (limited to 'pkg/domain')
-rw-r--r--pkg/domain/entities/containers.go9
-rw-r--r--pkg/domain/infra/abi/containers.go41
-rw-r--r--pkg/domain/infra/tunnel/containers.go26
3 files changed, 60 insertions, 16 deletions
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 934a7cbdc..df793034b 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -71,12 +71,15 @@ type StringSliceReport struct {
}
type PauseUnPauseOptions struct {
- All bool
+ Filters map[string][]string
+ All bool
+ Latest bool
}
type PauseUnpauseReport struct {
- Err error
- Id string //nolint:revive,stylecheck
+ Err error
+ Id string //nolint:revive,stylecheck
+ RawInput string
}
type StopOptions struct {
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 04eb85504..dd7053a23 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -62,6 +62,11 @@ func getContainersAndInputByContext(all, latest bool, names []string, filters ma
}
case all:
ctrs, err = runtime.GetAllContainers()
+ if err == nil {
+ for _, ctr := range ctrs {
+ rawInput = append(rawInput, ctr.ID())
+ }
+ }
case latest:
ctr, err = runtime.GetLatestContainer()
if err == nil {
@@ -133,37 +138,57 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin
}
func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
- ctrs, err := getContainersByContext(options.All, false, namesOrIds, ic.Libpod)
+ ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, options.Filters, ic.Libpod)
if err != nil {
return nil, err
}
- report := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
+ ctrMap := map[string]string{}
+ if len(rawInputs) == len(ctrs) {
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID()] = rawInputs[i]
+ }
+ }
+ reports := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
for _, c := range ctrs {
err := c.Pause()
if err != nil && options.All && errors.Is(err, define.ErrCtrStateInvalid) {
logrus.Debugf("Container %s is not running", c.ID())
continue
}
- report = append(report, &entities.PauseUnpauseReport{Id: c.ID(), Err: err})
+ reports = append(reports, &entities.PauseUnpauseReport{
+ Id: c.ID(),
+ Err: err,
+ RawInput: ctrMap[c.ID()],
+ })
}
- return report, nil
+ return reports, nil
}
func (ic *ContainerEngine) ContainerUnpause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
- ctrs, err := getContainersByContext(options.All, false, namesOrIds, ic.Libpod)
+ ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, options.Filters, ic.Libpod)
if err != nil {
return nil, err
}
- report := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
+ ctrMap := map[string]string{}
+ if len(rawInputs) == len(ctrs) {
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID()] = rawInputs[i]
+ }
+ }
+ reports := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
for _, c := range ctrs {
err := c.Unpause()
if err != nil && options.All && errors.Is(err, define.ErrCtrStateInvalid) {
logrus.Debugf("Container %s is not paused", c.ID())
continue
}
- report = append(report, &entities.PauseUnpauseReport{Id: c.ID(), Err: err})
+ reports = append(reports, &entities.PauseUnpauseReport{
+ Id: c.ID(),
+ Err: err,
+ RawInput: ctrMap[c.ID()],
+ })
}
- return report, nil
+ return reports, nil
}
func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []string, options entities.StopOptions) ([]*entities.StopReport, error) {
names := namesOrIds
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index fcabff7c4..272c23268 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -57,10 +57,14 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin
}
func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
- ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, namesOrIds)
+ ctrs, rawInputs, err := getContainersAndInputByContext(ic.ClientCtx, options.All, false, namesOrIds, options.Filters)
if err != nil {
return nil, err
}
+ ctrMap := map[string]string{}
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID] = rawInputs[i]
+ }
reports := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
for _, c := range ctrs {
err := containers.Pause(ic.ClientCtx, c.ID, nil)
@@ -68,24 +72,36 @@ func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []stri
logrus.Debugf("Container %s is not running", c.ID)
continue
}
- reports = append(reports, &entities.PauseUnpauseReport{Id: c.ID, Err: err})
+ reports = append(reports, &entities.PauseUnpauseReport{
+ Id: c.ID,
+ Err: err,
+ RawInput: ctrMap[c.ID],
+ })
}
return reports, nil
}
func (ic *ContainerEngine) ContainerUnpause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
- reports := []*entities.PauseUnpauseReport{}
- ctrs, err := getContainersByContext(ic.ClientCtx, options.All, false, namesOrIds)
+ ctrs, rawInputs, err := getContainersAndInputByContext(ic.ClientCtx, options.All, false, namesOrIds, options.Filters)
if err != nil {
return nil, err
}
+ ctrMap := map[string]string{}
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID] = rawInputs[i]
+ }
+ reports := make([]*entities.PauseUnpauseReport, 0, len(ctrs))
for _, c := range ctrs {
err := containers.Unpause(ic.ClientCtx, c.ID, nil)
if err != nil && options.All && strings.Contains(err.Error(), define.ErrCtrStateInvalid.Error()) {
logrus.Debugf("Container %s is not paused", c.ID)
continue
}
- reports = append(reports, &entities.PauseUnpauseReport{Id: c.ID, Err: err})
+ reports = append(reports, &entities.PauseUnpauseReport{
+ Id: c.ID,
+ Err: err,
+ RawInput: ctrMap[c.ID],
+ })
}
return reports, nil
}