mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
vmname.VM is the name of every machine devvm runs on a backend: a project VM, an image's machine (devvm-img-<key>), a build VM and a remake's aside. Fields, parameters, results and map keys that held a VM's name as a string now hold a VM, from the backend interface down to the CLI's --json structs, whose output is byte for byte the same. Boundary parsers, the only places a string becomes a VM: - vmname.Parse: a project VM's name (state's vm.json name, export file names, devvm _links's argument, the forwarder's -vm, project.Nth) - vmname.ParseListed: one path element, for what a backend lists - VM.UnmarshalText: JSON (Lima's list, proxy config and events, links' targets in state, link lists); empty stays no VM - vmname.Image(key), VM.Aside(), and typed constants for Lima's build VMs - msg.M.VM: the VM a message's function took, read back vmname's functions on names became methods (Hash, Slug, Short, Aside, AsideHash, ImageKey, IsProject); Lima's image prefix moved to vmname; vmname.Join joins VM lists. Messages' vm and vm_name fields are typed by the generator. Seven messages whose field took something else became what= (backend_lacks, backend_unreviewed, backend_unreviewed_used, starting, deleting, configuring, running_script) and rm_vm_failed's name=: the text is unchanged, the names-mode scripts follow. Review.RequireFor names an image or the tools being built. Typed sites per package (added lines with vmname.VM, non-test): msg 347 (generated), vm 124, lima 48, backendtest 32, vmssh 31, netpolicy 22, backend 16, gitprotect 14, proxy 11, cli 11, project 10, state 8, ports 6, paths 3, sshagent 2, sshconfig 2, tools 2. The structure test's owners rule now fails on a field, parameter or result named for a VM (vm, vms, otherVM, vmName) typed string, []string or map[string]…, and on converting anything but a literal to vmname.VM outside the files it lists; internal/stubtest is free. depguard holds internal/vmname to the standard library, and the proxy may import it. ParseListed and UnmarshalText refuse a name starting with -, which would read as a flag in limactl's argv, and vmname.Image refuses a key that's empty, holds a / or NUL, or makes a project VM's name, so Lima's ImageSize and DeleteImage no longer check it themselves. The check also fails on a *string VM name and an alias of vmname.VM, and says what it doesn't see. Co-Authored-By: Claude Opus 5.5 <[email protected]>
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package backend
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
|
|
"github.com/devvmhq/devvm/internal/vmname"
|
|
)
|
|
|
|
// LocationOf is where h's VMs live in this run (Host.Location), as a VM's
|
|
// state records it (a hash, so any path fits), and whether that's h's
|
|
// default; "" and true for a backend whose VMs can't move.
|
|
func LocationOf(h Host) (string, bool) {
|
|
where, isDefault := h.Location()
|
|
if where == "" {
|
|
return "", true
|
|
}
|
|
sum := sha256.Sum256([]byte(where))
|
|
return hex.EncodeToString(sum[:8]), isDefault
|
|
}
|
|
|
|
// Forgetter is a backend that keeps files or resources of its own for a
|
|
// VM besides the VM (an ssh key, say: Lima keeps none), which devvm gc
|
|
// --orphans deletes once the backend no longer has the VM, as Delete does
|
|
// after deleting it. It's the one role a backend may leave out, found
|
|
// with As.
|
|
type Forgetter interface {
|
|
// Forget deletes what the backend keeps for vm, which it must not
|
|
// have: a VM it has is refused, and nothing is deleted.
|
|
Forget(ctx context.Context, vm vmname.VM) error
|
|
}
|
|
|
|
// Stray is a VM with devvm's label that this devvm has no state for: one
|
|
// made by a devvm with another data folder (a sandbox's, a test's), or
|
|
// one whose state is gone (Housekeeping.Strays).
|
|
type Stray struct {
|
|
Name vmname.VM
|
|
Data string // the data folder its label names
|
|
}
|