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 ¶
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 ¶
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 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
}
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"`
}
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
}
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.