github.com/shishir-a412ed/docker@v1.3.2-0.20180103180333-fda904911d87/libcontainerd/types.go (about)

     1  package libcontainerd
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"time"
     7  
     8  	"github.com/containerd/containerd"
     9  	"github.com/containerd/containerd/cio"
    10  	"github.com/opencontainers/runtime-spec/specs-go"
    11  )
    12  
    13  // EventType represents a possible event from libcontainerd
    14  type EventType string
    15  
    16  // Event constants used when reporting events
    17  const (
    18  	EventUnknown     EventType = "unknown"
    19  	EventExit        EventType = "exit"
    20  	EventOOM         EventType = "oom"
    21  	EventCreate      EventType = "create"
    22  	EventStart       EventType = "start"
    23  	EventExecAdded   EventType = "exec-added"
    24  	EventExecStarted EventType = "exec-started"
    25  	EventPaused      EventType = "paused"
    26  	EventResumed     EventType = "resumed"
    27  )
    28  
    29  // Status represents the current status of a container
    30  type Status string
    31  
    32  // Possible container statuses
    33  const (
    34  	// Running indicates the process is currently executing
    35  	StatusRunning Status = "running"
    36  	// Created indicates the process has been created within containerd but the
    37  	// user's defined process has not started
    38  	StatusCreated Status = "created"
    39  	// Stopped indicates that the process has ran and exited
    40  	StatusStopped Status = "stopped"
    41  	// Paused indicates that the process is currently paused
    42  	StatusPaused Status = "paused"
    43  	// Pausing indicates that the process is currently switching from a
    44  	// running state into a paused state
    45  	StatusPausing Status = "pausing"
    46  	// Unknown indicates that we could not determine the status from the runtime
    47  	StatusUnknown Status = "unknown"
    48  )
    49  
    50  // Remote on Linux defines the accesspoint to the containerd grpc API.
    51  // Remote on Windows is largely an unimplemented interface as there is
    52  // no remote containerd.
    53  type Remote interface {
    54  	// Client returns a new Client instance connected with given Backend.
    55  	NewClient(namespace string, backend Backend) (Client, error)
    56  	// Cleanup stops containerd if it was started by libcontainerd.
    57  	// Note this is not used on Windows as there is no remote containerd.
    58  	Cleanup()
    59  }
    60  
    61  // RemoteOption allows to configure parameters of remotes.
    62  // This is unused on Windows.
    63  type RemoteOption interface {
    64  	Apply(Remote) error
    65  }
    66  
    67  // EventInfo contains the event info
    68  type EventInfo struct {
    69  	ContainerID string
    70  	ProcessID   string
    71  	Pid         uint32
    72  	ExitCode    uint32
    73  	ExitedAt    time.Time
    74  	OOMKilled   bool
    75  	// Windows Only field
    76  	UpdatePending bool
    77  }
    78  
    79  // Backend defines callbacks that the client of the library needs to implement.
    80  type Backend interface {
    81  	ProcessEvent(containerID string, event EventType, ei EventInfo) error
    82  }
    83  
    84  // Client provides access to containerd features.
    85  type Client interface {
    86  	Version(ctx context.Context) (containerd.Version, error)
    87  
    88  	Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
    89  
    90  	Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error
    91  	Start(ctx context.Context, containerID, checkpointDir string, withStdin bool, attachStdio StdioCallback) (pid int, err error)
    92  	SignalProcess(ctx context.Context, containerID, processID string, signal int) error
    93  	Exec(ctx context.Context, containerID, processID string, spec *specs.Process, withStdin bool, attachStdio StdioCallback) (int, error)
    94  	ResizeTerminal(ctx context.Context, containerID, processID string, width, height int) error
    95  	CloseStdin(ctx context.Context, containerID, processID string) error
    96  	Pause(ctx context.Context, containerID string) error
    97  	Resume(ctx context.Context, containerID string) error
    98  	Stats(ctx context.Context, containerID string) (*Stats, error)
    99  	ListPids(ctx context.Context, containerID string) ([]uint32, error)
   100  	Summary(ctx context.Context, containerID string) ([]Summary, error)
   101  	DeleteTask(ctx context.Context, containerID string) (uint32, time.Time, error)
   102  	Delete(ctx context.Context, containerID string) error
   103  	Status(ctx context.Context, containerID string) (Status, error)
   104  
   105  	UpdateResources(ctx context.Context, containerID string, resources *Resources) error
   106  	CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error
   107  }
   108  
   109  // StdioCallback is called to connect a container or process stdio.
   110  type StdioCallback func(*IOPipe) (cio.IO, error)
   111  
   112  // IOPipe contains the stdio streams.
   113  type IOPipe struct {
   114  	Stdin    io.WriteCloser
   115  	Stdout   io.ReadCloser
   116  	Stderr   io.ReadCloser
   117  	Terminal bool // Whether stderr is connected on Windows
   118  
   119  	cancel context.CancelFunc
   120  	config cio.Config
   121  }
   122  
   123  // ServerVersion contains version information as retrieved from the
   124  // server
   125  type ServerVersion struct {
   126  }