Beispiel #1
0
func getImage(name string, localOnly bool) (*jetpack.Image, error) {
	if h, err := types.NewHash(name); err == nil {
		if len(name) < hashSize {
			// Short hash. Iterate over images, return first prefix match.
			// FIXME: what about multiple matches?
			name = strings.ToLower(name)
			if imgs, err := Host.Images(); err != nil {
				return nil, errors.Trace(err)
			} else {
				for _, img := range imgs {
					if strings.HasPrefix(img.Hash.String(), name) {
						return img, nil
					}
				}
				return nil, jetpack.ErrNotFound
			}
		}
		return Host.GetImage(*h, "", nil)
	}
	if name, labels, err := acutil.ParseImageName(name); err != nil {
		return nil, errors.Trace(err)
	} else if localOnly {
		return Host.GetLocalImage(types.Hash{}, name, labels)
	} else {
		return Host.GetImage(types.Hash{}, name, labels)
	}
}
Beispiel #2
0
func cmdFetch(args []string) error {
	var idf *os.File
	if SaveID != "" {
		if f, err := os.Create(SaveID); err != nil {
			return err
		} else {
			idf = f
			defer idf.Close()
		}
	}

	for _, name := range args {
		if name, labels, err := acutil.ParseImageName(name); err != nil {
			return errors.Trace(err)
		} else if img, err := Host.FetchImage(types.Hash{}, name, labels); err != nil {
			return errors.Trace(err)
		} else {
			if idf != nil {
				fmt.Fprintln(idf, img.Hash)
			}
			if err := cmdShowImage(img); err != nil {
				return errors.Trace(err)
			}
		}
	}

	return nil
}