2017-02-24 23:50:59 +00:00
|
|
|
package linux
|
2017-02-13 18:23:28 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/containerd"
|
|
|
|
"github.com/docker/containerd/api/services/shim"
|
2017-03-02 09:42:55 +00:00
|
|
|
"github.com/docker/containerd/api/types/container"
|
2017-02-13 18:23:28 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type State struct {
|
|
|
|
pid uint32
|
|
|
|
status containerd.ContainerStatus
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s State) Pid() uint32 {
|
|
|
|
return s.pid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s State) Status() containerd.ContainerStatus {
|
|
|
|
return s.status
|
|
|
|
}
|
|
|
|
|
|
|
|
type Container struct {
|
|
|
|
id string
|
|
|
|
|
|
|
|
shim shim.ShimClient
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:59:58 +00:00
|
|
|
func (c *Container) Info() containerd.ContainerInfo {
|
|
|
|
return containerd.ContainerInfo{
|
|
|
|
ID: c.id,
|
|
|
|
Runtime: runtimeName,
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) Start(ctx context.Context) error {
|
|
|
|
_, err := c.shim.Start(ctx, &shim.StartRequest{})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) State(ctx context.Context) (containerd.State, error) {
|
|
|
|
response, err := c.shim.State(ctx, &shim.StateRequest{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-02 09:42:55 +00:00
|
|
|
var status containerd.ContainerStatus
|
|
|
|
switch response.Status {
|
|
|
|
case container.Status_CREATED:
|
|
|
|
status = containerd.CreatedStatus
|
|
|
|
case container.Status_RUNNING:
|
|
|
|
status = containerd.RunningStatus
|
|
|
|
case container.Status_STOPPED:
|
|
|
|
status = containerd.StoppedStatus
|
|
|
|
case container.Status_PAUSED:
|
|
|
|
status = containerd.PausedStatus
|
|
|
|
// TODO: containerd.DeletedStatus
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
return &State{
|
2017-03-02 09:42:55 +00:00
|
|
|
pid: response.Pid,
|
|
|
|
status: status,
|
2017-02-13 18:23:28 +00:00
|
|
|
}, nil
|
|
|
|
}
|