diff options
author | baude <bbaude@redhat.com> | 2017-11-27 10:12:24 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-27 16:41:08 +0000 |
commit | 61e0ab4f47b63039152a5576a2f9a1741d45b654 (patch) | |
tree | 5cf672c2366619800d020fea0f6ba79812704f2d /libpod/runtime_img.go | |
parent | 548f1516dedbd9574f624967d7022d52eb4d6c13 (diff) | |
download | podman-61e0ab4f47b63039152a5576a2f9a1741d45b654.tar.gz podman-61e0ab4f47b63039152a5576a2f9a1741d45b654.tar.bz2 podman-61e0ab4f47b63039152a5576a2f9a1741d45b654.zip |
Create|Run container from Image ID
As reported in Issue #50, we need to be able to run
or create a container based on an image ID (as well
as name).
Signed-off-by: baude <bbaude@redhat.com>
Closes: #76
Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_img.go')
-rw-r--r-- | libpod/runtime_img.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index eb9976d9b..873679b0a 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -138,6 +138,36 @@ func (r *Runtime) NewImage(name string) Image { } } +// IsImageID determines if the input is a valid image ID. +// The input can be a full or partial image ID +func (r *Runtime) IsImageID(input string) (bool, error) { + images, err := r.GetImages(&ImageFilterParams{}) + if err != nil { + return false, errors.Wrapf(err, "unable to get images") + } + for _, image := range images { + if strings.HasPrefix(image.ID, input) { + return true, nil + } + } + return false, nil +} + +// GetNameByID returns the name of the image when supplied +// the full or partion ID +func (k *Image) GetNameByID() (string, error) { + images, err := k.runtime.GetImages(&ImageFilterParams{}) + if err != nil { + return "", errors.Wrapf(err, "unable to get images") + } + for _, image := range images { + if strings.HasPrefix(image.ID, k.Name) { + return image.Names[0], nil + } + } + return "", errors.Errorf("unable to determine image for %s", k.Name) +} + // GetImageID returns the image ID of the image func (k *Image) GetImageID() (string, error) { // If the ID field is already populated, then @@ -309,6 +339,9 @@ func (k *Image) GetLocalImageName() (string, error) { return "", err } for _, image := range localImages { + if strings.HasPrefix(image.ID, k.Name) { + return image.ID, nil + } for _, name := range image.Names { imgRef, err := reference.Parse(name) if err != nil { |