From bb39051616fbce12b4cb3135a62c7747273ab0aa Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Tue, 31 Mar 2020 19:13:19 -0500 Subject: podmanv2 export add ability to export a container to a tarball Signed-off-by: Brent Baude --- pkg/bindings/containers/containers.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'pkg/bindings') diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index bad1294f4..49a2dfd58 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -2,6 +2,7 @@ package containers import ( "context" + "io" "net/http" "net/url" "strconv" @@ -296,3 +297,22 @@ func Stop(ctx context.Context, nameOrID string, timeout *uint) error { } return response.Process(nil) } + +// Export creates a tarball of the given name or ID of a container. It +// requires an io.Writer be provided to write the tarball. +func Export(ctx context.Context, nameOrID string, w io.Writer) error { + params := url.Values{} + conn, err := bindings.GetClient(ctx) + if err != nil { + return err + } + response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/export", params, nameOrID) + if err != nil { + return err + } + if response.StatusCode/100 == 2 { + _, err = io.Copy(w, response.Body) + return err + } + return response.Process(nil) +} -- cgit v1.2.3-54-g00ecf