labctl/internal/render/qemu.go
GnomeZworc e9a0c19b72
All checks were successful
Tests / test (push) Successful in 3m46s
labctl: segments sur des bridges de l'hôte, routeurs et passerelle VRRP #2
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-10-13 09:57:09 +02:00

49 lines
1.5 KiB
Go

package render
import (
"fmt"
"path/filepath"
"strconv"
"git.g3e.fr/syonad/labctl/internal/topology"
)
const loopback = "127.0.0.1"
func qemuArgs(p *topology.Plan, n topology.NodePlan, index int, dir string) []string {
args := []string{
"-name", n.Name,
"-machine", "q35",
"-accel", "kvm",
"-cpu", "host",
"-smp", strconv.Itoa(n.CPUs),
"-m", strconv.Itoa(n.Memory),
"-nodefaults",
"-display", "none",
"-serial", "file:" + filepath.Join(dir, ConsoleFile),
"-qmp", "unix:" + filepath.Join(dir, QMPFile) + ",server=on,wait=off",
"-pidfile", filepath.Join(dir, PIDFile),
"-drive", "file=" + filepath.Join(dir, DiskFile) + ",if=virtio,format=qcow2",
"-drive", "file=" + filepath.Join(dir, SeedFile) + ",media=cdrom,readonly=on",
}
if len(n.Files) > 0 {
args = append(args, "-drive", "file="+filepath.Join(dir, FilesISO)+",media=cdrom,readonly=on")
}
restrict := "on"
if n.Role == topology.RoleRouter {
restrict = "off"
}
args = append(args,
"-netdev", fmt.Sprintf("user,id=%s,restrict=%s,ipv6=off,hostfwd=tcp:%s:%d-:22", AdminInterface, restrict, loopback, n.SSHPort),
"-device", fmt.Sprintf("virtio-net-pci,netdev=%s,mac=%s,romfile=", AdminInterface, adminMAC(index)),
)
for _, port := range nodePorts(p, n.Name) {
args = append(args,
"-netdev", fmt.Sprintf("tap,id=%s,ifname=%s,script=no,downscript=no", port.Interface, port.Tap),
"-device", fmt.Sprintf("virtio-net-pci,netdev=%s,mac=%s,host_mtu=%d,romfile=", port.Interface, port.MAC, port.MTU),
)
}
return args
}