fleet

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	Online     = "online"
	Connecting = "connecting"
	Offline    = "offline"
)

A machine's state.

View Source
const Local = "local"

Local is this computer's machine ID.

Variables

This section is empty.

Functions

func ComposePaneID

func ComposePaneID(machine, pane string) string

ComposePaneID is a pane's ID outside its machine.

func FirstLine

func FirstLine(s string) string

FirstLine keeps a message to one line: ssh's refusals run to several, and this is shown beside a machine's name.

func IDOK

func IDOK(id string) bool

IDOK is the shape the catalog gives an ID (remote.slug): lower case letters, digits and dashes, and never a colon.

func MachineOf

func MachineOf(ref string) string

MachineOf is the machine a `machine:pane` names; a bare pane is this computer's.

func SplitPaneID

func SplitPaneID(ref string) (machine, pane string, err error)

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.

func (Machine) Client

func (m Machine) Client() *client.Client

Client is the connection while it is good, else nil.

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 New

func New(o Options) *Pool

New makes a pool. Close it when done.

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

func (p *Pool) Dial(id string) (*client.Client, error)

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.

func (*Pool) Machine

func (p *Pool) Machine(id string) (Machine, bool)

Machine is one machine of Machines, and whether there is one.

func (*Pool) Machines

func (p *Pool) Machines() []Machine

Machines returns every machine, this computer first and the rest by label, starting to reach any that is not up. A machine gone from the catalog takes its connection with it.

func (*Pool) Note

func (p *Pool) Note(id string, err error)

Note records why a machine could not be used, and drops a connection that has gone so the next look reaches for it again.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL