Make runtime defaults portable
Stop assuming one workstation layout for runtime artifacts, mapdns, and host tooling. The daemon and shell helpers now use portable mapdns configuration, and runtime bundles can carry bundle.json metadata for their default kernel, initrd, modules, rootfs, and helper paths. Load bundle metadata through config with a legacy layout fallback, thread mapdns_bin/mapdns_data_file through the Go and shell paths, and add command-scoped preflight checks for VM start, NAT, image build, work-disk resize, and SSH so missing tools or artifacts fail with actionable errors. Update the runtime-bundle manifest, docs, and tests to match the new model. Verified with go test ./..., make build, and bash -n customize.sh interactive.sh dns.sh make-rootfs.sh verify.sh.
This commit is contained in:
parent
238bb8a020
commit
fcedacba5c
23 changed files with 927 additions and 96 deletions
|
|
@ -125,7 +125,7 @@ func (d *Daemon) StartVM(ctx context.Context, idOrName string) (model.VMRecord,
|
|||
}
|
||||
|
||||
func (d *Daemon) startVMLocked(ctx context.Context, vm model.VMRecord, image model.Image) (model.VMRecord, error) {
|
||||
if err := d.requireStartPrereqs(ctx); err != nil {
|
||||
if err := d.validateStartPrereqs(ctx, vm, image); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
}
|
||||
if err := os.MkdirAll(vm.Runtime.VMDir, 0o755); err != nil {
|
||||
|
|
@ -389,6 +389,9 @@ func (d *Daemon) SetVM(ctx context.Context, params api.VMSetParams) (model.VMRec
|
|||
}
|
||||
if size > vm.Spec.WorkDiskSizeBytes {
|
||||
if exists(vm.Runtime.WorkDiskPath) {
|
||||
if err := d.validateWorkDiskResizePrereqs(); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
}
|
||||
if err := system.ResizeExt4Image(ctx, d.runner, vm.Runtime.WorkDiskPath, size); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
}
|
||||
|
|
@ -690,7 +693,12 @@ func clearRuntimeHandles(vm *model.VMRecord) {
|
|||
}
|
||||
|
||||
func (d *Daemon) setDNS(ctx context.Context, vmName, guestIP string) error {
|
||||
_, err := d.runner.Run(ctx, "mapdns", "set", "--data-file", "/home/thales/.local/share/mapdns/records.json", vmName+".vm", guestIP)
|
||||
if dataFile := strings.TrimSpace(d.config.MapDNSDataFile); dataFile != "" {
|
||||
if err := os.MkdirAll(filepath.Dir(dataFile), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err := d.runner.Run(ctx, d.mapdnsBinary(), d.mapdnsArgs("set", vmName+".vm", guestIP)...)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -698,7 +706,7 @@ func (d *Daemon) removeDNS(ctx context.Context, dnsName string) error {
|
|||
if dnsName == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := d.runner.Run(ctx, "mapdns", "rm", "--data-file", "/home/thales/.local/share/mapdns/records.json", dnsName)
|
||||
_, err := d.runner.Run(ctx, d.mapdnsBinary(), d.mapdnsArgs("rm", dnsName)...)
|
||||
if err != nil && strings.Contains(err.Error(), "not found") {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -710,28 +718,6 @@ func (d *Daemon) killVMProcess(ctx context.Context, pid int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Daemon) requireStartPrereqs(ctx context.Context) error {
|
||||
return system.RequireCommands(
|
||||
ctx,
|
||||
"sudo",
|
||||
"ip",
|
||||
"dmsetup",
|
||||
"losetup",
|
||||
"blockdev",
|
||||
"e2cp",
|
||||
"e2rm",
|
||||
"debugfs",
|
||||
"mkfs.ext4",
|
||||
"truncate",
|
||||
"pgrep",
|
||||
"mount",
|
||||
"umount",
|
||||
"cp",
|
||||
"ps",
|
||||
"mapdns",
|
||||
)
|
||||
}
|
||||
|
||||
func (d *Daemon) generateName(ctx context.Context) (string, error) {
|
||||
if exists(d.config.NamegenPath) {
|
||||
out, err := d.runner.Run(ctx, d.config.NamegenPath)
|
||||
|
|
@ -759,3 +745,19 @@ func defaultInt(value, fallback int) int {
|
|||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func (d *Daemon) mapdnsBinary() string {
|
||||
if value := strings.TrimSpace(d.config.MapDNSBin); value != "" {
|
||||
return value
|
||||
}
|
||||
return "mapdns"
|
||||
}
|
||||
|
||||
func (d *Daemon) mapdnsArgs(subcommand string, args ...string) []string {
|
||||
out := []string{subcommand}
|
||||
if value := strings.TrimSpace(d.config.MapDNSDataFile); value != "" {
|
||||
out = append(out, "--data-file", value)
|
||||
}
|
||||
out = append(out, args...)
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue