aboutsummaryrefslogtreecommitdiff
path: root/libpod/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/adapter')
-rw-r--r--libpod/adapter/images_remote.go17
-rw-r--r--libpod/adapter/runtime.go29
-rw-r--r--libpod/adapter/runtime_remote.go151
3 files changed, 195 insertions, 2 deletions
diff --git a/libpod/adapter/images_remote.go b/libpod/adapter/images_remote.go
new file mode 100644
index 000000000..77b0629a7
--- /dev/null
+++ b/libpod/adapter/images_remote.go
@@ -0,0 +1,17 @@
+// +build remoteclient
+
+package adapter
+
+import (
+ "github.com/containers/libpod/libpod"
+)
+
+// Images returns information for the host system and its components
+func (r RemoteRuntime) Images() ([]libpod.InfoData, error) {
+ conn, err := r.Connect()
+ if err != nil {
+ return nil, err
+ }
+ _ = conn
+ return nil, nil
+}
diff --git a/libpod/adapter/runtime.go b/libpod/adapter/runtime.go
index b6db51071..13141f886 100644
--- a/libpod/adapter/runtime.go
+++ b/libpod/adapter/runtime.go
@@ -5,6 +5,7 @@ package adapter
import (
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/image"
"github.com/urfave/cli"
)
@@ -14,6 +15,11 @@ type LocalRuntime struct {
Remote bool
}
+// ContainerImage ...
+type ContainerImage struct {
+ *image.Image
+}
+
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
runtime, err := libpodruntime.GetRuntime(c)
@@ -24,3 +30,26 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
Runtime: runtime,
}, nil
}
+
+// GetImages returns a slice of images in containerimages
+func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
+ var containerImages []*ContainerImage
+ images, err := r.Runtime.ImageRuntime().GetImages()
+ if err != nil {
+ return nil, err
+ }
+ for _, i := range images {
+ containerImages = append(containerImages, &ContainerImage{i})
+ }
+ return containerImages, nil
+
+}
+
+// NewImageFromLocal returns a containerimage representation of a image from local storage
+func (r *LocalRuntime) NewImageFromLocal(name string) (*ContainerImage, error) {
+ img, err := r.Runtime.ImageRuntime().NewFromLocal(name)
+ if err != nil {
+ return nil, err
+ }
+ return &ContainerImage{img}, nil
+}
diff --git a/libpod/adapter/runtime_remote.go b/libpod/adapter/runtime_remote.go
index 715728d21..2f22dd36b 100644
--- a/libpod/adapter/runtime_remote.go
+++ b/libpod/adapter/runtime_remote.go
@@ -2,23 +2,43 @@
package adapter
-import "github.com/urfave/cli"
+import (
+ "context"
+ "fmt"
+ "github.com/containers/libpod/cmd/podman/varlink"
+ "github.com/containers/libpod/libpod/image"
+ "github.com/opencontainers/go-digest"
+ "github.com/urfave/cli"
+ "github.com/varlink/go/varlink"
+ "strings"
+ "time"
+)
+
+// ImageRuntime is wrapper for image runtime
+type RemoteImageRuntime struct{}
// RemoteRuntime describes a wrapper runtime struct
-type RemoteRuntime struct{}
+type RemoteRuntime struct {
+}
// LocalRuntime describes a typical libpod runtime
type LocalRuntime struct {
Runtime *RemoteRuntime
Remote bool
+ Conn *varlink.Connection
}
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
runtime := RemoteRuntime{}
+ conn, err := runtime.Connect()
+ if err != nil {
+ return nil, err
+ }
return &LocalRuntime{
Runtime: &runtime,
Remote: true,
+ Conn: conn,
}, nil
}
@@ -26,3 +46,130 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
func (r RemoteRuntime) Shutdown(force bool) error {
return nil
}
+
+// ContainerImage
+type ContainerImage struct {
+ remoteImage
+}
+
+type remoteImage struct {
+ ID string
+ Labels map[string]string
+ RepoTags []string
+ RepoDigests []string
+ Parent string
+ Size int64
+ Tag string
+ Repository string
+ Created time.Time
+ InputName string
+ Names []string
+ Digest digest.Digest
+ isParent bool
+}
+
+// GetImages returns a slice of containerimages over a varlink connection
+func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
+ var newImages []*ContainerImage
+ images, err := iopodman.ListImages().Call(r.Conn)
+ if err != nil {
+ return nil, err
+ }
+ for _, i := range images {
+ name := i.Id
+ if len(i.RepoTags) > 1 {
+ name = i.RepoTags[0]
+ }
+ newImage, err := imageInListToContainerImage(i, name)
+ if err != nil {
+ return nil, err
+ }
+ newImages = append(newImages, newImage)
+ }
+ return newImages, nil
+}
+
+func imageInListToContainerImage(i iopodman.ImageInList, name string) (*ContainerImage, error) {
+ imageParts, err := image.DecomposeString(name)
+ if err != nil {
+ return nil, err
+ }
+ created, err := splitStringDate(i.Created)
+ if err != nil {
+ return nil, err
+ }
+ ri := remoteImage{
+ InputName: name,
+ ID: i.Id,
+ Labels: i.Labels,
+ RepoTags: i.RepoTags,
+ RepoDigests: i.RepoTags,
+ Parent: i.ParentId,
+ Size: i.Size,
+ Created: created,
+ Tag: imageParts.Tag,
+ Repository: imageParts.Registry,
+ Names: i.RepoTags,
+ isParent: i.IsParent,
+ }
+ return &ContainerImage{ri}, nil
+}
+
+// NewImageFromLocal returns a container image representation of a image over varlink
+func (r *LocalRuntime) NewImageFromLocal(name string) (*ContainerImage, error) {
+ img, err := iopodman.GetImage().Call(r.Conn, name)
+ if err != nil {
+ return nil, err
+ }
+ return imageInListToContainerImage(img, name)
+
+}
+
+func splitStringDate(d string) (time.Time, error) {
+ fields := strings.Fields(d)
+ t := fmt.Sprintf("%sT%sZ", fields[0], fields[1])
+ return time.ParseInLocation(time.RFC3339Nano, t, time.UTC)
+}
+
+// IsParent goes through the layers in the store and checks if i.TopLayer is
+// the parent of any other layer in store. Double check that image with that
+// layer exists as well.
+func (ci *ContainerImage) IsParent() (bool, error) {
+ return ci.remoteImage.isParent, nil
+}
+
+// ID returns the image ID as a string
+func (ci *ContainerImage) ID() string {
+ return ci.remoteImage.ID
+}
+
+// Names returns a string array of names associated with the image
+func (ci *ContainerImage) Names() []string {
+ return ci.remoteImage.Names
+}
+
+// Created returns the time the image was created
+func (ci *ContainerImage) Created() time.Time {
+ return ci.remoteImage.Created
+}
+
+// Size returns the size of the image
+func (ci *ContainerImage) Size(ctx context.Context) (*uint64, error) {
+ usize := uint64(ci.remoteImage.Size)
+ return &usize, nil
+}
+
+// Digest returns the image's digest
+func (ci *ContainerImage) Digest() digest.Digest {
+ return ci.remoteImage.Digest
+}
+
+// Labels returns a map of the image's labels
+func (ci *ContainerImage) Labels(ctx context.Context) (map[string]string, error) {
+ return ci.remoteImage.Labels, nil
+}
+
+// Dangling returns a bool if the image is "dangling"
+func (ci *ContainerImage) Dangling() bool {
+ return len(ci.Names()) == 0
+}