diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-02 20:45:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-02 20:45:44 +0200 |
commit | ccf28a89bdded86b044f2fd3aa3389b923a81988 (patch) | |
tree | 2acc41efb2ade3f451004a2d00c702eaeba53cad /pkg/adapter/containers.go | |
parent | 3cec403268cf311ed21d981089236cabd0bd66f7 (diff) | |
parent | 4b339145356e505971aa04773ef733c2938687ff (diff) | |
download | podman-ccf28a89bdded86b044f2fd3aa3389b923a81988.tar.gz podman-ccf28a89bdded86b044f2fd3aa3389b923a81988.tar.bz2 podman-ccf28a89bdded86b044f2fd3aa3389b923a81988.zip |
Merge pull request #3039 from mheon/podman_init
Add podman init command
Diffstat (limited to 'pkg/adapter/containers.go')
-rw-r--r-- | pkg/adapter/containers.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index 068ab3a8a..eb90ab50e 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -133,6 +133,43 @@ func (r *LocalRuntime) KillContainers(ctx context.Context, cli *cliconfig.KillVa return pool.Run() } +// InitContainers initializes container(s) based on CLI inputs. +// Returns list of successful id(s), map of failed id(s) to errors, or a general +// error not from the container. +func (r *LocalRuntime) InitContainers(ctx context.Context, cli *cliconfig.InitValues) ([]string, map[string]error, error) { + maxWorkers := shared.DefaultPoolSize("init") + if cli.GlobalIsSet("max-workers") { + maxWorkers = cli.GlobalFlags.MaxWorks + } + logrus.Debugf("Setting maximum init workers to %d", maxWorkers) + + ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime) + if err != nil { + return nil, nil, err + } + + pool := shared.NewPool("init", maxWorkers, len(ctrs)) + for _, c := range ctrs { + ctr := c + + pool.Add(shared.Job{ + ctr.ID(), + func() error { + err := ctr.Init(ctx) + if err != nil { + // If we're initializing all containers, ignore invalid state errors + if cli.All && errors.Cause(err) == libpod.ErrCtrStateInvalid { + return nil + } + return err + } + return nil + }, + }) + } + return pool.Run() +} + // RemoveContainers removes container(s) based on CLI inputs. func (r *LocalRuntime) RemoveContainers(ctx context.Context, cli *cliconfig.RmValues) ([]string, map[string]error, error) { var ( |