summaryrefslogtreecommitdiff
path: root/libpod/adapter
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-15 14:31:03 -0600
committerbaude <bbaude@redhat.com>2019-01-15 14:50:30 -0600
commit341f91da480bbf337dfb13107389307835b1f0c3 (patch)
treec1ace140bfd9cfdbae370404f27159748dc2c851 /libpod/adapter
parent1b2f75298d98f59fac73a63599cdca3478bef835 (diff)
downloadpodman-341f91da480bbf337dfb13107389307835b1f0c3.tar.gz
podman-341f91da480bbf337dfb13107389307835b1f0c3.tar.bz2
podman-341f91da480bbf337dfb13107389307835b1f0c3.zip
Collaberative podman-remote container exists
Began frameout of container super structs for adapted methods. This allows for the use of container exists. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/adapter')
-rw-r--r--libpod/adapter/runtime.go14
-rw-r--r--libpod/adapter/runtime_remote.go74
2 files changed, 84 insertions, 4 deletions
diff --git a/libpod/adapter/runtime.go b/libpod/adapter/runtime.go
index 883ae2c76..b49c91403 100644
--- a/libpod/adapter/runtime.go
+++ b/libpod/adapter/runtime.go
@@ -24,6 +24,11 @@ type ContainerImage struct {
*image.Image
}
+// Container ...
+type Container struct {
+ *libpod.Container
+}
+
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
runtime, err := libpodruntime.GetRuntime(c)
@@ -85,3 +90,12 @@ func (r *LocalRuntime) New(ctx context.Context, name, signaturePolicyPath, authf
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
return r.Runtime.RemoveImage(ctx, img.Image, force)
}
+
+// LookupContainer ...
+func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
+ ctr, err := r.Runtime.LookupContainer(idOrName)
+ if err != nil {
+ return nil, err
+ }
+ return &Container{ctr}, nil
+}
diff --git a/libpod/adapter/runtime_remote.go b/libpod/adapter/runtime_remote.go
index 5413385d2..48dcf76a9 100644
--- a/libpod/adapter/runtime_remote.go
+++ b/libpod/adapter/runtime_remote.go
@@ -22,8 +22,12 @@ type RemoteImageRuntime struct{}
// RemoteRuntime describes a wrapper runtime struct
type RemoteRuntime struct {
+ Conn *varlink.Connection
}
+//func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
+// if _, err := runtime.Runtime.LookupContainer(args[0]); err != nil {
+
// LocalRuntime describes a typical libpod runtime
type LocalRuntime struct {
Runtime *RemoteRuntime
@@ -38,6 +42,7 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
if err != nil {
return nil, err
}
+ runtime.Conn = conn
return &LocalRuntime{
Runtime: &runtime,
Remote: true,
@@ -70,6 +75,30 @@ type remoteImage struct {
Runtime *LocalRuntime
}
+// Container ...
+type Container struct {
+ remoteContainer
+}
+
+// remoteContainer ....
+type remoteContainer struct {
+ ID string
+ Image string
+ ImageID string
+ Command []string
+ Created time.Time
+ RunningFor string
+ Status string
+ //Ports []ocicni.PortMapping
+ RootFsSize int64
+ RWSize int64
+ Names string
+ Labels []map[string]string
+ // Mounts []string
+ // ContainerRunning bool
+ //Namespaces []LinuxNameSpace
+}
+
// GetImages returns a slice of containerimages over a varlink connection
func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
var newImages []*ContainerImage
@@ -213,10 +242,6 @@ func (ci *ContainerImage) TagImage(tag string) error {
return err
}
-func (r RemoteRuntime) RemoveImage(force bool) error {
- return nil
-}
-
// RemoveImage calls varlink to remove an image
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
return iopodman.RemoveImage().Call(r.Conn, img.InputName, force)
@@ -246,3 +271,44 @@ func (ci *ContainerImage) History(ctx context.Context) ([]*image.History, error)
}
return imageHistories, nil
}
+
+// LookupContainer ...
+func (r *RemoteRuntime) LookupContainer(idOrName string) (*Container, error) {
+ container, err := iopodman.GetContainer().Call(r.Conn, idOrName)
+ if err != nil {
+ return nil, err
+ }
+
+ ctr, err := listContainerDataToContainer(container)
+ if err != nil {
+ return nil, err
+ }
+ return ctr, nil
+}
+
+// listContainerDataToContainer takes a varlink listcontainerData struct and makes
+// an "adapted" Container
+func listContainerDataToContainer(listData iopodman.ListContainerData) (*Container, error) {
+ created, err := splitStringDate(listData.Createdat)
+ if err != nil {
+ return nil, err
+ }
+ rc := remoteContainer{
+ ID: listData.Id,
+ Image: listData.Image,
+ ImageID: listData.Imageid,
+ Command: listData.Command,
+ Created: created,
+ RunningFor: listData.Runningfor,
+ Status: listData.Status,
+ //ports: //map[ocicni.portmapping]
+ RootFsSize: listData.Rootfssize,
+ RWSize: listData.Rwsize,
+ Names: listData.Names,
+ //Labels:
+ //Mounts
+ //ContainerRunning: listData.r
+ //namespaces:
+ }
+ return &Container{rc}, nil
+}