labctl/internal/render/qemu.go
GnomeZworc ef7392f09b
Some checks failed
Tests / test (push) Successful in 4m12s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (lab-host.sh, scripts/lab-host.sh) (push) Successful in 7s
Release Pipeline / build (push) Successful in 1m31s
Release Pipeline / build (amd64, linux) (push) Successful in 0s
Release Pipeline / build (arm64, darwin) (push) Successful in 0s
Release Pipeline / checksums (push) Successful in 6s
Release Pipeline / release (push) Failing after 22s
Release Pipeline / publish (push) Failing after 0s
labctl: dépôt autonome — module git.g3e.fr/syonad/labctl, exemple evpn-2hv, LABCTL_BIN, licence, README, CI
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-10-12 16:33:02 +02:00

57 lines
1.9 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.RoleSwitch {
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 _, c := range nodeCables(p, n.Name) {
args = append(args, cable(c.NodeInterface, c.NodePort, c.SwitchPort, c.NodeMAC.String(), c.MTU)...)
}
for _, c := range switchCables(p, n.Name) {
args = append(args, cable(c.SwitchInterface, c.SwitchPort, c.NodePort, c.SwitchMAC.String(), c.MTU)...)
}
return args
}
func cable(id string, local, remote int, mac string, mtu int) []string {
return []string{
"-netdev", fmt.Sprintf("dgram,id=%s,local.type=inet,local.host=%s,local.port=%d,remote.type=inet,remote.host=%s,remote.port=%d",
id, loopback, local, loopback, remote),
"-device", fmt.Sprintf("virtio-net-pci,netdev=%s,mac=%s,host_mtu=%d,romfile=", id, mac, mtu),
}
}