types.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }
  30. // Client provides access to containerd features.
  31. type Client interface {
  32. Create(containerID string, spec 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) 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. }
  45. // CreateOption allows to configure parameters of container creation.
  46. type CreateOption interface {
  47. Apply(interface{}) error
  48. }
  49. // StdioCallback is called to connect a container or process stdio.
  50. type StdioCallback func(IOPipe) error
  51. // IOPipe contains the stdio streams.
  52. type IOPipe struct {
  53. Stdin io.WriteCloser
  54. Stdout io.ReadCloser
  55. Stderr io.ReadCloser
  56. Terminal bool // Whether stderr is connected on Windows
  57. }