2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2026-06-22 12:26:07 +00:00

feat: add mac address support to qemu run command

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2026-06-18 15:37:31 +02:00
parent 58739c9f1b
commit 8d40bc255e
4 changed files with 21 additions and 3 deletions
+10 -3
View File
@@ -135,6 +135,14 @@ func Run(ctx context.Context, path string, opts ...Option) error {
return fmt.Errorf("Invalid networking mode: %s", netMode[0])
}
if config.mac != "" {
if _, err := net.ParseMAC(config.mac); err != nil {
return fmt.Errorf("Invalid MAC address: %s", config.mac)
}
} else {
config.mac = generateMAC().String()
}
if err := config.discoverBinaries(); err != nil {
log.Fatal(err)
}
@@ -286,11 +294,10 @@ func (c *config) buildQemuCmdline() ([]string, error) {
}
if c.netdevConfig != "" {
mac := generateMAC()
if c.arch == "s390x" {
qemuArgs = append(qemuArgs, "-device", "virtio-net-ccw,netdev=t0,mac="+mac.String())
qemuArgs = append(qemuArgs, "-device", "virtio-net-ccw,netdev=t0,mac="+c.mac)
} else {
qemuArgs = append(qemuArgs, "-device", "virtio-net-pci,netdev=t0,mac="+mac.String())
qemuArgs = append(qemuArgs, "-device", "virtio-net-pci,netdev=t0,mac="+c.mac)
}
forwardings, err := buildQemuForwardings(c.publishedPorts)
if err != nil {