image_import.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package lib
  2. import (
  3. "io"
  4. "net/url"
  5. )
  6. // ImportImageOptions holds information to import images from the client host.
  7. type ImportImageOptions struct {
  8. // Source is the data to send to the server to create this image from
  9. Source io.Reader
  10. // Source is the name of the source to import this image from
  11. SourceName string
  12. // RepositoryName is the name of the repository to import this image
  13. RepositoryName string
  14. // Message is the message to tag the image with
  15. Message string
  16. // Tag is the name to tag this image
  17. Tag string
  18. // Changes are the raw changes to apply to the image
  19. Changes []string
  20. }
  21. // ImportImage creates a new image based in the source options.
  22. // It returns the JSON content in the response body.
  23. func (cli *Client) ImportImage(options ImportImageOptions) (io.ReadCloser, error) {
  24. var query url.Values
  25. query.Set("fromSrc", options.SourceName)
  26. query.Set("repo", options.RepositoryName)
  27. query.Set("tag", options.Tag)
  28. query.Set("message", options.Message)
  29. for _, change := range options.Changes {
  30. query.Add("changes", change)
  31. }
  32. resp, err := cli.POSTRaw("/images/create", query, options.Source, nil)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return resp.body, nil
  37. }