2016-05-23 16:12:06 -07:00
package hcsshim
import (
2017-06-01 16:49:56 -07:00
"encoding/json"
2016-05-23 16:12:06 -07:00
"io"
"time"
)
2018-08-20 09:38:40 -07:00
// RegistryKey is used to specify registry key name
type RegistryKey struct {
Hive string
Name string
Volatile bool ` json:",omitempty" `
}
// RegistryKey is used to specify registry key name
type RegistryValue struct {
Key RegistryKey
Name string
Type string
StringValue string ` json:",omitempty" `
BinaryValue [ ] byte ` json:",omitempty" `
DWordValue * uint32 ` json:",omitempty" `
QWordValue * uint64 ` json:",omitempty" `
CustomType * uint32 ` json:",omitempty" `
}
type RegistryChanges struct {
AddValues [ ] RegistryValue ` json:",omitempty" `
DeleteKeys [ ] RegistryValue ` json:",omitempty" `
}
2016-05-23 16:12:06 -07:00
// ProcessConfig is used as both the input of Container.CreateProcess
// and to convert the parameters to JSON for passing onto the HCS
type ProcessConfig struct {
2017-06-01 16:49:56 -07:00
ApplicationName string ` json:",omitempty" `
CommandLine string ` json:",omitempty" `
2017-06-22 14:14:38 -07:00
CommandArgs [ ] string ` json:",omitempty" ` // Used by Linux Containers on Windows
2017-06-01 16:49:56 -07:00
User string ` json:",omitempty" `
WorkingDirectory string ` json:",omitempty" `
Environment map [ string ] string ` json:",omitempty" `
EmulateConsole bool ` json:",omitempty" `
CreateStdInPipe bool ` json:",omitempty" `
CreateStdOutPipe bool ` json:",omitempty" `
CreateStdErrPipe bool ` json:",omitempty" `
ConsoleSize [ 2 ] uint ` json:",omitempty" `
CreateInUtilityVm bool ` json:",omitempty" ` // Used by Linux Containers on Windows
OCISpecification * json . RawMessage ` json:",omitempty" ` // Used by Linux Containers on Windows
2016-05-23 16:12:06 -07:00
}
type Layer struct {
ID string
Path string
}
type MappedDir struct {
2017-09-07 12:08:40 -07:00
HostPath string
ContainerPath string
ReadOnly bool
BandwidthMaximum uint64
IOPSMaximum uint64
CreateInUtilityVM bool
2018-07-23 09:11:13 -07:00
// LinuxMetadata - Support added in 1803/RS4+.
LinuxMetadata bool ` json:",omitempty" `
2016-05-23 16:12:06 -07:00
}
2017-07-26 15:03:47 -07:00
type MappedPipe struct {
HostPath string
ContainerPipeName string
}
2016-05-23 16:12:06 -07:00
type HvRuntime struct {
2017-07-26 15:03:47 -07:00
ImagePath string ` json:",omitempty" `
SkipTemplate bool ` json:",omitempty" `
LinuxInitrdFile string ` json:",omitempty" ` // File under ImagePath on host containing an initrd image for starting a Linux utility VM
LinuxKernelFile string ` json:",omitempty" ` // File under ImagePath on host containing a kernel for starting a Linux utility VM
LinuxBootParameters string ` json:",omitempty" ` // Additional boot parameters for starting a Linux Utility VM in initrd mode
2017-08-03 16:29:25 -07:00
BootSource string ` json:",omitempty" ` // "Vhd" for Linux Utility VM booting from VHD
WritableBootSource bool ` json:",omitempty" ` // Linux Utility VM booting from VHD
2017-06-01 16:49:56 -07:00
}
type MappedVirtualDisk struct {
HostPath string ` json:",omitempty" ` // Path to VHD on the host
ContainerPath string // Platform-specific mount point path in the container
CreateInUtilityVM bool ` json:",omitempty" `
ReadOnly bool ` json:",omitempty" `
Cache string ` json:",omitempty" ` // "" (Unspecified); "Disabled"; "Enabled"; "Private"; "PrivateAllowSharing"
2017-07-26 15:03:47 -07:00
AttachOnly bool ` json:",omitempty: `
2016-05-23 16:12:06 -07:00
}
2018-07-23 09:11:13 -07:00
// AssignedDevice represents a device that has been directly assigned to a container
//
// NOTE: Support added in RS5
type AssignedDevice struct {
// InterfaceClassGUID of the device to assign to container.
InterfaceClassGUID string ` json:"InterfaceClassGuid,omitempty" `
}
2016-05-23 16:12:06 -07:00
// ContainerConfig is used as both the input of CreateContainer
// and to convert the parameters to JSON for passing onto the HCS
type ContainerConfig struct {
2017-06-01 16:49:56 -07:00
SystemType string // HCS requires this to be hard-coded to "Container"
Name string // Name of the container. We use the docker ID.
Owner string ` json:",omitempty" ` // The management platform that created this container
VolumePath string ` json:",omitempty" ` // Windows volume path for scratch space. Used by Windows Server Containers only. Format \\?\\Volume{GUID}
IgnoreFlushesDuringBoot bool ` json:",omitempty" ` // Optimization hint for container startup in Windows
LayerFolderPath string ` json:",omitempty" ` // Where the layer folders are located. Used by Windows Server Containers only. Format %root%\windowsfilter\containerID
Layers [ ] Layer // List of storage layers. Required for Windows Server and Hyper-V Containers. Format ID=GUID;Path=%root%\windowsfilter\layerID
Credentials string ` json:",omitempty" ` // Credentials information
ProcessorCount uint32 ` json:",omitempty" ` // Number of processors to assign to the container.
2017-07-26 15:03:47 -07:00
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.
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.
2017-06-01 16:49:56 -07:00
StorageIOPSMaximum uint64 ` json:",omitempty" ` // Maximum Storage IOPS
StorageBandwidthMaximum uint64 ` json:",omitempty" ` // Maximum Storage Bandwidth in bytes per second
StorageSandboxSize uint64 ` json:",omitempty" ` // Size in bytes that the container system drive should be expanded to if smaller
MemoryMaximumInMB int64 ` json:",omitempty" ` // Maximum memory available to the container in Megabytes
HostName string ` json:",omitempty" ` // Hostname
MappedDirectories [ ] MappedDir ` json:",omitempty" ` // List of mapped directories (volumes/mounts)
2017-07-26 15:03:47 -07:00
MappedPipes [ ] MappedPipe ` json:",omitempty" ` // List of mapped Windows named pipes
2017-06-01 16:49:56 -07:00
HvPartition bool // True if it a Hyper-V Container
NetworkSharedContainerName string ` json:",omitempty" ` // Name (ID) of the container that we will share the network stack with.
EndpointList [ ] string ` json:",omitempty" ` // List of networking endpoints to be attached to container
HvRuntime * HvRuntime ` json:",omitempty" ` // Hyper-V container settings. Used by Hyper-V containers only. Format ImagePath=%root%\BaseLayerID\UtilityVM
Servicing bool ` json:",omitempty" ` // True if this container is for servicing
AllowUnqualifiedDNSQuery bool ` json:",omitempty" ` // True to allow unqualified DNS name resolution
DNSSearchList string ` json:",omitempty" ` // Comma seperated list of DNS suffixes to use for name resolution
ContainerType string ` json:",omitempty" ` // "Linux" for Linux containers on Windows. Omitted otherwise.
TerminateOnLastHandleClosed bool ` json:",omitempty" ` // Should HCS terminate the container once all handles have been closed
MappedVirtualDisks [ ] MappedVirtualDisk ` json:",omitempty" ` // Array of virtual disks to mount at start
2018-07-23 09:11:13 -07:00
AssignedDevices [ ] AssignedDevice ` json:",omitempty" ` // Array of devices to assign. NOTE: Support added in RS5
2018-08-20 09:38:40 -07:00
RegistryChanges * RegistryChanges ` json:",omitempty" ` // Registry changes to be applied to the container
2016-05-23 16:12:06 -07:00
}
2016-11-08 11:36:07 -08:00
type ComputeSystemQuery struct {
IDs [ ] string ` json:"Ids,omitempty" `
Types [ ] string ` json:",omitempty" `
Names [ ] string ` json:",omitempty" `
Owners [ ] string ` json:",omitempty" `
}
2016-05-23 16:12:06 -07:00
// Container represents a created (but not necessarily running) container.
type Container interface {
// Start synchronously starts the container.
Start ( ) error
// Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
Shutdown ( ) error
// Terminate requests a container terminate, but it may not actually be terminated until Wait() succeeds.
Terminate ( ) error
// Waits synchronously waits for the container to shutdown or terminate.
Wait ( ) error
// WaitTimeout synchronously waits for the container to terminate or the duration to elapse. It
// returns false if timeout occurs.
WaitTimeout ( time . Duration ) error
// Pause pauses the execution of a container.
Pause ( ) error
// Resume resumes the execution of a container.
Resume ( ) error
// HasPendingUpdates returns true if the container has updates pending to install.
HasPendingUpdates ( ) ( bool , error )
2016-08-03 17:47:43 -07:00
// Statistics returns statistics for a container.
Statistics ( ) ( Statistics , error )
2016-08-18 12:53:01 -07:00
// ProcessList returns details for the processes in a container.
ProcessList ( ) ( [ ] ProcessListItem , error )
2017-07-26 15:03:47 -07:00
// MappedVirtualDisks returns virtual disks mapped to a utility VM, indexed by controller
MappedVirtualDisks ( ) ( map [ int ] MappedVirtualDiskController , error )
2016-05-23 16:12:06 -07:00
// CreateProcess launches a new process within the container.
CreateProcess ( c * ProcessConfig ) ( Process , error )
// OpenProcess gets an interface to an existing process within the container.
OpenProcess ( pid int ) ( Process , error )
// Close cleans up any state associated with the container but does not terminate or wait for it.
Close ( ) error
2017-05-08 10:30:41 -07:00
// Modify the System
Modify ( config * ResourceModificationRequestResponse ) error
2016-05-23 16:12:06 -07:00
}
// Process represents a running or exited process.
type Process interface {
// Pid returns the process ID of the process within the container.
Pid ( ) int
// Kill signals the process to terminate but does not wait for it to finish terminating.
Kill ( ) error
// Wait waits for the process to exit.
Wait ( ) error
// WaitTimeout waits for the process to exit or the duration to elapse. It returns
// false if timeout occurs.
WaitTimeout ( time . Duration ) error
// ExitCode returns the exit code of the process. The process must have
// already terminated.
ExitCode ( ) ( int , error )
// ResizeConsole resizes the console of the process.
ResizeConsole ( width , height uint16 ) error
// Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
// these pipes does not close the underlying pipes; it should be possible to
// call this multiple times to get multiple interfaces.
Stdio ( ) ( io . WriteCloser , io . ReadCloser , io . ReadCloser , error )
// CloseStdin closes the write side of the stdin pipe so that the process is
// notified on the read side that there is no more data in stdin.
CloseStdin ( ) error
// Close cleans up any state associated with the process but does not kill
// or wait on it.
Close ( ) error
}