interface.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package hcsshim
  2. import (
  3. "io"
  4. "time"
  5. "github.com/Microsoft/hcsshim/internal/schema1"
  6. )
  7. // ProcessConfig is used as both the input of Container.CreateProcess
  8. // and to convert the parameters to JSON for passing onto the HCS
  9. type ProcessConfig = schema1.ProcessConfig
  10. type Layer = schema1.Layer
  11. type MappedDir = schema1.MappedDir
  12. type MappedPipe = schema1.MappedPipe
  13. type HvRuntime = schema1.HvRuntime
  14. type MappedVirtualDisk = schema1.MappedVirtualDisk
  15. // AssignedDevice represents a device that has been directly assigned to a container
  16. //
  17. // NOTE: Support added in RS5
  18. type AssignedDevice = schema1.AssignedDevice
  19. // ContainerConfig is used as both the input of CreateContainer
  20. // and to convert the parameters to JSON for passing onto the HCS
  21. type ContainerConfig = schema1.ContainerConfig
  22. type ComputeSystemQuery = schema1.ComputeSystemQuery
  23. // Container represents a created (but not necessarily running) container.
  24. type Container interface {
  25. // Start synchronously starts the container.
  26. Start() error
  27. // Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
  28. Shutdown() error
  29. // Terminate requests a container terminate, but it may not actually be terminated until Wait() succeeds.
  30. Terminate() error
  31. // Waits synchronously waits for the container to shutdown or terminate.
  32. Wait() error
  33. // WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
  34. // returns false if timeout occurs.
  35. WaitTimeout(time.Duration) error
  36. // Pause pauses the execution of a container.
  37. Pause() error
  38. // Resume resumes the execution of a container.
  39. Resume() error
  40. // HasPendingUpdates returns true if the container has updates pending to install.
  41. HasPendingUpdates() (bool, error)
  42. // Statistics returns statistics for a container.
  43. Statistics() (Statistics, error)
  44. // ProcessList returns details for the processes in a container.
  45. ProcessList() ([]ProcessListItem, error)
  46. // MappedVirtualDisks returns virtual disks mapped to a utility VM, indexed by controller
  47. MappedVirtualDisks() (map[int]MappedVirtualDiskController, error)
  48. // CreateProcess launches a new process within the container.
  49. CreateProcess(c *ProcessConfig) (Process, error)
  50. // OpenProcess gets an interface to an existing process within the container.
  51. OpenProcess(pid int) (Process, error)
  52. // Close cleans up any state associated with the container but does not terminate or wait for it.
  53. Close() error
  54. // Modify the System
  55. Modify(config *ResourceModificationRequestResponse) error
  56. }
  57. // Process represents a running or exited process.
  58. type Process interface {
  59. // Pid returns the process ID of the process within the container.
  60. Pid() int
  61. // Kill signals the process to terminate but does not wait for it to finish terminating.
  62. Kill() error
  63. // Wait waits for the process to exit.
  64. Wait() error
  65. // WaitTimeout waits for the process to exit or the duration to elapse. It returns
  66. // false if timeout occurs.
  67. WaitTimeout(time.Duration) error
  68. // ExitCode returns the exit code of the process. The process must have
  69. // already terminated.
  70. ExitCode() (int, error)
  71. // ResizeConsole resizes the console of the process.
  72. ResizeConsole(width, height uint16) error
  73. // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
  74. // these pipes does not close the underlying pipes; it should be possible to
  75. // call this multiple times to get multiple interfaces.
  76. Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error)
  77. // CloseStdin closes the write side of the stdin pipe so that the process is
  78. // notified on the read side that there is no more data in stdin.
  79. CloseStdin() error
  80. // Close cleans up any state associated with the process but does not kill
  81. // or wait on it.
  82. Close() error
  83. }