f-33: vm: start vms with multiple nic
All checks were successful
Release Pipeline / checksums (push) Successful in 4s
Release Pipeline / release (push) Successful in 11s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (agent.service, systemd/agent.service) (push) Successful in 4s
Release Pipeline / upload-assets (dnsmasq@.service, systemd/dnsmasq@.service) (push) Successful in 4s
Release Pipeline / upload-assets (metadata@.service, systemd/metadata@.service) (push) Successful in 4s
Release Pipeline / upload-assets (run-dnsmasq-in-netns.sh, scripts/run-dnsmasq-in-netns.sh) (push) Successful in 4s
Release Pipeline / build (agent, amd64, linux) (push) Successful in 0s
Release Pipeline / build (metadata, amd64, linux) (push) Successful in 0s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 1m36s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-08-25 23:12:55 +02:00
commit 26d5805747
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
8 changed files with 309 additions and 25 deletions

View file

@ -11,6 +11,12 @@ import (
"strings"
)
const (
firstNICSlot = 0x03
lastNICSlot = 0x1d
maxNICs = lastNICSlot - firstNICSlot + 1
)
func Start(cfg Config) error {
memory := cfg.Memory
if memory == 0 {
@ -97,11 +103,24 @@ func Start(cfg Config) error {
}
}
args = append(args,
"-netdev", fmt.Sprintf("tap,id=net0,ifname=tap%d,script=no,downscript=no", cfg.TapID),
"-device", fmt.Sprintf("virtio-net-pci,netdev=net0,mac=%s,bus=pci.0,addr=0x03", cfg.Mac),
"-daemonize",
)
// Slots 0x03 à 0x1d réservés au réseau par la carte PCI (#36). Le slot est
// dérivé de l'index et non laissé à QEMU : c'est lui qui fixe le nom de
// l'interface dans le guest, et un slot flottant la renomme d'un démarrage
// à l'autre.
if len(cfg.NICs) == 0 {
return fmt.Errorf("vm %s has no network interface", cfg.Name)
}
if len(cfg.NICs) > maxNICs {
return fmt.Errorf("vm %s has %d interfaces, the pci map holds %d", cfg.Name, len(cfg.NICs), maxNICs)
}
for i, n := range cfg.NICs {
args = append(args,
"-netdev", fmt.Sprintf("tap,id=net%d,ifname=tap%d,script=no,downscript=no", i, n.TapID),
"-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s,bus=pci.0,addr=0x%02x", i, n.Mac, firstNICSlot+i),
)
}
args = append(args, "-daemonize")
scopeArgs := append([]string{
"--scope",