2017-09-05 14:29:17 +00:00
|
|
|
package libpod
|
2017-08-11 16:42:25 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-06 15:15:11 +00:00
|
|
|
"sync"
|
2017-08-17 14:43:02 +00:00
|
|
|
|
|
|
|
"github.com/containers/storage"
|
2017-09-06 15:15:11 +00:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
|
|
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
2017-09-11 15:27:40 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-09-06 15:15:11 +00:00
|
|
|
"github.com/ulule/deepcopier"
|
2017-08-11 16:42:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Container is a single OCI container
|
|
|
|
type Container struct {
|
2017-09-06 15:15:11 +00:00
|
|
|
id string
|
|
|
|
name string
|
|
|
|
|
|
|
|
spec *spec.Spec
|
|
|
|
pod *Pod
|
|
|
|
|
|
|
|
valid bool
|
|
|
|
lock sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the container's ID
|
|
|
|
func (c *Container) ID() string {
|
|
|
|
// No locking needed, ID will never mutate after a container is created
|
|
|
|
return c.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the container's name
|
|
|
|
func (c *Container) Name() string {
|
|
|
|
// Name can potentially be changed while a container is running
|
|
|
|
// So lock access to it
|
|
|
|
c.lock.RLock()
|
|
|
|
defer c.lock.RUnlock()
|
|
|
|
|
|
|
|
return c.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spec returns the container's OCI runtime spec
|
|
|
|
func (c *Container) Spec() *spec.Spec {
|
|
|
|
// The spec can potentially be altered when storage is configured and to
|
|
|
|
// add annotations at container create time
|
|
|
|
// As such, access to it is locked
|
|
|
|
c.lock.RLock()
|
|
|
|
defer c.lock.RUnlock()
|
|
|
|
|
|
|
|
spec := new(spec.Spec)
|
|
|
|
deepcopier.Copy(c.spec).To(spec)
|
|
|
|
|
|
|
|
return spec
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a new container
|
|
|
|
func newContainer(rspec *spec.Spec) (*Container, error) {
|
|
|
|
if rspec == nil {
|
2017-09-11 15:27:40 +00:00
|
|
|
return nil, errors.Wrapf(ErrInvalidArg, "must provide a valid runtime spec to create container")
|
2017-09-06 15:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctr := new(Container)
|
|
|
|
ctr.id = stringid.GenerateNonCryptoID()
|
|
|
|
ctr.name = ctr.id // TODO generate unique human-readable names
|
|
|
|
|
|
|
|
ctr.spec = new(spec.Spec)
|
|
|
|
deepcopier.Copy(rspec).To(ctr.spec)
|
|
|
|
|
|
|
|
return ctr, nil
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create creates a container in the OCI runtime
|
|
|
|
func (c *Container) Create() error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts a container
|
|
|
|
func (c *Container) Start() error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop stops a container
|
|
|
|
func (c *Container) Stop() error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kill sends a signal to a container
|
|
|
|
func (c *Container) Kill(signal uint) error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exec starts a new process inside the container
|
2017-08-15 18:33:40 +00:00
|
|
|
// Returns fully qualified URL of streaming server for executed process
|
|
|
|
func (c *Container) Exec(cmd []string, tty bool, stdin bool) (string, error) {
|
2017-09-11 15:27:40 +00:00
|
|
|
return "", ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attach attaches to a container
|
2017-08-15 18:33:40 +00:00
|
|
|
// Returns fully qualified URL of streaming server for the container
|
|
|
|
func (c *Container) Attach(stdin, tty bool) (string, error) {
|
2017-09-11 15:27:40 +00:00
|
|
|
return "", ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mount mounts a container's filesystem on the host
|
|
|
|
// The path where the container has been mounted is returned
|
|
|
|
func (c *Container) Mount() (string, error) {
|
2017-09-11 15:27:40 +00:00
|
|
|
return "", ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Status gets a container's status
|
|
|
|
// TODO this should return relevant information about container state
|
|
|
|
func (c *Container) Status() error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-11 16:42:25 +00:00
|
|
|
}
|
2017-08-17 14:43:02 +00:00
|
|
|
|
|
|
|
// Export exports a container's root filesystem as a tar archive
|
|
|
|
// The archive will be saved as a file at the given path
|
|
|
|
func (c *Container) Export(path string) error {
|
2017-09-11 15:27:40 +00:00
|
|
|
return ErrNotImplemented
|
2017-08-17 14:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Commit commits the changes between a container and its image, creating a new
|
|
|
|
// image
|
|
|
|
// If the container was not created from an image (for example,
|
|
|
|
// WithRootFSFromPath will create a container from a directory on the system),
|
|
|
|
// a new base image will be created from the contents of the container's
|
|
|
|
// filesystem
|
|
|
|
func (c *Container) Commit() (*storage.Image, error) {
|
2017-09-11 15:27:40 +00:00
|
|
|
return nil, ErrNotImplemented
|
2017-08-17 14:43:02 +00:00
|
|
|
}
|