types.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package libcontainerd
  2. import (
  3. "io"
  4. containerd "github.com/containerd/containerd/api/grpc/types"
  5. "github.com/opencontainers/runtime-spec/specs-go"
  6. "golang.org/x/net/context"
  7. )
  8. // State constants used in state change reporting.
  9. const (
  10. StateStart = "start-container"
  11. StatePause = "pause"
  12. StateResume = "resume"
  13. StateExit = "exit"
  14. StateRestore = "restore"
  15. StateExitProcess = "exit-process"
  16. StateOOM = "oom" // fake state
  17. )
  18. // CommonStateInfo contains the state info common to all platforms.
  19. type CommonStateInfo struct { // FIXME: event?
  20. State string
  21. Pid uint32
  22. ExitCode uint32
  23. ProcessID string
  24. }
  25. // Backend defines callbacks that the client of the library needs to implement.
  26. type Backend interface {
  27. StateChanged(containerID string, state StateInfo) error
  28. }
  29. // Client provides access to containerd features.
  30. type Client interface {
  31. GetServerVersion(ctx context.Context) (*ServerVersion, error)
  32. Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error
  33. Signal(containerID string, sig int) error
  34. SignalProcess(containerID string, processFriendlyName string, sig int) error
  35. AddProcess(ctx context.Context, containerID, processFriendlyName string, process Process, attachStdio StdioCallback) (int, error)
  36. Resize(containerID, processFriendlyName string, width, height int) error
  37. Pause(containerID string) error
  38. Resume(containerID string) error
  39. Restore(containerID string, attachStdio StdioCallback, options ...CreateOption) error
  40. Stats(containerID string) (*Stats, error)
  41. GetPidsForContainer(containerID string) ([]int, error)
  42. Summary(containerID string) ([]Summary, error)
  43. UpdateResources(containerID string, resources Resources) error
  44. CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error
  45. DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error
  46. ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error)
  47. }
  48. // CreateOption allows to configure parameters of container creation.
  49. type CreateOption interface {
  50. Apply(interface{}) error
  51. }
  52. // StdioCallback is called to connect a container or process stdio.
  53. type StdioCallback func(IOPipe) error
  54. // IOPipe contains the stdio streams.
  55. type IOPipe struct {
  56. Stdin io.WriteCloser
  57. Stdout io.ReadCloser
  58. Stderr io.ReadCloser
  59. Terminal bool // Whether stderr is connected on Windows
  60. }
  61. // ServerVersion contains version information as retrieved from the
  62. // server
  63. type ServerVersion struct {
  64. containerd.GetServerVersionResponse
  65. }