Keep same-named VMs from different drivers, reject ambiguous bare-name resolution, and add exact ResolveRef routing with driver-qualified keys. Declare DataRoot-relative VM roots in guest driver manifests, validate traversal and absolute paths, and scan declarations for unavailable drivers. Add data layout v3 for driver-qualified per-VM plugin settings, preserve explicit values during migration, and pass VMRef keys from the settings UI.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package driver
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// VMRef identifies a VM within its owning driver. Name alone is not globally
|
|
// unique: two drivers may expose VMs with the same name.
|
|
type VMRef struct {
|
|
DriverID string `json:"driver_id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func NewVMRef(driverID, name string) VMRef {
|
|
driverID = CanonicalDriverID(strings.TrimSpace(driverID))
|
|
if driverID == "" {
|
|
driverID = BuiltinReimsMacOSDriverID
|
|
}
|
|
return VMRef{DriverID: driverID, Name: strings.TrimSpace(name)}
|
|
}
|
|
|
|
// Key is the stable settings/map key for a VM reference. Windows VM names
|
|
// cannot contain ':', so the driver/name boundary is unambiguous.
|
|
func (r VMRef) Key() string {
|
|
r = NewVMRef(r.DriverID, r.Name)
|
|
return r.DriverID + ":" + r.Name
|
|
}
|
|
|
|
func ParseVMRef(key string) (VMRef, bool) {
|
|
driverID, name, ok := strings.Cut(strings.TrimSpace(key), ":")
|
|
if !ok || strings.TrimSpace(driverID) == "" || strings.TrimSpace(name) == "" {
|
|
return VMRef{}, false
|
|
}
|
|
return NewVMRef(driverID, name), true
|
|
}
|
|
|
|
func (v VMInfo) Ref() VMRef { return NewVMRef(v.DriverID, v.Name) }
|
|
|
|
func foldedRefKey(driverID, name string) string {
|
|
return strings.ToLower(NewVMRef(driverID, name).Key())
|
|
}
|
|
|
|
// AmbiguousVMError requires the caller to select a driver explicitly.
|
|
type AmbiguousVMError struct {
|
|
Name string
|
|
DriverIDs []string
|
|
}
|
|
|
|
func (e *AmbiguousVMError) Error() string {
|
|
return fmt.Sprintf("VM %q is ambiguous across drivers %s; specify a driver", e.Name, strings.Join(e.DriverIDs, ", "))
|
|
}
|