mirror of
https://github.com/containers/podman.git
synced 2026-07-21 12:42:05 -04:00
Begin the migration of the image bindings for podman 3.0. this includes the use of options for each binding. build was intentionally not converted as I believe it needs more discussion before migration. specifically, the build options themselves. also noteworthly is that the remove image and remove images bindings were merged into one. the remove images (or batch remove) has one downside in that the errors return no longer adhere to http return codes. this should be discussed and reimplemented in subsequent code. Signed-off-by: baude <bbaude@redhat.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package images
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/containers/podman/v2/pkg/api/handlers"
|
|
"github.com/containers/podman/v2/pkg/bindings"
|
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
|
"github.com/containers/podman/v2/pkg/errorhandling"
|
|
)
|
|
|
|
// Remove removes one or more images from the local storage. Use optional force option to remove an
|
|
// image, even if it's used by containers.
|
|
func Remove(ctx context.Context, images []string, options *RemoveOptions) (*entities.ImageRemoveReport, []error) {
|
|
if options == nil {
|
|
options = new(RemoveOptions)
|
|
}
|
|
// FIXME - bindings tests are missing for this endpoint. Once the CI is
|
|
// re-enabled for bindings, we need to add them. At the time of writing,
|
|
// the tests don't compile.
|
|
var report handlers.LibpodImagesRemoveReport
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return nil, []error{err}
|
|
}
|
|
|
|
params, err := options.ToParams()
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
for _, image := range images {
|
|
params.Add("images", image)
|
|
}
|
|
response, err := conn.DoRequest(nil, http.MethodDelete, "/images/remove", params, nil)
|
|
if err != nil {
|
|
return nil, []error{err}
|
|
}
|
|
if err := response.Process(&report); err != nil {
|
|
return nil, []error{err}
|
|
}
|
|
|
|
return &report.ImageRemoveReport, errorhandling.StringsToErrors(report.Errors)
|
|
}
|