Manage NAT directly from VM records
Fix the Go control plane NAT path now that runtime state lives in the daemon instead of the old repo-local vm.json files. Add a daemon-native NAT helper that derives uplink, guest IP, and TAP rules directly from VMRecord, applies the existing iptables/sysctl behavior idempotently, and removes the broken nat.sh handoff from vm.go. Cover uplink parsing and rule generation with unit tests. Validated with go test ./... and make build; a live verify.sh --nat run installed host rules but stopped on the same guest SSH-readiness issue seen in the plain smoke test on this host.
This commit is contained in:
parent
2539800f5c
commit
171009b30b
3 changed files with 278 additions and 18 deletions
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -686,23 +685,6 @@ func (d *Daemon) removeDNS(ctx context.Context, dnsName string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Daemon) ensureNAT(ctx context.Context, vm model.VMRecord, enable bool) error {
|
||||
if d.config.RepoRoot == "" {
|
||||
return errors.New("repo root not detected")
|
||||
}
|
||||
script := filepath.Join(d.config.RepoRoot, "nat.sh")
|
||||
action := "down"
|
||||
if enable {
|
||||
action = "up"
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "bash", script, action, vm.ID)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Dir = d.config.RepoRoot
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (d *Daemon) killVMProcess(ctx context.Context, pid int) error {
|
||||
_, err := d.runner.RunSudo(ctx, "kill", "-KILL", strconv.Itoa(pid))
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue