Add Load for container and Task with Attach

This adds both container and task loading of running tasks as well as
reattaching to the IO of the task after load.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-05-31 16:29:41 -07:00
parent 1db752bca8
commit 43fb19e01c
7 changed files with 228 additions and 47 deletions

View File

@@ -16,6 +16,7 @@ type Container interface {
NewTask(context.Context, IOCreation) (Task, error)
Spec() (*specs.Spec, error)
Task() Task
LoadTask(context.Context, IOCreation) (Task, error)
}
func containerFromProto(client *Client, c containers.Container) *container {
@@ -108,3 +109,24 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation) (Task, err
c.task = t
return t, nil
}
func (c *container) LoadTask(ctx context.Context, ioCreate IOCreation) (Task, error) {
i, err := ioCreate()
if err != nil {
return nil, err
}
response, err := c.client.TaskService().Info(ctx, &execution.InfoRequest{
ContainerID: c.c.ID,
})
if err != nil {
return nil, err
}
t := &task{
client: c.client,
io: i,
containerID: response.Task.ContainerID,
pid: response.Task.Pid,
}
c.task = t
return t, nil
}