summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/util.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-04-27 14:00:32 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-03 17:31:33 +0000
commit8dfebd4607c1152bd26c4a586e6d56a196c56e54 (patch)
treee4fdfcc0b1813fccd2ee6134931afbf2725a8208 /pkg/varlinkapi/util.go
parentfae5033a01b78d3e8f23c1c9438bc5534dfe0fa3 (diff)
downloadpodman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.tar.gz
podman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.tar.bz2
podman-8dfebd4607c1152bd26c4a586e6d56a196c56e54.zip
varlink containers
first pass at adding in the container related endpoints/methods for the libpod backend. Couple of important notes: * endpoints that can use a console are not going to be done until we have "remote" console * several of the container methods should probably be able to stream as opposed to a one-off return Signed-off-by: baude <bbaude@redhat.com> Closes: #708 Approved by: baude
Diffstat (limited to 'pkg/varlinkapi/util.go')
-rw-r--r--pkg/varlinkapi/util.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/pkg/varlinkapi/util.go b/pkg/varlinkapi/util.go
index ff0fb6ecb..25ab59801 100644
--- a/pkg/varlinkapi/util.go
+++ b/pkg/varlinkapi/util.go
@@ -2,9 +2,76 @@ package varlinkapi
import (
"context"
+ "strconv"
+ "time"
+
+ "github.com/projectatomic/libpod/cmd/podman/batchcontainer"
+ "github.com/projectatomic/libpod/cmd/podman/varlink"
+ "github.com/projectatomic/libpod/libpod"
)
// getContext returns a non-nil, empty context
func getContext() context.Context {
return context.TODO()
}
+
+func makeListContainer(containerID string, batchInfo batchcontainer.BatchContainerStruct) ioprojectatomicpodman.ListContainerData {
+ var (
+ mounts []ioprojectatomicpodman.ContainerMount
+ ports []ioprojectatomicpodman.ContainerPortMappings
+ )
+ ns := batchcontainer.GetNamespaces(batchInfo.Pid)
+
+ for _, mount := range batchInfo.ConConfig.Spec.Mounts {
+ m := ioprojectatomicpodman.ContainerMount{
+ Destination: mount.Destination,
+ Type: mount.Type,
+ Source: mount.Source,
+ Options: mount.Options,
+ }
+ mounts = append(mounts, m)
+ }
+
+ for _, pm := range batchInfo.ConConfig.PortMappings {
+ p := ioprojectatomicpodman.ContainerPortMappings{
+ Host_port: strconv.Itoa(int(pm.HostPort)),
+ Host_ip: pm.HostIP,
+ Protocol: pm.Protocol,
+ Container_port: strconv.Itoa(int(pm.ContainerPort)),
+ }
+ ports = append(ports, p)
+
+ }
+
+ // If we find this needs to be done for other container endpoints, we should
+ // convert this to a separate function or a generic map from struct function.
+ namespace := ioprojectatomicpodman.ContainerNameSpace{
+ User: ns.User,
+ Uts: ns.UTS,
+ Pidns: ns.PIDNS,
+ Pid: ns.PID,
+ Cgroup: ns.Cgroup,
+ Net: ns.NET,
+ Mnt: ns.MNT,
+ Ipc: ns.IPC,
+ }
+
+ lc := ioprojectatomicpodman.ListContainerData{
+ Id: containerID,
+ Image: batchInfo.ConConfig.RootfsImageName,
+ Imageid: batchInfo.ConConfig.RootfsImageID,
+ Command: batchInfo.ConConfig.Spec.Process.Args,
+ Createdat: batchInfo.ConConfig.CreatedTime.String(),
+ Runningfor: time.Since(batchInfo.ConConfig.CreatedTime).String(),
+ Status: batchInfo.ConState.String(),
+ Ports: ports,
+ Rootfssize: batchInfo.RootFsSize,
+ Rwsize: batchInfo.RwSize,
+ Names: batchInfo.ConConfig.Name,
+ Labels: batchInfo.ConConfig.Labels,
+ Mounts: mounts,
+ Containerrunning: batchInfo.ConState == libpod.ContainerStateRunning,
+ Namespaces: namespace,
+ }
+ return lc
+}