Add NewContainer and Delete container support

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-05-24 10:42:37 -07:00
parent d0e5732f0b
commit 31a3bda41b
3 changed files with 171 additions and 5 deletions

View File

@@ -1,21 +1,47 @@
package containerd
import "github.com/containerd/containerd/api/services/containers"
import (
"context"
"encoding/json"
"github.com/containerd/containerd/api/services/containers"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func containerFromProto(client *Client, c containers.Container) *Container {
return &Container{
client: client,
id: c.ID,
c: c,
}
}
type Container struct {
client *Client
id string
c containers.Container
}
// ID returns the container's unique id
func (c *Container) ID() string {
return c.id
return c.c.ID
}
// Spec returns the current OCI specification for the container
func (c *Container) Spec() (*specs.Spec, error) {
var s specs.Spec
if err := json.Unmarshal(c.c.Spec.Value, &s); err != nil {
return nil, err
}
return &s, nil
}
// Delete deletes an existing container
// an error is returned if the container has running tasks
func (c *Container) Delete(ctx context.Context) error {
// TODO: should the client be the one removing resources attached
// to the container at the moment before we have GC?
_, err := c.client.containers().Delete(ctx, &containers.DeleteContainerRequest{
ID: c.c.ID,
})
return err
}