Add container update method

This adds an update method to the container interface for the client
package.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-10-03 16:59:52 -04:00
parent 6b9aafdab1
commit 9e85035f15
4 changed files with 86 additions and 6 deletions

View File

@@ -45,6 +45,8 @@ type Container interface {
SetLabels(context.Context, map[string]string) (map[string]string, error)
// Extensions returns the extensions set on the container
Extensions() map[string]prototypes.Any
// Update a container
Update(context.Context, ...UpdateContainerOpts) error
}
func containerFromRecord(client *Client, c containers.Container) *container {
@@ -238,6 +240,27 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation, opts ...Ne
return t, nil
}
func (c *container) Update(ctx context.Context, opts ...UpdateContainerOpts) error {
c.mu.Lock()
defer c.mu.Unlock()
// fetch the current container config before updating it
current, err := c.client.ContainerService().Get(ctx, c.ID())
if err != nil {
return err
}
for _, o := range opts {
if err := o(ctx, c.client, &current); err != nil {
return err
}
}
nc, err := c.client.ContainerService().Update(ctx, current)
if err != nil {
return errdefs.FromGRPC(err)
}
c.c = nc
return nil
}
func (c *container) loadTask(ctx context.Context, ioAttach IOAttach) (Task, error) {
response, err := c.client.TaskService().Get(ctx, &tasks.GetRequest{
ContainerID: c.c.ID,