types.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package libcontainerd
  2. import (
  3. "io"
  4. "golang.org/x/net/context"
  5. )
  6. // State constants used in state change reporting.
  7. const (
  8. StateStart = "start-container"
  9. StatePause = "pause"
  10. StateResume = "resume"
  11. StateExit = "exit"
  12. StateRestart = "restart"
  13. StateRestore = "restore"
  14. StateStartProcess = "start-process"
  15. StateExitProcess = "exit-process"
  16. StateOOM = "oom" // fake state
  17. stateLive = "live"
  18. )
  19. // CommonStateInfo contains the state info common to all platforms.
  20. type CommonStateInfo struct { // FIXME: event?
  21. State string
  22. Pid uint32
  23. ExitCode uint32
  24. ProcessID string
  25. }
  26. // Backend defines callbacks that the client of the library needs to implement.
  27. type Backend interface {
  28. StateChanged(containerID string, state StateInfo) error
  29. AttachStreams(processFriendlyName string, io IOPipe) error
  30. }
  31. // Client provides access to containerd features.
  32. type Client interface {
  33. Create(containerID string, spec Spec, options ...CreateOption) error
  34. Signal(containerID string, sig int) error
  35. SignalProcess(containerID string, processFriendlyName string, sig int) error
  36. AddProcess(ctx context.Context, containerID, processFriendlyName string, process Process) error
  37. Resize(containerID, processFriendlyName string, width, height int) error
  38. Pause(containerID string) error
  39. Resume(containerID string) error
  40. Restore(containerID string, options ...CreateOption) error
  41. Stats(containerID string) (*Stats, error)
  42. GetPidsForContainer(containerID string) ([]int, error)
  43. Summary(containerID string) ([]Summary, error)
  44. UpdateResources(containerID string, resources Resources) error
  45. }
  46. // CreateOption allows to configure parameters of container creation.
  47. type CreateOption interface {
  48. Apply(interface{}) error
  49. }
  50. // IOPipe contains the stdio streams.
  51. type IOPipe struct {
  52. Stdin io.WriteCloser
  53. Stdout io.Reader
  54. Stderr io.Reader
  55. Terminal bool // Whether stderr is connected on Windows
  56. }