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