schema1.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //go:build windows
  2. package schema1
  3. import (
  4. "encoding/json"
  5. "time"
  6. "github.com/Microsoft/go-winio/pkg/guid"
  7. hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
  8. )
  9. // ProcessConfig is used as both the input of Container.CreateProcess
  10. // and to convert the parameters to JSON for passing onto the HCS
  11. type ProcessConfig struct {
  12. ApplicationName string `json:",omitempty"`
  13. CommandLine string `json:",omitempty"`
  14. CommandArgs []string `json:",omitempty"` // Used by Linux Containers on Windows
  15. User string `json:",omitempty"`
  16. WorkingDirectory string `json:",omitempty"`
  17. Environment map[string]string `json:",omitempty"`
  18. EmulateConsole bool `json:",omitempty"`
  19. CreateStdInPipe bool `json:",omitempty"`
  20. CreateStdOutPipe bool `json:",omitempty"`
  21. CreateStdErrPipe bool `json:",omitempty"`
  22. ConsoleSize [2]uint `json:",omitempty"`
  23. CreateInUtilityVm bool `json:",omitempty"` // Used by Linux Containers on Windows
  24. OCISpecification *json.RawMessage `json:",omitempty"` // Used by Linux Containers on Windows
  25. }
  26. type Layer struct {
  27. ID string
  28. Path string
  29. }
  30. type MappedDir struct {
  31. HostPath string
  32. ContainerPath string
  33. ReadOnly bool
  34. BandwidthMaximum uint64
  35. IOPSMaximum uint64
  36. CreateInUtilityVM bool
  37. // LinuxMetadata - Support added in 1803/RS4+.
  38. LinuxMetadata bool `json:",omitempty"`
  39. }
  40. type MappedPipe struct {
  41. HostPath string
  42. ContainerPipeName string
  43. }
  44. type HvRuntime struct {
  45. ImagePath string `json:",omitempty"`
  46. SkipTemplate bool `json:",omitempty"`
  47. LinuxInitrdFile string `json:",omitempty"` // File under ImagePath on host containing an initrd image for starting a Linux utility VM
  48. LinuxKernelFile string `json:",omitempty"` // File under ImagePath on host containing a kernel for starting a Linux utility VM
  49. LinuxBootParameters string `json:",omitempty"` // Additional boot parameters for starting a Linux Utility VM in initrd mode
  50. BootSource string `json:",omitempty"` // "Vhd" for Linux Utility VM booting from VHD
  51. WritableBootSource bool `json:",omitempty"` // Linux Utility VM booting from VHD
  52. }
  53. type MappedVirtualDisk struct {
  54. HostPath string `json:",omitempty"` // Path to VHD on the host
  55. ContainerPath string // Platform-specific mount point path in the container
  56. CreateInUtilityVM bool `json:",omitempty"`
  57. ReadOnly bool `json:",omitempty"`
  58. Cache string `json:",omitempty"` // "" (Unspecified); "Disabled"; "Enabled"; "Private"; "PrivateAllowSharing"
  59. AttachOnly bool `json:",omitempty"`
  60. }
  61. // AssignedDevice represents a device that has been directly assigned to a container
  62. //
  63. // NOTE: Support added in RS5
  64. type AssignedDevice struct {
  65. // InterfaceClassGUID of the device to assign to container.
  66. InterfaceClassGUID string `json:"InterfaceClassGuid,omitempty"`
  67. }
  68. // ContainerConfig is used as both the input of CreateContainer
  69. // and to convert the parameters to JSON for passing onto the HCS
  70. type ContainerConfig struct {
  71. SystemType string // HCS requires this to be hard-coded to "Container"
  72. Name string // Name of the container. We use the docker ID.
  73. Owner string `json:",omitempty"` // The management platform that created this container
  74. VolumePath string `json:",omitempty"` // Windows volume path for scratch space. Used by Windows Server Containers only. Format \\?\\Volume{GUID}
  75. IgnoreFlushesDuringBoot bool `json:",omitempty"` // Optimization hint for container startup in Windows
  76. LayerFolderPath string `json:",omitempty"` // Where the layer folders are located. Used by Windows Server Containers only. Format %root%\windowsfilter\containerID
  77. Layers []Layer // List of storage layers. Required for Windows Server and Hyper-V Containers. Format ID=GUID;Path=%root%\windowsfilter\layerID
  78. Credentials string `json:",omitempty"` // Credentials information
  79. ProcessorCount uint32 `json:",omitempty"` // Number of processors to assign to the container.
  80. 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.
  81. 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.
  82. StorageIOPSMaximum uint64 `json:",omitempty"` // Maximum Storage IOPS
  83. StorageBandwidthMaximum uint64 `json:",omitempty"` // Maximum Storage Bandwidth in bytes per second
  84. StorageSandboxSize uint64 `json:",omitempty"` // Size in bytes that the container system drive should be expanded to if smaller
  85. MemoryMaximumInMB int64 `json:",omitempty"` // Maximum memory available to the container in Megabytes
  86. HostName string `json:",omitempty"` // Hostname
  87. MappedDirectories []MappedDir `json:",omitempty"` // List of mapped directories (volumes/mounts)
  88. MappedPipes []MappedPipe `json:",omitempty"` // List of mapped Windows named pipes
  89. HvPartition bool // True if it a Hyper-V Container
  90. NetworkSharedContainerName string `json:",omitempty"` // Name (ID) of the container that we will share the network stack with.
  91. EndpointList []string `json:",omitempty"` // List of networking endpoints to be attached to container
  92. HvRuntime *HvRuntime `json:",omitempty"` // Hyper-V container settings. Used by Hyper-V containers only. Format ImagePath=%root%\BaseLayerID\UtilityVM
  93. Servicing bool `json:",omitempty"` // True if this container is for servicing
  94. AllowUnqualifiedDNSQuery bool `json:",omitempty"` // True to allow unqualified DNS name resolution
  95. DNSSearchList string `json:",omitempty"` // Comma separated list of DNS suffixes to use for name resolution
  96. ContainerType string `json:",omitempty"` // "Linux" for Linux containers on Windows. Omitted otherwise.
  97. TerminateOnLastHandleClosed bool `json:",omitempty"` // Should HCS terminate the container once all handles have been closed
  98. MappedVirtualDisks []MappedVirtualDisk `json:",omitempty"` // Array of virtual disks to mount at start
  99. AssignedDevices []AssignedDevice `json:",omitempty"` // Array of devices to assign. NOTE: Support added in RS5
  100. }
  101. type ComputeSystemQuery struct {
  102. IDs []string `json:"Ids,omitempty"`
  103. Types []string `json:",omitempty"`
  104. Names []string `json:",omitempty"`
  105. Owners []string `json:",omitempty"`
  106. }
  107. type PropertyType string
  108. const (
  109. PropertyTypeStatistics PropertyType = "Statistics" // V1 and V2
  110. PropertyTypeProcessList PropertyType = "ProcessList" // V1 and V2
  111. PropertyTypeMappedVirtualDisk PropertyType = "MappedVirtualDisk" // Not supported in V2 schema call
  112. PropertyTypeGuestConnection PropertyType = "GuestConnection" // V1 and V2. Nil return from HCS before RS5
  113. )
  114. type PropertyQuery struct {
  115. PropertyTypes []PropertyType `json:",omitempty"`
  116. }
  117. // ContainerProperties holds the properties for a container and the processes running in that container
  118. type ContainerProperties struct {
  119. ID string `json:"Id"`
  120. State string
  121. Name string
  122. SystemType string
  123. RuntimeOSType string `json:"RuntimeOsType,omitempty"`
  124. Owner string
  125. SiloGUID string `json:"SiloGuid,omitempty"`
  126. RuntimeID guid.GUID `json:"RuntimeId,omitempty"`
  127. IsRuntimeTemplate bool `json:",omitempty"`
  128. RuntimeImagePath string `json:",omitempty"`
  129. Stopped bool `json:",omitempty"`
  130. ExitType string `json:",omitempty"`
  131. AreUpdatesPending bool `json:",omitempty"`
  132. ObRoot string `json:",omitempty"`
  133. Statistics Statistics `json:",omitempty"`
  134. ProcessList []ProcessListItem `json:",omitempty"`
  135. MappedVirtualDiskControllers map[int]MappedVirtualDiskController `json:",omitempty"`
  136. GuestConnectionInfo GuestConnectionInfo `json:",omitempty"`
  137. }
  138. // MemoryStats holds the memory statistics for a container
  139. type MemoryStats struct {
  140. UsageCommitBytes uint64 `json:"MemoryUsageCommitBytes,omitempty"`
  141. UsageCommitPeakBytes uint64 `json:"MemoryUsageCommitPeakBytes,omitempty"`
  142. UsagePrivateWorkingSetBytes uint64 `json:"MemoryUsagePrivateWorkingSetBytes,omitempty"`
  143. }
  144. // ProcessorStats holds the processor statistics for a container
  145. type ProcessorStats struct {
  146. TotalRuntime100ns uint64 `json:",omitempty"`
  147. RuntimeUser100ns uint64 `json:",omitempty"`
  148. RuntimeKernel100ns uint64 `json:",omitempty"`
  149. }
  150. // StorageStats holds the storage statistics for a container
  151. type StorageStats struct {
  152. ReadCountNormalized uint64 `json:",omitempty"`
  153. ReadSizeBytes uint64 `json:",omitempty"`
  154. WriteCountNormalized uint64 `json:",omitempty"`
  155. WriteSizeBytes uint64 `json:",omitempty"`
  156. }
  157. // NetworkStats holds the network statistics for a container
  158. type NetworkStats struct {
  159. BytesReceived uint64 `json:",omitempty"`
  160. BytesSent uint64 `json:",omitempty"`
  161. PacketsReceived uint64 `json:",omitempty"`
  162. PacketsSent uint64 `json:",omitempty"`
  163. DroppedPacketsIncoming uint64 `json:",omitempty"`
  164. DroppedPacketsOutgoing uint64 `json:",omitempty"`
  165. EndpointId string `json:",omitempty"`
  166. InstanceId string `json:",omitempty"`
  167. }
  168. // Statistics is the structure returned by a statistics call on a container
  169. type Statistics struct {
  170. Timestamp time.Time `json:",omitempty"`
  171. ContainerStartTime time.Time `json:",omitempty"`
  172. Uptime100ns uint64 `json:",omitempty"`
  173. Memory MemoryStats `json:",omitempty"`
  174. Processor ProcessorStats `json:",omitempty"`
  175. Storage StorageStats `json:",omitempty"`
  176. Network []NetworkStats `json:",omitempty"`
  177. }
  178. // ProcessList is the structure of an item returned by a ProcessList call on a container
  179. type ProcessListItem struct {
  180. CreateTimestamp time.Time `json:",omitempty"`
  181. ImageName string `json:",omitempty"`
  182. KernelTime100ns uint64 `json:",omitempty"`
  183. MemoryCommitBytes uint64 `json:",omitempty"`
  184. MemoryWorkingSetPrivateBytes uint64 `json:",omitempty"`
  185. MemoryWorkingSetSharedBytes uint64 `json:",omitempty"`
  186. ProcessId uint32 `json:",omitempty"`
  187. UserTime100ns uint64 `json:",omitempty"`
  188. }
  189. // MappedVirtualDiskController is the structure of an item returned by a MappedVirtualDiskList call on a container
  190. type MappedVirtualDiskController struct {
  191. MappedVirtualDisks map[int]MappedVirtualDisk `json:",omitempty"`
  192. }
  193. // GuestDefinedCapabilities is part of the GuestConnectionInfo returned by a GuestConnection call on a utility VM
  194. type GuestDefinedCapabilities struct {
  195. NamespaceAddRequestSupported bool `json:",omitempty"`
  196. SignalProcessSupported bool `json:",omitempty"`
  197. DumpStacksSupported bool `json:",omitempty"`
  198. DeleteContainerStateSupported bool `json:",omitempty"`
  199. UpdateContainerSupported bool `json:",omitempty"`
  200. }
  201. // GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM
  202. type GuestConnectionInfo struct {
  203. SupportedSchemaVersions []hcsschema.Version `json:",omitempty"`
  204. ProtocolVersion uint32 `json:",omitempty"`
  205. GuestDefinedCapabilities GuestDefinedCapabilities `json:",omitempty"`
  206. }
  207. // Type of Request Support in ModifySystem
  208. type RequestType string
  209. // Type of Resource Support in ModifySystem
  210. type ResourceType string
  211. // RequestType const
  212. const (
  213. Add RequestType = "Add"
  214. Remove RequestType = "Remove"
  215. Network ResourceType = "Network"
  216. )
  217. // ResourceModificationRequestResponse is the structure used to send request to the container to modify the system
  218. // Supported resource types are Network and Request Types are Add/Remove
  219. type ResourceModificationRequestResponse struct {
  220. Resource ResourceType `json:"ResourceType"`
  221. Data interface{} `json:"Settings"`
  222. Request RequestType `json:"RequestType,omitempty"`
  223. }