Documentation
¶
Overview ¶
Package fleet keeps a client per machine — this computer and every enabled machine in the catalog — for a program that shows them all at once: the phone gateway.
Three things make it different from simply dialling each one:
- Nobody waits on ssh. Reaching a machine takes seconds at best, and a minute when conch has to be installed there, so a machine is connected to in the background and its state says how far it got. Asking again shortly says more; Changed says when it does.
- A machine that cannot be reached does not take the others with it. It carries why, so nothing is silently missing.
- A pane ID is its server's own, so `p3` exists on every machine. Outside a machine a pane is `machine:pane` (ComposePaneID).
Index ¶
Constants ¶
const ( Online = "online" Connecting = "connecting" Offline = "offline" )
A machine's state.
const Local = "local"
Local is this computer's machine ID.
Variables ¶
This section is empty.
Functions ¶
func ComposePaneID ¶
ComposePaneID is a pane's ID outside its machine.
func FirstLine ¶
FirstLine keeps a message to one line: ssh's refusals run to several, and this is shown beside a machine's name.
func IDOK ¶
IDOK is the shape the catalog gives an ID (remote.slug): lower case letters, digits and dashes, and never a colon.
func SplitPaneID ¶
SplitPaneID reads one back. A bare pane ID means this computer, so a caller from before machines keeps working. The machine is checked here because it goes into a map lookup, not into a shell.
Types ¶
type Machine ¶
type Machine struct {
ID, Label string
State string
Detail string // why it is offline, one line
// contains filtered or unexported fields
}
Machine is a machine as it was when it was looked at: a snapshot, not the live connection, because reaching a machine happens in another goroutine and a pointer handed out here would be read while it is written. The client is safe to carry — it is not replaced once set, only closed, and a closed one reports its own error.
type Options ¶
type Options struct {
// Local is this computer's shared client, cheap to ask for: the pool
// asks at every look rather than keeping its own.
Local func() (*client.Client, error)
// DialLocal is a fresh connection of this computer's, for Dial.
DialLocal func() (*client.Client, error)
// LocalLabel is what this computer is called; "this computer".
LocalLabel string
// Connect reaches a machine of the catalog: over ssh, by default.
Connect func(context.Context, remote.Machine) (*client.Client, error)
// Catalog is the machines there are: remote.Machines, by default.
Catalog func() ([]remote.Machine, error)
// Retry is how long before a machine that would not answer is tried
// again (30 s); ConnectWait bounds one attempt (45 s).
Retry, ConnectWait func() time.Duration
Now func() time.Time
// Changed is told when a machine comes up. It is called with no lock
// held, so it may look at the pool.
Changed func()
// Logf gets one line for each machine that fails, and nothing else.
Logf func(format string, args ...any)
}
Options says how a pool reaches things. Everything but Local has a default; the functions are read at each use, so a test may change what they return while the pool runs.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the clients of every machine.
func (*Pool) Close ¶
func (p *Pool) Close()
Close drops every remote connection and waits for the attempts in flight, so a closed pool leaves no ssh behind. This computer's client is the caller's, and is left alone.
func (*Pool) Dial ¶
Dial is a connection of the caller's own to a machine, for following its events: the pool's client is shared, and its events are thrown away. A machine other than this computer must be up first, so this rides the connection already made rather than starting another from nothing.