Documentation
¶
Overview ¶
Package host serves the proxy and the terminal of a running VM, however the VM was started and however its listeners came about, and says how the run ended.
Index ¶
- Constants
- Variables
- func ConsoleLog(w io.Writer) io.Writer
- func Result(vmErr error, ended Outcome, consoleLog string) error
- func ServeProxy(ctx context.Context, listener net.Listener, options proxy.Options, ...) func()
- func ServeTerminal(ctx context.Context, listener net.Listener, s Session) func() Outcome
- type Outcome
- type Session
- type Watched
Constants ¶
const ( DefaultBootTimeout = time.Minute DefaultPowerOffWait = 10 * time.Second )
DefaultBootTimeout is how long the guest of a VM the backend owns may take to connect, and DefaultPowerOffWait how long such a VM may take to power off after its session, before the backend stops it, unless the backend says otherwise.
const DefaultSessionEndDelay = 3 * time.Second
DefaultSessionEndDelay is how long the session may go on after the VM stopped, to show its last output, unless a backend says otherwise.
const MaxConsoleLogBytes = 16 << 20
MaxConsoleLogBytes is how much of the console of a VM goes into its log.
Variables ¶
var ErrNoTerminal = errors.New("the VM ended before its terminal came up")
ErrNoTerminal is a VM that ended before the command in it connected, which the console log usually explains.
Functions ¶
func ConsoleLog ¶ added in v1.2.0
ConsoleLog passes the first MaxConsoleLogBytes on to w and drops the rest, so that the VM cannot fill the disk of the host through its console. It never fails, so that the console is read to its end.
func Result ¶
Result is how the run ended: the error of the VM itself, a VM that never connected, with the console log that likely says why, the error of the session, or the exit code of the command in the VM.
func ServeProxy ¶
func ServeProxy(ctx context.Context, listener net.Listener, options proxy.Options, stderr io.Writer) func()
ServeProxy serves the proxy to the VM on the listener until the returned function is called, which also waits for the proxy to stop. A proxy that breaks is reported on stderr. A closed listener is not: it means the end of the VM went away, as when the VM stops before the proxy does.
func ServeTerminal ¶
ServeTerminal runs the session of the VM on the terminal of the person until the returned function is called. That function lets the session end, waits for the terminal to be restored and reports how it went.
Types ¶
type Outcome ¶
type Outcome struct {
// contains filtered or unexported fields
}
Outcome is how the terminal session went: whether the VM connected, the exit code of the command in it, and why the session broke off.
type Session ¶
type Session struct {
Stdin *os.File
Stdout io.Writer
Errors io.Writer
Env []string
EndDelay time.Duration
// OnPaste is called each time the person presses Ctrl+V, or is nil.
OnPaste func()
}
Session is the terminal of the person on Stdin and Stdout, and the variables for the command in the VM, as NAME=value. EndDelay is how long the session may go on after the VM stopped, to show its last output. With Errors the session has no terminal: the command gets no input, what it prints goes to Stdout and its standard error to Errors.
type Watched ¶ added in v1.6.0
type Watched struct {
net.Listener
Connected chan struct{}
Ended chan struct{}
Again chan struct{}
// contains filtered or unexported fields
}
Watched is the terminal listener of a VM the backend owns, which reports when the guest connected, when its session ended and when it connected again, so that the backend stops a VM that never connects, stays up after its session or started over. The guest is not trusted, so every connection after the first is closed. Watch makes one, and each channel closes as what it stands for happens.