From 9c819db5a3523bc38fb036bd7c91bb334eb872a8 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 16 Oct 2018 13:20:55 -0700 Subject: [PATCH] qemu: Fix virtio-net-pci QMP command This patch fixes the wrong behavior of specifying a netdev, MAC address or PCI address entry when those were empty. Instead, it does not provide those entries if the content is empty. Signed-off-by: Sebastien Boeuf --- qemu/qmp.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qemu/qmp.go b/qemu/qmp.go index 134608ec7d..43daed369d 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -912,15 +912,21 @@ func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAd args := map[string]interface{}{ "id": devID, "driver": VirtioNetPCI, - "netdev": netdevID, - "mac": macAddr, - "addr": addr, "romfile": romfile, } if bus != "" { args["bus"] = bus } + if addr != "" { + args["addr"] = addr + } + if macAddr != "" { + args["mac"] = macAddr + } + if netdevID != "" { + args["netdev"] = netdevID + } if queues > 0 { // (2N+2 vectors, N for tx queues, N for rx queues, 1 for config, and one for possible control vq)