diff options
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r-- | libpod/runtime.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index 39c65548b..869727f38 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -12,6 +12,7 @@ import ( "github.com/containers/image/types" "github.com/containers/storage" "github.com/cri-o/ocicni/pkg/ocicni" + "github.com/docker/docker/pkg/namesgenerator" "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod/image" "github.com/sirupsen/logrus" @@ -562,6 +563,31 @@ func (r *Runtime) Info() ([]InfoData, error) { return info, nil } +// generateName generates a unigue name for a container or pod. +func (r *Runtime) generateName() (string, error) { + for { + name := namesgenerator.GetRandomName(0) + // Make sure container with this name does not exist + if _, err := r.state.LookupContainer(name); err == nil { + continue + } else { + if errors.Cause(err) != ErrNoSuchCtr { + return "", err + } + } + // Make sure pod with this name does not exist + if _, err := r.state.LookupPod(name); err == nil { + continue + } else { + if errors.Cause(err) != ErrNoSuchPod { + return "", err + } + } + return name, nil + } + // The code should never reach here. +} + // SaveDefaultConfig saves a copy of the default config at the given path func SaveDefaultConfig(path string) error { var w bytes.Buffer |