]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vmx: Better Workstation vmx handling
authorJean-Baptiste Rouault <jean-baptiste.rouault@diateam.net>
Thu, 23 Feb 2012 09:34:45 +0000 (10:34 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 24 Feb 2012 10:53:23 +0000 (11:53 +0100)
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

15 files changed:
src/vmx/vmx.c
tests/vmx2xmldata/vmx2xml-ethernet-nat.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-ethernet-nat.xml [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml [new file with mode: 0644]
tests/vmx2xmltest.c
tests/xml2vmxdata/xml2vmx-ethernet-nat.vmx [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-ethernet-nat.xml [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.vmx [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-ws-in-the-wild-1.xml [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.vmx [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-ws-in-the-wild-2.xml [new file with mode: 0644]
tests/xml2vmxtest.c

index 823d5dfc9caeda7e6348e6ea1c470fb230290da0..910bb0eb69150c90ddf8419c7d42724ab1b8a7a9 100644 (file)
@@ -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 (file)
index 0000000..701c385
--- /dev/null
@@ -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 (file)
index 0000000..8631049
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='vmware'>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory>32768</memory>
+  <currentMemory>32768</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <interface type='user'>
+      <mac address='00:50:56:11:22:33'/>
+    </interface>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
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 (file)
index 0000000..a25f3de
--- /dev/null
@@ -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 (file)
index 0000000..71bf9e8
--- /dev/null
@@ -0,0 +1,35 @@
+<domain type='vmware'>
+  <name>debian6</name>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory>524288</memory>
+  <currentMemory>524288</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <source file='/data/vmware/disk.vmdk'/>
+      <target dev='sda' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <source file='/usr/lib/vmware/isoimages/linux.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <address type='drive' controller='0' bus='1' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0' model='lsilogic'/>
+    <controller type='ide' index='0'/>
+    <interface type='user'>
+      <mac address='00:50:56:2f:d3:46'/>
+      <model type='e1000'/>
+    </interface>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
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 (file)
index 0000000..6e078d4
--- /dev/null
@@ -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 (file)
index 0000000..d310204
--- /dev/null
@@ -0,0 +1,36 @@
+<domain type='vmware'>
+  <name>debian6</name>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory>524288</memory>
+  <currentMemory>524288</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <source file='/data/vmware/disk.vmdk'/>
+      <target dev='sda' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <source file='/usr/lib/vmware/isoimages/linux.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <address type='drive' controller='0' bus='1' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0' model='lsilogic'/>
+    <controller type='ide' index='0'/>
+    <interface type='bridge'>
+      <mac address='00:50:56:2f:d3:46'/>
+      <source bridge=''/>
+      <model type='e1000'/>
+    </interface>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
index 3c566f898624db698cd846a96c0781fe6fb849e8..35740ea423d044815cd6fe7f7e523afcfa3f5408 100644 (file)
@@ -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 (file)
index 0000000..0ee0f03
--- /dev/null
@@ -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 (file)
index 0000000..1df74f4
--- /dev/null
@@ -0,0 +1,13 @@
+<domain type='vmware'>
+  <name>ethernet-nat</name>
+  <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
+  <memory>4096</memory>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <interface type='user'>
+      <mac address='00:50:56:11:22:33'/>
+    </interface>
+  </devices>
+</domain>
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 (file)
index 0000000..539a371
--- /dev/null
@@ -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 (file)
index 0000000..eab25d8
--- /dev/null
@@ -0,0 +1,29 @@
+<domain type='vmware'>
+  <name>dcd9c436-4825-4fc0-8fa1-14444b0f0569</name>
+  <uuid>dcd9c436-4825-4fc0-8fa1-14444b0f0569</uuid>
+  <memory>524288</memory>
+  <currentMemory>524288</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <source file='/data/vmware/disk.vmdk'/>
+      <target dev='sda' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0' model='lsilogic'/>
+    <interface type='user'>
+      <mac address='00:90:b9:dc:ea:81'/>
+      <model type='e1000'/>
+    </interface>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
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 (file)
index 0000000..7035ac3
--- /dev/null
@@ -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 (file)
index 0000000..30fb76c
--- /dev/null
@@ -0,0 +1,30 @@
+<domain type='vmware'>
+  <name>dcd9c436-4825-4fc0-8fa1-14444b0f0569</name>
+  <uuid>dcd9c436-4825-4fc0-8fa1-14444b0f0569</uuid>
+  <memory>524288</memory>
+  <currentMemory>524288</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <source file='/data/vmware/disk.vmdk'/>
+      <target dev='sda' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0' model='lsilogic'/>
+    <interface type='bridge'>
+      <mac address='00:90:b9:dc:ea:81'/>
+      <source bridge=''/>
+      <model type='e1000'/>
+    </interface>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
index f4e4ed6b60d37eb4a917a29f5f711b85e6700b86..60a24b2a6bb10b5389de62b5ce196aa8464b1b8b 100644 (file)
@@ -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);