summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/kpod/create.go12
-rw-r--r--cmd/kpod/run.go12
-rw-r--r--libpod/runtime_img.go33
3 files changed, 57 insertions, 0 deletions
diff --git a/cmd/kpod/create.go b/cmd/kpod/create.go
index 2684f8927..30837e7df 100644
--- a/cmd/kpod/create.go
+++ b/cmd/kpod/create.go
@@ -171,6 +171,18 @@ func createCmd(c *cli.Context) error {
return err
}
if createImage.LocalName != "" {
+ nameIsID, err := runtime.IsImageID(createImage.LocalName)
+ if err != nil {
+ return err
+ }
+ if nameIsID {
+ // If the input from the user is an ID, then we need to get the image
+ // name for cstorage
+ createImage.LocalName, err = createImage.GetNameByID()
+ if err != nil {
+ return err
+ }
+ }
imageName = createImage.LocalName
} else {
imageName, err = createImage.GetFQName()
diff --git a/cmd/kpod/run.go b/cmd/kpod/run.go
index 275654f65..b79ba5121 100644
--- a/cmd/kpod/run.go
+++ b/cmd/kpod/run.go
@@ -54,6 +54,18 @@ func runCmd(c *cli.Context) error {
logrus.Debug("spec is ", runtimeSpec)
if createImage.LocalName != "" {
+ nameIsID, err := runtime.IsImageID(createImage.LocalName)
+ if err != nil {
+ return err
+ }
+ if nameIsID {
+ // If the input from the user is an ID, then we need to get the image
+ // name for cstorage
+ createImage.LocalName, err = createImage.GetNameByID()
+ if err != nil {
+ return err
+ }
+ }
imageName = createImage.LocalName
} else {
imageName, err = createImage.GetFQName()
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 {