From 82feafecdda8040432c008d9b79e4f973009adfc Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 16 May 2018 12:38:17 -0500 Subject: podman create, start, getattachsocket First pass at implement API endpoints for create and start. Signed-off-by: baude Closes: #805 Approved by: baude --- pkg/varlinkapi/containers.go | 45 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'pkg/varlinkapi/containers.go') diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go index 9468719fc..43ab3c995 100644 --- a/pkg/varlinkapi/containers.go +++ b/pkg/varlinkapi/containers.go @@ -67,11 +67,6 @@ func (i *LibpodAPI) GetContainer(call ioprojectatomicpodman.VarlinkCall, name st return call.ReplyGetContainer(makeListContainer(ctr.ID(), batchInfo)) } -// CreateContainer ... -func (i *LibpodAPI) CreateContainer(call ioprojectatomicpodman.VarlinkCall) error { - return call.ReplyMethodNotImplemented("CreateContainer") -} - // InspectContainer ... func (i *LibpodAPI) InspectContainer(call ioprojectatomicpodman.VarlinkCall, name string) error { runtime, err := libpodruntime.GetRuntime(i.Cli) @@ -264,8 +259,26 @@ func (i *LibpodAPI) ResizeContainerTty(call ioprojectatomicpodman.VarlinkCall) e } // StartContainer ... -func (i *LibpodAPI) StartContainer(call ioprojectatomicpodman.VarlinkCall) error { - return call.ReplyMethodNotImplemented("StartContainer") +func (i *LibpodAPI) StartContainer(call ioprojectatomicpodman.VarlinkCall, name string) error { + runtime, err := libpodruntime.GetRuntime(i.Cli) + if err != nil { + return call.ReplyRuntimeError(err.Error()) + } + ctr, err := runtime.LookupContainer(name) + if err != nil { + return call.ReplyContainerNotFound(name) + } + state, err := ctr.State() + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + if state == libpod.ContainerStateRunning || state == libpod.ContainerStatePaused { + return call.ReplyErrorOccurred("container is alrady running or paused") + } + if err := ctr.Start(getContext()); err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + return call.ReplyStartContainer(ctr.ID()) } // StopContainer ... @@ -429,3 +442,21 @@ func (i *LibpodAPI) DeleteStoppedContainers(call ioprojectatomicpodman.VarlinkCa } return call.ReplyDeleteStoppedContainers(deletedContainers) } + +// GetAttachSockets ... +func (i *LibpodAPI) GetAttachSockets(call ioprojectatomicpodman.VarlinkCall, name string) error { + runtime, err := libpodruntime.GetRuntime(i.Cli) + if err != nil { + return call.ReplyRuntimeError(err.Error()) + } + ctr, err := runtime.LookupContainer(name) + if err != nil { + return call.ReplyContainerNotFound(name) + } + s := ioprojectatomicpodman.Sockets{ + Container_id: ctr.ID(), + Io_socket: ctr.AttachSocketPath(), + Control_socket: ctr.ControlSocketPath(), + } + return call.ReplyGetAttachSockets(s) +} -- cgit v1.2.3-54-g00ecf