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:
22
container.go
22
container.go
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user