Documentation
¶
Overview ¶
Package vmsync keeps a manifest's VM hosts in step with the hypervisors that run them: `authama ssh vm sync`, the VM half of `authama doctor --fix` and the web UI's VM page.
For every VM host it asks the hypervisor what became of the VM, and plans:
- a running VM: pin its host key under the alias when nothing is pinned (replace a changed pin only when asked to), re-install the host's public key in the guest when the guest refuses it, and create or refresh the Docker context ssh://<alias>;
- a VM the hypervisor no longer has: remove the host entry (never its key files) and the Docker context authama made for it;
- a suspended or stopped VM: report it, and leave it alone - sync never starts, stops or deletes a VM.
It also adds the devboxes authama.json declares that are not hosts yet (adopting a declared loose key by copying it) and removes Docker contexts authama made whose host is gone from the manifest.
A plan is computed without writing anything, so a dry run shows exactly what a run does; a run applied twice changes nothing the second time. Nothing here ever reads a private key: the guest gets the .pub.
Index ¶
- Constants
- func AddVMHost(p paths.Paths, profile, alias, hv, vmName, user, keyName string) error
- func ReleaseReservation(P paths.Paths, src string) (bool, error)
- type Action
- type AdoptResult
- type Checker
- type ContextStatus
- type Deps
- type DockerOps
- type Host
- type Options
- type Plan
- type ProbeResult
- type Syncer
Constants ¶
const ( ProbeOK = "ok" // the guest accepted the key ProbeKeyRefused = "key-refused" // the guest answered and refused every key ProbeUnreachable = "unreachable" // anything else: timeout, host key, proxy )
Probe outcomes.
const ( ActPin = "pin" // pin the guest's host key under the alias ActRepin = "repin" // replace a changed pin (opt-in) ActInstallKey = "install-key" // append the host's .pub to the guest's authorized_keys ActDockerCreate = "docker-create" // docker context create <alias> ActDockerUpdate = "docker-update" // docker context update <alias> ActDockerRemove = "docker-remove" // docker context rm <alias> (backed up first) ActRemoveHost = "remove-host" // drop a gone VM's host entry (keys stay) ActAddDevbox = "add-devbox" // add a devbox authama.json declares ActAdoptKey = "adopt-key" // copy a declared loose key into the profile ActUpdateDevbox = "update-devbox" // bring a host in line with its declaration )
Action kinds.
Variables ¶
This section is empty.
Functions ¶
func AddVMHost ¶
AddVMHost adds a VM host to profile (created per_service when missing), using keyName when set. It does not re-render the config.
func ReleaseReservation ¶ added in v0.1.6
ReleaseReservation drops the reservation of a loose key that has just been adopted from src (a path directly in ~/.ssh): the key now has a host, so the note that it is kept for later no longer applies. Reports whether one was dropped.
Types ¶
type Action ¶
type Action struct {
Kind string
Profile string
Alias string
Detail string // the line a plan prints
// contains filtered or unexported fields
}
Action is one step a sync takes.
type AdoptResult ¶
AdoptResult is what AdoptKey did.
type Checker ¶ added in v0.1.6
Checker asks the engine behind a context; dockerctx.Check is the real one.
type ContextStatus ¶ added in v0.1.6
type ContextStatus struct {
Name string `json:"name"`
Endpoint string `json:"endpoint"`
// Managed: authama made it (its description), or it points exactly
// where an authama context for its name would.
Managed bool `json:"managed"`
Current bool `json:"current"`
// Host is profile/alias of the VM host by that name, "" when none.
Host string `json:"host,omitempty"`
// VMState is the hypervisor's word for the host's VM (running, stopped,
// gone, ...), "" when there is no host.
VMState string `json:"vm_state,omitempty"`
// Docker is the engine check; nil when it was not made (not asked for,
// or the VM is not running: a check never starts a VM).
Docker *dockerctx.Diagnosis `json:"docker,omitempty"`
// Problem says why the context needs attention, "" when it does not;
// Fix says what to do.
Problem string `json:"problem,omitempty"`
Fix string `json:"fix,omitempty"`
}
ContextStatus is one Docker context that belongs to a VM host: whether it still points where it should, the VM's state, and (when asked) whether the engine behind it answers. doctor and the web UI's VMs page show these.
func ContextStatuses ¶ added in v0.1.6
func ContextStatuses(plan Plan, contexts []dockerctx.Context, check Checker) []ContextStatus
ContextStatuses lists the Docker contexts that belong to VM hosts: every one authama manages, and any other named after a VM host. Other contexts (default, orbstack, desktop-linux, ...) are not authama's and are left out. With check, the engine behind each context of a running VM is asked; without it nothing connects to a guest.
type Deps ¶
type Deps struct {
Driver func(name string) (hypervisor.Driver, error)
Enabled func(name string) bool
Scan func(sshDir, host string, port int) ([]knownhosts.ScannedKey, error)
Probe func(sshDir, alias string, port int, scanned []knownhosts.ScannedKey) ProbeResult
Docker DockerOps
// pin is replaced or its entry removed, so no master keeps talking to the
// old guest. nil does nothing.
CloseShared func(sshDir, alias, user string, port int)
}
Deps are the outside world, swappable in tests.
type DockerOps ¶
type DockerOps interface {
List() ([]dockerctx.Context, error)
Apply(alias string) (string, error)
Remove(c dockerctx.Context, backupDir string) (string, error)
}
DockerOps is the docker CLI.
type Host ¶
type Host struct {
Profile string `json:"profile"`
Alias string `json:"alias"`
Hypervisor string `json:"hypervisor"`
VM string `json:"vm"`
// State: running | stopped | suspended | ... (the hypervisor's word) |
// gone | unknown | disabled | not-installed.
State string `json:"state"`
Note string `json:"note,omitempty"`
// Declared is set when authama.json's devboxes section declares the host.
Declared bool `json:"declared,omitempty"`
// Running is set when the hypervisor says the VM runs (State is its own
// word for it, which differs between hypervisors).
Running bool `json:"running,omitempty"`
// User is the guest user the host connects as.
User string `json:"user,omitempty"`
// Docker is what the probe found about the guest's Docker engine; nil
// when the guest was not probed (not running, or a plan without probes).
Docker *dockerctx.Diagnosis `json:"docker,omitempty"`
}
Host is one VM host as the hypervisor sees it now.
type Options ¶
type Options struct {
// Probe connects to running guests (ssh-keyscan and one BatchMode ssh)
// to check the host key and the key. Off, the plan is the hypervisor's
// view only - what doctor shows without --fix.
Probe bool
// Repin replaces a VM host's pin when the guest's host key changed.
Repin bool
// PruneGone removes the host of a VM the hypervisor no longer has.
PruneGone bool
// AutoPin pins an unpinned running VM host (ssh.auto_pin).
AutoPin bool
// Docker manages Docker contexts (off when the docker CLI is missing).
Docker bool
}
Options steer a sync.
func DefaultOptions ¶
DefaultOptions reads the settings: vm.prune_gone, vm.repin_changed, ssh.auto_pin, and whether docker is installed.
type Plan ¶
type Plan struct {
Hosts []Host `json:"hosts"`
Actions []Action `json:"-"`
Notes []string `json:"notes,omitempty"`
}
Plan is everything a sync would do, and why.
func (Plan) ManifestChanges ¶
ManifestChanges reports whether the plan edits the manifest.
type ProbeResult ¶
type ProbeResult struct {
Status string
Docker bool // the guest has a docker command
Detail string // why, when not ok
// Daemon is whether the guest user reaches the Docker engine: a docker
// command alone is not enough (the user may not be in the docker group,
// or the engine may be stopped). Empty State when the probe did not run.
Daemon dockerctx.Diagnosis
}
ProbeResult is what one BatchMode ssh to the guest found.
type Syncer ¶
Syncer plans and applies a sync.
func (*Syncer) ApplyManifest ¶
ApplyManifest makes the plan's manifest steps: removing gone hosts, adding and updating declared devboxes, adopting declared keys. The caller holds the lock, has snapshotted ~/.ssh and backed the manifest up, and re-renders the config afterwards.
func (*Syncer) ApplyOutside ¶
ApplyOutside makes the plan's steps outside the manifest: pins, key installs, Docker contexts. Each is independent; a failure is reported and the rest still run.
func (*Syncer) BackupDir ¶
BackupDir is where sync keeps what it backs up before removing: the manifest and inventory, and exported Docker contexts.
func (*Syncer) BackupManifest ¶
BackupManifest copies manifest.json and inventory.json into BackupDir and returns the manifest copy's path.