summaryrefslogtreecommitdiff
path: root/libpod/adapter/runtime_remote.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/adapter/runtime_remote.go')
-rw-r--r--libpod/adapter/runtime_remote.go105
1 files changed, 105 insertions, 0 deletions
diff --git a/libpod/adapter/runtime_remote.go b/libpod/adapter/runtime_remote.go
index 0633c036d..c73e98c95 100644
--- a/libpod/adapter/runtime_remote.go
+++ b/libpod/adapter/runtime_remote.go
@@ -3,11 +3,13 @@
package adapter
import (
+ "bufio"
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io"
+ "os"
"strings"
"time"
@@ -324,6 +326,109 @@ func (r *LocalRuntime) Config(name string) *libpod.ContainerConfig {
return &data
}
+
+// PruneImages is the wrapper call for a remote-client to prune images
func (r *LocalRuntime) PruneImages(all bool) ([]string, error) {
return iopodman.ImagesPrune().Call(r.Conn, all)
}
+
+// Export is a wrapper to container export to a tarfile
+func (r *LocalRuntime) Export(name string, path string) error {
+ tempPath, err := iopodman.ExportContainer().Call(r.Conn, name, "")
+ if err != nil {
+ return err
+ }
+
+ outputFile, err := os.Create(path)
+ if err != nil {
+ return err
+ }
+ defer outputFile.Close()
+
+ writer := bufio.NewWriter(outputFile)
+ defer writer.Flush()
+
+ reply, err := iopodman.ReceiveFile().Send(r.Conn, varlink.Upgrade, tempPath, true)
+ if err != nil {
+ return err
+ }
+
+ length, _, err := reply()
+ if err != nil {
+ return errors.Wrap(err, "unable to get file length for transfer")
+ }
+
+ reader := r.Conn.Reader
+ if _, err := io.CopyN(writer, reader, length); err != nil {
+ return errors.Wrap(err, "file transer failed")
+ }
+
+ return nil
+}
+
+// Import implements the remote calls required to import a container image to the store
+func (r *LocalRuntime) Import(ctx context.Context, source, reference string, changes []string, history string, quiet bool) (string, error) {
+ // First we send the file to the host
+ fs, err := os.Open(source)
+ if err != nil {
+ return "", err
+ }
+
+ fileInfo, err := fs.Stat()
+ if err != nil {
+ return "", err
+ }
+ reply, err := iopodman.SendFile().Send(r.Conn, varlink.Upgrade, "", int64(fileInfo.Size()))
+ if err != nil {
+ return "", err
+ }
+ _, _, err = reply()
+ if err != nil {
+ return "", err
+ }
+
+ reader := bufio.NewReader(fs)
+ _, err = reader.WriteTo(r.Conn.Writer)
+ if err != nil {
+ return "", err
+ }
+ r.Conn.Writer.Flush()
+
+ // All was sent, wait for the ACK from the server
+ tempFile, err := r.Conn.Reader.ReadString(':')
+ if err != nil {
+ return "", err
+ }
+
+ // r.Conn is kaput at this point due to the upgrade
+ if err := r.RemoteRuntime.RefreshConnection(); err != nil {
+ return "", err
+
+ }
+ return iopodman.ImportImage().Call(r.Conn, strings.TrimRight(tempFile, ":"), reference, history, changes, true)
+}
+
+// GetAllVolumes retrieves all the volumes
+func (r *LocalRuntime) GetAllVolumes() ([]*libpod.Volume, error) {
+ return nil, libpod.ErrNotImplemented
+}
+
+// RemoveVolume removes a volumes
+func (r *LocalRuntime) RemoveVolume(ctx context.Context, v *libpod.Volume, force, prune bool) error {
+ return libpod.ErrNotImplemented
+}
+
+// GetContainers retrieves all containers from the state
+// Filters can be provided which will determine what containers are included in
+// the output. Multiple filters are handled by ANDing their output, so only
+// containers matching all filters are returned
+func (r *LocalRuntime) GetContainers(filters ...libpod.ContainerFilter) ([]*libpod.Container, error) {
+ return nil, libpod.ErrNotImplemented
+}
+
+// RemoveContainer removes the given container
+// If force is specified, the container will be stopped first
+// Otherwise, RemoveContainer will return an error if the container is running
+func (r *LocalRuntime) RemoveContainer(ctx context.Context, c *libpod.Container, force bool) error {
+ return libpod.ErrNotImplemented
+}