From f246cdb5aca13ac9409b2ad43087e3078615ffcb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Rouault Date: Thu, 23 Feb 2012 10:34:45 +0100 Subject: [PATCH] vmx: Better Workstation vmx handling This patch adds support for vmx files with empty networkName values (which is the case for vmx generated by Workstation). It also adds support for vmx containing NATed network interfaces. Update test suite accordingly --- src/vmx/vmx.c | 39 +++++++++----- tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx | 6 +++ tests/vmx2xmldata/vmx2xml-ethernet-nat.xml | 21 ++++++++ .../vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx | 52 +++++++++++++++++++ .../vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml | 35 +++++++++++++ .../vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx | 52 +++++++++++++++++++ .../vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml | 36 +++++++++++++ tests/vmx2xmltest.c | 4 ++ tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx | 14 +++++ tests/xml2vmxdata/xml2vmx-ethernet-nat.xml | 13 +++++ .../xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx | 22 ++++++++ .../xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml | 29 +++++++++++ .../xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx | 22 ++++++++ .../xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml | 30 +++++++++++ tests/xml2vmxtest.c | 4 ++ 15 files changed, 366 insertions(+), 13 deletions(-) create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-ethernet-nat.xml create mode 100644 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml create mode 100644 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-ethernet-nat.xml create mode 100644 tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml create mode 100644 tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 823d5dfc9c..910bb0eb69 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -2418,12 +2418,20 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) } /* vmx:networkName -> def:data.bridge.brname */ - if ((connectionType == NULL || - STRCASEEQ(connectionType, "bridged") || - STRCASEEQ(connectionType, "custom")) && - virVMXGetConfigString(conf, networkName_name, &networkName, - false) < 0) { - goto cleanup; + if (connectionType == NULL || + STRCASEEQ(connectionType, "bridged") || + STRCASEEQ(connectionType, "custom")) { + if (virVMXGetConfigString(conf, networkName_name, &networkName, + true) < 0) + goto cleanup; + + if (networkName == NULL) { + networkName = strdup(""); + if (networkName == NULL) { + virReportOOMError(); + goto cleanup; + } + } } /* vmx:vnet -> def:data.ifname */ @@ -2447,11 +2455,10 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) connectionType, connectionType_name); goto cleanup; } else if (STRCASEEQ(connectionType, "nat")) { - /* FIXME */ - VMX_ERROR(VIR_ERR_INTERNAL_ERROR, - _("No yet handled value '%s' for VMX entry '%s'"), - connectionType, connectionType_name); - goto cleanup; + (*def)->type = VIR_DOMAIN_NET_TYPE_USER; + (*def)->model = virtualDev; + + virtualDev = NULL; } else if (STRCASEEQ(connectionType, "custom")) { (*def)->type = VIR_DOMAIN_NET_TYPE_BRIDGE; (*def)->model = virtualDev; @@ -3533,8 +3540,9 @@ virVMXFormatEthernet(virDomainNetDefPtr def, int controller, /* def:type, def:ifname -> vmx:connectionType */ switch (def->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: - virBufferAsprintf(buffer, "ethernet%d.networkName = \"%s\"\n", - controller, def->data.bridge.brname); + if (STRNEQ(def->data.bridge.brname, "")) + virBufferAsprintf(buffer, "ethernet%d.networkName = \"%s\"\n", + controller, def->data.bridge.brname); if (def->ifname != NULL) { virBufferAsprintf(buffer, "ethernet%d.connectionType = \"custom\"\n", @@ -3548,6 +3556,11 @@ virVMXFormatEthernet(virDomainNetDefPtr def, int controller, break; + case VIR_DOMAIN_NET_TYPE_USER: + virBufferAsprintf(buffer, "ethernet%d.connectionType = \"nat\"\n", + controller); + break; + default: VMX_ERROR(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported net type '%s'"), virDomainNetTypeToString(def->type)); diff --git a/tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx b/tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx new file mode 100644 index 0000000000..701c3851fb --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx @@ -0,0 +1,6 @@ +config.version = "8" +virtualHW.version = "4" +ethernet0.present = "true" +ethernet0.connectionType = "nat" +ethernet0.addressType = "static" +ethernet0.address = "00:50:56:11:22:33" diff --git a/tests/vmx2xmldata/vmx2xml-ethernet-nat.xml b/tests/vmx2xmldata/vmx2xml-ethernet-nat.xml new file mode 100644 index 0000000000..8631049e8a --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ethernet-nat.xml @@ -0,0 +1,21 @@ + + 00000000-0000-0000-0000-000000000000 + 32768 + 32768 + 1 + + hvm + + + destroy + restart + destroy + + + + + + + diff --git a/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx new file mode 100644 index 0000000000..a25f3de64a --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx @@ -0,0 +1,52 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "8" +virtualHW.productCompatibility = "hosted" +displayName = "debian6" +guestOS = "debian6-64" +memsize = "512" +numvcpus = "1" +vcpu.hotadd = "TRUE" +scsi0.present = "TRUE" +scsi0.virtualDev = "lsilogic" +scsi0:0.present = "TRUE" +scsi0:0.fileName = "/data/vmware/disk.vmdk" +ide1:0.present = "TRUE" +ide1:0.fileName = "/usr/lib/vmware/isoimages/linux.iso" +ide1:0.deviceType = "cdrom-image" +floppy0.startConnected = "FALSE" +floppy0.fileName = "" +floppy0.autodetect = "TRUE" +ethernet0.present = "TRUE" +ethernet0.connectionType = "nat" +ethernet0.virtualDev = "e1000" +ethernet0.wakeOnPcktRcv = "FALSE" +ethernet0.addressType = "static" +ethernet0.address = "00:50:56:2F:D3:46" +usb.present = "TRUE" +usb.vbluetooth.startConnected = "TRUE" +ehci.present = "TRUE" +sound.present = "TRUE" +sound.startConnected = "FALSE" +sound.fileName = "-1" +sound.autodetect = "TRUE" +pciBridge0.present = "TRUE" +pciBridge4.present = "TRUE" +pciBridge4.virtualDev = "pcieRootPort" +pciBridge4.functions = "8" +pciBridge5.present = "TRUE" +pciBridge5.virtualDev = "pcieRootPort" +pciBridge5.functions = "8" +pciBridge6.present = "TRUE" +pciBridge6.virtualDev = "pcieRootPort" +pciBridge6.functions = "8" +pciBridge7.present = "TRUE" +pciBridge7.virtualDev = "pcieRootPort" +pciBridge7.functions = "8" +vmci0.present = "TRUE" +hpet0.present = "TRUE" +powerType.powerOff = "hard" +powerType.powerOn = "hard" +powerType.suspend = "hard" +powerType.reset = "hard" +serial0.present = "FALSE" diff --git a/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml new file mode 100644 index 0000000000..71bf9e88d4 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml @@ -0,0 +1,35 @@ + + debian6 + 00000000-0000-0000-0000-000000000000 + 524288 + 524288 + 1 + + hvm + + + destroy + restart + destroy + + + + +
+ + + + +
+ + + + + + + + + + diff --git a/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx new file mode 100644 index 0000000000..6e078d4d92 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx @@ -0,0 +1,52 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "8" +virtualHW.productCompatibility = "hosted" +displayName = "debian6" +guestOS = "debian6-64" +memsize = "512" +numvcpus = "1" +vcpu.hotadd = "TRUE" +scsi0.present = "TRUE" +scsi0.virtualDev = "lsilogic" +scsi0:0.present = "TRUE" +scsi0:0.fileName = "/data/vmware/disk.vmdk" +ide1:0.present = "TRUE" +ide1:0.fileName = "/usr/lib/vmware/isoimages/linux.iso" +ide1:0.deviceType = "cdrom-image" +floppy0.startConnected = "FALSE" +floppy0.fileName = "" +floppy0.autodetect = "TRUE" +ethernet0.present = "TRUE" +ethernet0.connectionType = "bridged" +ethernet0.virtualDev = "e1000" +ethernet0.wakeOnPcktRcv = "FALSE" +ethernet0.addressType = "static" +ethernet0.address = "00:50:56:2F:D3:46" +usb.present = "TRUE" +usb.vbluetooth.startConnected = "TRUE" +ehci.present = "TRUE" +sound.present = "TRUE" +sound.startConnected = "FALSE" +sound.fileName = "-1" +sound.autodetect = "TRUE" +pciBridge0.present = "TRUE" +pciBridge4.present = "TRUE" +pciBridge4.virtualDev = "pcieRootPort" +pciBridge4.functions = "8" +pciBridge5.present = "TRUE" +pciBridge5.virtualDev = "pcieRootPort" +pciBridge5.functions = "8" +pciBridge6.present = "TRUE" +pciBridge6.virtualDev = "pcieRootPort" +pciBridge6.functions = "8" +pciBridge7.present = "TRUE" +pciBridge7.virtualDev = "pcieRootPort" +pciBridge7.functions = "8" +vmci0.present = "TRUE" +hpet0.present = "TRUE" +powerType.powerOff = "hard" +powerType.powerOn = "hard" +powerType.suspend = "hard" +powerType.reset = "hard" +serial0.present = "FALSE" diff --git a/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml new file mode 100644 index 0000000000..d31020413a --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml @@ -0,0 +1,36 @@ + + debian6 + 00000000-0000-0000-0000-000000000000 + 524288 + 524288 + 1 + + hvm + + + destroy + restart + destroy + + + + +
+ + + + +
+ + + + + + + + + + + diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 3c566f8986..35740ea423 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -245,6 +245,7 @@ mymain(void) DO_TEST("ethernet-custom", "ethernet-custom"); DO_TEST("ethernet-bridged", "ethernet-bridged"); + DO_TEST("ethernet-nat", "ethernet-nat"); DO_TEST("ethernet-generated", "ethernet-generated"); DO_TEST("ethernet-static", "ethernet-static"); @@ -275,6 +276,9 @@ mymain(void) DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3"); DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4"); + DO_TEST("ws-in-the-wild-1", "ws-in-the-wild-1"); + DO_TEST("ws-in-the-wild-2", "ws-in-the-wild-2"); + DO_TEST("annotation", "annotation"); DO_TEST("smbios", "smbios"); diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx b/tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx new file mode 100644 index 0000000000..0ee0f034f7 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx @@ -0,0 +1,14 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "4" +guestOS = "other" +uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15" +displayName = "ethernet-nat" +memsize = "4" +numvcpus = "1" +floppy0.present = "false" +floppy1.present = "false" +ethernet0.present = "true" +ethernet0.connectionType = "nat" +ethernet0.addressType = "static" +ethernet0.address = "00:50:56:11:22:33" diff --git a/tests/xml2vmxdata/xml2vmx-ethernet-nat.xml b/tests/xml2vmxdata/xml2vmx-ethernet-nat.xml new file mode 100644 index 0000000000..1df74f4eaf --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ethernet-nat.xml @@ -0,0 +1,13 @@ + + ethernet-nat + 564d9bef-acd9-b4e0-c8f0-aea8b9103515 + 4096 + + hvm + + + + + + + diff --git a/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx new file mode 100644 index 0000000000..539a371237 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx @@ -0,0 +1,22 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "8" +guestOS = "other-64" +uuid.bios = "dc d9 c4 36 48 25 4f c0-8f a1 14 44 4b 0f 05 69" +displayName = "dcd9c436-4825-4fc0-8fa1-14444b0f0569" +memsize = "512" +numvcpus = "1" +scsi0.present = "true" +scsi0.virtualDev = "lsilogic" +scsi0:0.present = "true" +scsi0:0.deviceType = "scsi-hardDisk" +scsi0:0.fileName = "/data/vmware/disk.vmdk" +floppy0.present = "false" +floppy1.present = "false" +ethernet0.present = "true" +ethernet0.virtualDev = "e1000" +ethernet0.connectionType = "nat" +ethernet0.addressType = "static" +ethernet0.address = "00:90:B9:DC:EA:81" +ethernet0.checkMACAddress = "false" +svga.vramSize = "4194304" diff --git a/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml new file mode 100644 index 0000000000..eab25d8e58 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml @@ -0,0 +1,29 @@ + + dcd9c436-4825-4fc0-8fa1-14444b0f0569 + dcd9c436-4825-4fc0-8fa1-14444b0f0569 + 524288 + 524288 + 1 + + hvm + + + destroy + restart + destroy + + + + +
+ + + + + + + + + diff --git a/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx new file mode 100644 index 0000000000..7035ac3160 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx @@ -0,0 +1,22 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "8" +guestOS = "other-64" +uuid.bios = "dc d9 c4 36 48 25 4f c0-8f a1 14 44 4b 0f 05 69" +displayName = "dcd9c436-4825-4fc0-8fa1-14444b0f0569" +memsize = "512" +numvcpus = "1" +scsi0.present = "true" +scsi0.virtualDev = "lsilogic" +scsi0:0.present = "true" +scsi0:0.deviceType = "scsi-hardDisk" +scsi0:0.fileName = "/data/vmware/disk.vmdk" +floppy0.present = "false" +floppy1.present = "false" +ethernet0.present = "true" +ethernet0.virtualDev = "e1000" +ethernet0.connectionType = "bridged" +ethernet0.addressType = "static" +ethernet0.address = "00:90:B9:DC:EA:81" +ethernet0.checkMACAddress = "false" +svga.vramSize = "4194304" diff --git a/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml new file mode 100644 index 0000000000..30fb76c818 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml @@ -0,0 +1,30 @@ + + dcd9c436-4825-4fc0-8fa1-14444b0f0569 + dcd9c436-4825-4fc0-8fa1-14444b0f0569 + 524288 + 524288 + 1 + + hvm + + + destroy + restart + destroy + + + + +
+ + + + + + + + + + diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index f4e4ed6b60..60a24b2a6b 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -260,6 +260,7 @@ mymain(void) DO_TEST("ethernet-custom", "ethernet-custom", 4); DO_TEST("ethernet-bridged", "ethernet-bridged", 4); + DO_TEST("ethernet-nat", "ethernet-nat", 4); DO_TEST("ethernet-generated", "ethernet-generated", 4); DO_TEST("ethernet-static", "ethernet-static", 4); @@ -287,6 +288,9 @@ mymain(void) DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3", 4); DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4", 4); + DO_TEST("ws-in-the-wild-1", "ws-in-the-wild-1", 8); + DO_TEST("ws-in-the-wild-2", "ws-in-the-wild-2", 8); + DO_TEST("annotation", "annotation", 4); DO_TEST("smbios", "smbios", 4); -- GitLab