interface.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package hcsshim
  2. import (
  3. "encoding/json"
  4. "io"
  5. "time"
  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 struct {
  10. ApplicationName string `json:",omitempty"`
  11. CommandLine string `json:",omitempty"`
  12. CommandArgs []string `json:",omitempty"` // Used by Linux Containers on Windows
  13. User string `json:",omitempty"`
  14. WorkingDirectory string `json:",omitempty"`
  15. Environment map[string]string `json:",omitempty"`
  16. EmulateConsole bool `json:",omitempty"`
  17. CreateStdInPipe bool `json:",omitempty"`
  18. CreateStdOutPipe bool `json:",omitempty"`
  19. CreateStdErrPipe bool `json:",omitempty"`
  20. ConsoleSize [2]uint `json:",omitempty"`
  21. CreateInUtilityVm bool `json:",omitempty"` // Used by Linux Containers on Windows
  22. OCISpecification *json.RawMessage `json:",omitempty"` // Used by Linux Containers on Windows
  23. }
  24. type Layer struct {
  25. ID string
  26. Path string
  27. }
  28. type MappedDir struct {
  29. HostPath string
  30. ContainerPath string
  31. ReadOnly bool
  32. BandwidthMaximum uint64
  33. IOPSMaximum uint64
  34. }
  35. type MappedPipe struct {
  36. HostPath string
  37. ContainerPipeName string
  38. }
  39. type HvRuntime struct {
  40. ImagePath string `json:",omitempty"`
  41. SkipTemplate bool `json:",omitempty"`
  42. LinuxInitrdFile string `json:",omitempty"` // File under ImagePath on host containing an initrd image for starting a Linux utility VM
  43. LinuxKernelFile string `json:",omitempty"` // File under ImagePath on host containing a kernel for starting a Linux utility VM
  44. LinuxBootParameters string `json:",omitempty"` // Additional boot parameters for starting a Linux Utility VM in initrd mode
  45. BootSource string `json:",omitempty"` // "Vhd" for Linux Utility VM booting from VHD
  46. WritableBootSource bool `json:",omitempty"` // Linux Utility VM booting from VHD
  47. }
  48. type MappedVirtualDisk struct {
  49. HostPath string `json:",omitempty"` // Path to VHD on the host
  50. ContainerPath string // Platform-specific mount point path in the container
  51. CreateInUtilityVM bool `json:",omitempty"`
  52. ReadOnly bool `json:",omitempty"`
  53. Cache string `json:",omitempty"` // "" (Unspecified); "Disabled"; "Enabled"; "Private"; "PrivateAllowSharing"
  54. AttachOnly bool `json:",omitempty:`
  55. }
  56. // ContainerConfig is used as both the input of CreateContainer
  57. // and to convert the parameters to JSON for passing onto the HCS
  58. type ContainerConfig struct {
  59. SystemType string // HCS requires this to be hard-coded to "Container"
  60. Name string // Name of the container. We use the docker ID.
  61. Owner string `json:",omitempty"` // The management platform that created this container
  62. VolumePath string `json:",omitempty"` // Windows volume path for scratch space. Used by Windows Server Containers only. Format \\?\\Volume{GUID}
  63. IgnoreFlushesDuringBoot bool `json:",omitempty"` // Optimization hint for container startup in Windows
  64. LayerFolderPath string `json:",omitempty"` // Where the layer folders are located. Used by Windows Server Containers only. Format %root%\windowsfilter\containerID
  65. Layers []Layer // List of storage layers. Required for Windows Server and Hyper-V Containers. Format ID=GUID;Path=%root%\windowsfilter\layerID
  66. Credentials string `json:",omitempty"` // Credentials information
  67. ProcessorCount uint32 `json:",omitempty"` // Number of processors to assign to the container.
  68. ProcessorWeight uint64 `json:",omitempty"` // CPU shares (relative weight to other containers with cpu shares). Range is from 1 to 10000. A value of 0 results in default shares.
  69. ProcessorMaximum int64 `json:",omitempty"` // Specifies the portion of processor cycles that this container can use as a percentage times 100. Range is from 1 to 10000. A value of 0 results in no limit.
  70. StorageIOPSMaximum uint64 `json:",omitempty"` // Maximum Storage IOPS
  71. StorageBandwidthMaximum uint64 `json:",omitempty"` // Maximum Storage Bandwidth in bytes per second
  72. StorageSandboxSize uint64 `json:",omitempty"` // Size in bytes that the container system drive should be expanded to if smaller
  73. MemoryMaximumInMB int64 `json:",omitempty"` // Maximum memory available to the container in Megabytes
  74. HostName string `json:",omitempty"` // Hostname
  75. MappedDirectories []MappedDir `json:",omitempty"` // List of mapped directories (volumes/mounts)
  76. MappedPipes []MappedPipe `json:",omitempty"` // List of mapped Windows named pipes
  77. HvPartition bool // True if it a Hyper-V Container
  78. NetworkSharedContainerName string `json:",omitempty"` // Name (ID) of the container that we will share the network stack with.
  79. EndpointList []string `json:",omitempty"` // List of networking endpoints to be attached to container
  80. HvRuntime *HvRuntime `json:",omitempty"` // Hyper-V container settings. Used by Hyper-V containers only. Format ImagePath=%root%\BaseLayerID\UtilityVM
  81. Servicing bool `json:",omitempty"` // True if this container is for servicing
  82. AllowUnqualifiedDNSQuery bool `json:",omitempty"` // True to allow unqualified DNS name resolution
  83. DNSSearchList string `json:",omitempty"` // Comma seperated list of DNS suffixes to use for name resolution
  84. ContainerType string `json:",omitempty"` // "Linux" for Linux containers on Windows. Omitted otherwise.
  85. TerminateOnLastHandleClosed bool `json:",omitempty"` // Should HCS terminate the container once all handles have been closed
  86. MappedVirtualDisks []MappedVirtualDisk `json:",omitempty"` // Array of virtual disks to mount at start
  87. }
  88. type ComputeSystemQuery struct {
  89. IDs []string `json:"Ids,omitempty"`
  90. Types []string `json:",omitempty"`
  91. Names []string `json:",omitempty"`
  92. Owners []string `json:",omitempty"`
  93. }
  94. // Container represents a created (but not necessarily running) container.
  95. type Container interface {
  96. // Start synchronously starts the container.
  97. Start() error
  98. // Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
  99. Shutdown() error
  100. // Terminate requests a container terminate, but it may not actually be terminated until Wait() succeeds.
  101. Terminate() error
  102. // Waits synchronously waits for the container to shutdown or terminate.
  103. Wait() error
  104. // WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
  105. // returns false if timeout occurs.
  106. WaitTimeout(time.Duration) error
  107. // Pause pauses the execution of a container.
  108. Pause() error
  109. // Resume resumes the execution of a container.
  110. Resume() error
  111. // HasPendingUpdates returns true if the container has updates pending to install.
  112. HasPendingUpdates() (bool, error)
  113. // Statistics returns statistics for a container.
  114. Statistics() (Statistics, error)
  115. // ProcessList returns details for the processes in a container.
  116. ProcessList() ([]ProcessListItem, error)
  117. // MappedVirtualDisks returns virtual disks mapped to a utility VM, indexed by controller
  118. MappedVirtualDisks() (map[int]MappedVirtualDiskController, error)
  119. // CreateProcess launches a new process within the container.
  120. CreateProcess(c *ProcessConfig) (Process, error)
  121. // OpenProcess gets an interface to an existing process within the container.
  122. OpenProcess(pid int) (Process, error)
  123. // Close cleans up any state associated with the container but does not terminate or wait for it.
  124. Close() error
  125. // Modify the System
  126. Modify(config *ResourceModificationRequestResponse) error
  127. }
  128. // Process represents a running or exited process.
  129. type Process interface {
  130. // Pid returns the process ID of the process within the container.
  131. Pid() int
  132. // Kill signals the process to terminate but does not wait for it to finish terminating.
  133. Kill() error
  134. // Wait waits for the process to exit.
  135. Wait() error
  136. // WaitTimeout waits for the process to exit or the duration to elapse. It returns
  137. // false if timeout occurs.
  138. WaitTimeout(time.Duration) error
  139. // ExitCode returns the exit code of the process. The process must have
  140. // already terminated.
  141. ExitCode() (int, error)
  142. // ResizeConsole resizes the console of the process.
  143. ResizeConsole(width, height uint16) error
  144. // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
  145. // these pipes does not close the underlying pipes; it should be possible to
  146. // call this multiple times to get multiple interfaces.
  147. Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error)
  148. // CloseStdin closes the write side of the stdin pipe so that the process is
  149. // notified on the read side that there is no more data in stdin.
  150. CloseStdin() error
  151. // Close cleans up any state associated with the process but does not kill
  152. // or wait on it.
  153. Close() error
  154. }