esx: Move VMX handling code out of the driver directory

Now the VMware driver doesn't depend on the ESX driver anymore.

Add a WITH_VMX option that depends on WITH_ESX and WITH_VMWARE.
Also add a libvirt_vmx.syms file.

Move some escaping functions from esx_util.c to vmx.c.

Adapt the test suite, ESX and VMware driver to the new code layout.
This commit is contained in:
Matthias Bolte 2010-12-21 22:39:55 +01:00
parent 8cd4ca459e
commit 42b2f35d36
19 changed files with 1044 additions and 1035 deletions

View File

@ -1776,6 +1776,15 @@ if test "$with_esx" = "yes" ; then
fi
AM_CONDITIONAL([WITH_ESX], [test "$with_esx" = "yes"])
with_vmx=yes
if test "$with_esx" != "yes" && test "$with_vmware" != "yes"; then
with_vmx=no
fi
if test "$with_vmx" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_VMX], 1, [whether VMware VMX config handling is enabled])
fi
AM_CONDITIONAL([WITH_VMX], [test "$with_vmx" = "yes"])
if test "$with_xenapi" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_XENAPI], 1, [whether XenAPI driver is enabled])
fi

View File

@ -25,7 +25,6 @@ src/esx/esx_util.c
src/esx/esx_vi.c
src/esx/esx_vi_methods.c
src/esx/esx_vi_types.c
src/esx/esx_vmx.c
src/fdstream.c
src/interface/netcf_driver.c
src/internal.h
@ -109,6 +108,7 @@ src/vbox/vbox_driver.c
src/vbox/vbox_tmpl.c
src/vmware/vmware_conf.c
src/vmware/vmware_driver.c
src/vmx/vmx.c
src/xen/xen_driver.c
src/xen/xen_hypervisor.c
src/xen/xen_inotify.c

View File

@ -322,8 +322,7 @@ ESX_DRIVER_SOURCES = \
esx/esx_util.c esx/esx_util.h \
esx/esx_vi.c esx/esx_vi.h \
esx/esx_vi_methods.c esx/esx_vi_methods.h \
esx/esx_vi_types.c esx/esx_vi_types.h \
esx/esx_vmx.c esx/esx_vmx.h
esx/esx_vi_types.c esx/esx_vi_types.h
ESX_DRIVER_GENERATED = \
esx/esx_vi_methods.generated.c \
@ -418,6 +417,9 @@ CPU_SOURCES = \
cpu/cpu_x86.h cpu/cpu_x86.c cpu/cpu_x86_data.h \
cpu/cpu_map.h cpu/cpu_map.c
VMX_SOURCES = \
vmx/vmx.c vmx/vmx.h
pkgdata_DATA = cpu/cpu_map.xml
EXTRA_DIST += $(pkgdata_DATA)
@ -451,6 +453,14 @@ libvirt_cpu_la_CFLAGS = \
-I@top_srcdir@/src/conf $(AM_CFLAGS)
libvirt_cpu_la_SOURCES = $(CPU_SOURCES)
if WITH_VMX
noinst_LTLIBRARIES += libvirt_vmx.la
libvirt_la_BUILT_LIBADD += libvirt_vmx.la
libvirt_vmx_la_CFLAGS = \
-I@top_srcdir@/src/conf $(AM_CFLAGS)
libvirt_vmx_la_SOURCES = $(VMX_SOURCES)
endif
noinst_LTLIBRARIES += libvirt_driver.la
libvirt_la_BUILT_LIBADD += libvirt_driver.la
@ -621,7 +631,7 @@ noinst_LTLIBRARIES += libvirt_driver_vmware.la
libvirt_la_BUILT_LIBADD += libvirt_driver_vmware.la
endif
libvirt_driver_vmware_la_CFLAGS = \
-I@top_srcdir@/src/conf
-I@top_srcdir@/src/conf -I@top_srcdir@/src/vmx
if WITH_DRIVER_MODULES
libvirt_driver_vmware_la_LDFLAGS = -module -avoid-version
endif
@ -768,7 +778,7 @@ noinst_LTLIBRARIES += libvirt_driver_esx.la
libvirt_la_BUILT_LIBADD += libvirt_driver_esx.la
endif
libvirt_driver_esx_la_CFLAGS = $(LIBCURL_CFLAGS) \
-I@top_srcdir@/src/conf $(AM_CFLAGS)
-I@top_srcdir@/src/conf -I@top_srcdir@/src/vmx $(AM_CFLAGS)
libvirt_driver_esx_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_esx_la_LIBADD = $(LIBCURL_LIBS)
if WITH_DRIVER_MODULES
@ -1043,6 +1053,10 @@ if WITH_NWFILTER
USED_SYM_FILES += libvirt_nwfilter.syms
endif
if WITH_VMX
USED_SYM_FILES += libvirt_vmx.syms
endif
EXTRA_DIST += \
libvirt_public.syms \
libvirt_private.syms \

View File

@ -31,6 +31,7 @@
#include "memory.h"
#include "logging.h"
#include "uuid.h"
#include "vmx.h"
#include "esx_driver.h"
#include "esx_interface_driver.h"
#include "esx_network_driver.h"
@ -42,7 +43,6 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
#include "esx_vmx.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@ -88,7 +88,7 @@ struct _esxVMX_Data {
* Firstly this functions checks if the given file name contains a separator.
* If it doesn't then the referenced file is in the same directory as the .vmx
* file. The datastore name and directory of the .vmx file are passed to this
* function via the opaque paramater by the caller of esxVMX_ParseConfig.
* function via the opaque parameter by the caller of virVMXParseConfig.
*
* Otherwise query for all known datastores and their mount directories. Then
* try to find a datastore with a mount directory that is a prefix to the given
@ -584,10 +584,6 @@ esxCapsInit(esxPrivate *priv)
goto failure;
}
/*
* FIXME: Maybe distinguish betwen ESX and GSX here, see
* esxVMX_ParseConfig() and VIR_DOMAIN_VIRT_VMWARE
*/
if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0,
NULL) == NULL) {
goto failure;
@ -602,10 +598,6 @@ esxCapsInit(esxPrivate *priv)
goto failure;
}
/*
* FIXME: Maybe distinguish betwen ESX and GSX here, see
* esxVMX_ParseConfig() and VIR_DOMAIN_VIRT_VMWARE
*/
if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0,
NULL) == NULL) {
goto failure;
@ -2570,7 +2562,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
char *vmx = NULL;
esxVMX_Context ctx;
virVMXContext ctx;
esxVMX_Data data;
virDomainDefPtr def = NULL;
char *xml = NULL;
@ -2637,8 +2629,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
ctx.formatFileName = NULL;
ctx.autodetectSCSIControllerModel = NULL;
def = esxVMX_ParseConfig(&ctx, priv->caps, vmx,
priv->primary->productVersion);
def = virVMXParseConfig(&ctx, priv->caps, vmx);
if (def != NULL) {
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
@ -2674,7 +2665,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
unsigned int flags ATTRIBUTE_UNUSED)
{
esxPrivate *priv = conn->privateData;
esxVMX_Context ctx;
virVMXContext ctx;
esxVMX_Data data;
virDomainDefPtr def = NULL;
char *xml = NULL;
@ -2693,8 +2684,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
ctx.formatFileName = NULL;
ctx.autodetectSCSIControllerModel = NULL;
def = esxVMX_ParseConfig(&ctx, priv->caps, nativeConfig,
priv->primary->productVersion);
def = virVMXParseConfig(&ctx, priv->caps, nativeConfig);
if (def != NULL) {
xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
@ -2713,7 +2703,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
unsigned int flags ATTRIBUTE_UNUSED)
{
esxPrivate *priv = conn->privateData;
esxVMX_Context ctx;
int virtualHW_version;
virVMXContext ctx;
esxVMX_Data data;
virDomainDefPtr def = NULL;
char *vmx = NULL;
@ -2724,6 +2715,13 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
return NULL;
}
virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion
(priv->primary->productVersion);
if (virtualHW_version < 0) {
return NULL;
}
def = virDomainDefParseString(priv->caps, domainXml, 0);
if (def == NULL) {
@ -2738,8 +2736,7 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
ctx.formatFileName = esxFormatVMXFileName;
ctx.autodetectSCSIControllerModel = esxAutodetectSCSIControllerModel;
vmx = esxVMX_FormatConfig(&ctx, priv->caps, def,
priv->primary->productVersion);
vmx = virVMXFormatConfig(&ctx, priv->caps, def, virtualHW_version);
virDomainDefFree(def);
@ -2922,7 +2919,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
int i;
virDomainDiskDefPtr disk = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVMX_Context ctx;
int virtualHW_version;
virVMXContext ctx;
esxVMX_Data data;
char *datastoreName = NULL;
char *directoryName = NULL;
@ -2973,6 +2971,13 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
}
/* Build VMX from domain XML */
virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion
(priv->primary->productVersion);
if (virtualHW_version < 0) {
goto cleanup;
}
data.ctx = priv->primary;
data.datastorePathWithoutFileName = NULL;
@ -2981,8 +2986,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
ctx.formatFileName = esxFormatVMXFileName;
ctx.autodetectSCSIControllerModel = esxAutodetectSCSIControllerModel;
vmx = esxVMX_FormatConfig(&ctx, priv->caps, def,
priv->primary->productVersion);
vmx = virVMXFormatConfig(&ctx, priv->caps, def, virtualHW_version);
if (vmx == NULL) {
goto cleanup;

View File

@ -24,7 +24,6 @@
#include <config.h>
#include <c-ctype.h>
#include <netdb.h>
#include "internal.h"
@ -34,6 +33,7 @@
#include "memory.h"
#include "logging.h"
#include "uuid.h"
#include "vmx.h"
#include "esx_private.h"
#include "esx_util.h"
@ -414,198 +414,6 @@ esxUtil_ResolveHostname(const char *hostname,
int
esxUtil_GetConfigString(virConfPtr conf, const char *name, char **string,
bool optional)
{
virConfValuePtr value;
*string = NULL;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
}
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
if (value->type != VIR_CONF_STRING) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must be a string"), name);
return -1;
}
if (value->str == NULL) {
if (optional) {
return 0;
}
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
*string = strdup(value->str);
if (*string == NULL) {
virReportOOMError();
return -1;
}
return 0;
}
int
esxUtil_GetConfigUUID(virConfPtr conf, const char *name, unsigned char *uuid,
bool optional)
{
virConfValuePtr value;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (value->type != VIR_CONF_STRING) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must be a string"), name);
return -1;
}
if (value->str == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (virUUIDParse(value->str, uuid) < 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not parse UUID from string '%s'"), value->str);
return -1;
}
return 0;
}
int
esxUtil_GetConfigLong(virConfPtr conf, const char *name, long long *number,
long long default_, bool optional)
{
virConfValuePtr value;
*number = default_;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (value->type == VIR_CONF_STRING) {
if (value->str == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (STREQ(value->str, "unlimited")) {
*number = -1;
} else if (virStrToLong_ll(value->str, NULL, 10, number) < 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must represent an integer value"),
name);
return -1;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must be a string"), name);
return -1;
}
return 0;
}
int
esxUtil_GetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_,
bool default_, bool optional)
{
virConfValuePtr value;
*boolean_ = default_;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (value->type == VIR_CONF_STRING) {
if (value->str == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
return -1;
}
}
if (STRCASEEQ(value->str, "true")) {
*boolean_ = 1;
} else if (STRCASEEQ(value->str, "false")) {
*boolean_ = 0;
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must represent a boolean value "
"(true|false)"), name);
return -1;
}
} else {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Config entry '%s' must be a string"), name);
return -1;
}
return 0;
}
int
esxUtil_ReformatUuid(const char *input, char *output)
{
@ -625,81 +433,6 @@ esxUtil_ReformatUuid(const char *input, char *output)
char *
esxUtil_EscapeHex(const char *string, char escape, const char *special)
{
char *escaped = NULL;
size_t length = 1; /* 1 byte for termination */
const char *tmp1 = string;
char *tmp2;
/* Calculate length of escaped string */
while (*tmp1 != '\0') {
if (*tmp1 == escape || strspn(tmp1, special) > 0) {
length += 2;
}
++tmp1;
++length;
}
if (VIR_ALLOC_N(escaped, length) < 0) {
virReportOOMError();
return NULL;
}
tmp1 = string; /* reading from this one */
tmp2 = escaped; /* writing to this one */
/* Escape to 'cXX' where c is the escape char and X is a hex digit */
while (*tmp1 != '\0') {
if (*tmp1 == escape || strspn(tmp1, special) > 0) {
*tmp2++ = escape;
snprintf(tmp2, 3, "%02x", (unsigned int)*tmp1);
tmp2 += 2;
} else {
*tmp2++ = *tmp1;
}
++tmp1;
}
*tmp2 = '\0';
return escaped;
}
int
esxUtil_UnescapeHex(char *string, char escape)
{
char *tmp1 = string; /* reading from this one */
char *tmp2 = string; /* writing to this one */
/* Unescape from 'cXX' where c is the escape char and X is a hex digit */
while (*tmp1 != '\0') {
if (*tmp1 == escape) {
if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) {
return -1;
}
*tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]);
tmp1 += 3;
} else {
*tmp2++ = *tmp1++;
}
}
*tmp2 = '\0';
return 0;
}
char *
esxUtil_EscapeBase64(const char *string)
{
@ -805,7 +538,7 @@ esxUtil_EscapeDatastoreItem(const char *string)
esxUtil_ReplaceSpecialWindowsPathChars(replaced);
escaped1 = esxUtil_EscapeHexPercent(replaced);
escaped1 = virVMXEscapeHexPercent(replaced);
if (escaped1 == NULL) {
goto cleanup;
@ -819,41 +552,3 @@ esxUtil_EscapeDatastoreItem(const char *string)
return escaped2;
}
char *
esxUtil_ConvertToUTF8(const char *encoding, const char *string)
{
char *result = NULL;
xmlCharEncodingHandlerPtr handler;
xmlBufferPtr input;
xmlBufferPtr utf8;
handler = xmlFindCharEncodingHandler(encoding);
if (handler == NULL) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("libxml2 doesn't handle %s encoding"), encoding);
return NULL;
}
input = xmlBufferCreateStatic((char *)string, strlen(string));
utf8 = xmlBufferCreate();
if (xmlCharEncInFunc(handler, utf8, input) < 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not convert from %s to UTF-8 encoding"), encoding);
goto cleanup;
}
result = (char *)utf8->content;
utf8->content = NULL;
cleanup:
xmlCharEncCloseFunc(handler);
xmlBufferFree(input);
xmlBufferFree(utf8);
return result;
}

View File

@ -27,7 +27,6 @@
# include <libxml/uri.h>
# include "internal.h"
# include "conf.h"
typedef struct _esxUtil_ParsedUri esxUtil_ParsedUri;
@ -57,38 +56,12 @@ int esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
int esxUtil_ResolveHostname(const char *hostname,
char *ipAddress, size_t ipAddress_length);
int esxUtil_GetConfigString(virConfPtr conf, const char *name, char **string,
bool optional);
int esxUtil_GetConfigUUID(virConfPtr conf, const char *name,
unsigned char *uuid, bool optional);
int esxUtil_GetConfigLong(virConfPtr conf, const char *name, long long *number,
long long default_, bool optional);
int esxUtil_GetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_,
bool default_, bool optional);
int esxUtil_ReformatUuid(const char *input, char *output);
char *esxUtil_EscapeHex(const char *string, char escape, const char *special);
# define esxUtil_EscapeHexPipe(_string) esxUtil_EscapeHex(_string, '|', "\"")
# define esxUtil_EscapeHexPercent(_string) esxUtil_EscapeHex(_string, '%', "/\\")
int esxUtil_UnescapeHex(char *string, char escape);
# define esxUtil_UnescapeHexPipe(_string) esxUtil_UnescapeHex(_string, '|')
# define esxUtil_UnescapeHexPercent(_string) esxUtil_UnescapeHex(_string, '%')
char *esxUtil_EscapeBase64(const char *string);
void esxUtil_ReplaceSpecialWindowsPathChars(char *string);
char *esxUtil_EscapeDatastoreItem(const char *string);
char *esxUtil_ConvertToUTF8(const char *encoding, const char *string);
#endif /* __ESX_UTIL_H__ */

View File

@ -31,6 +31,7 @@
#include "logging.h"
#include "util.h"
#include "uuid.h"
#include "vmx.h"
#include "xml.h"
#include "esx_vi.h"
#include "esx_vi_methods.h"
@ -2048,7 +2049,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
goto failure;
}
if (esxUtil_UnescapeHexPercent(*name) < 0) {
if (virVMXUnescapeHexPercent(*name) < 0) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain name contains invalid escape sequence"));
goto failure;
@ -3723,3 +3724,40 @@ esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
return 0;
}
int
esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersion)
{
/*
* virtualHW.version compatibility matrix:
*
* 4 7 API
* ESX 3.5 + 2.5
* ESX 4.0 + + 4.0
* ESX 4.1 + + 4.1
* GSX 2.0 + + 2.5
*/
switch (productVersion) {
case esxVI_ProductVersion_ESX35:
case esxVI_ProductVersion_VPX25:
return 4;
case esxVI_ProductVersion_GSX20:
case esxVI_ProductVersion_ESX40:
case esxVI_ProductVersion_ESX41:
case esxVI_ProductVersion_VPX40:
case esxVI_ProductVersion_VPX41:
return 7;
case esxVI_ProductVersion_ESX4x:
case esxVI_ProductVersion_VPX4x:
return 7;
default:
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpected product version"));
return -1;
}
}

View File

@ -435,4 +435,6 @@ int esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
int esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
esxVI_HostCpuIdInfo *hostCpuIdInfo);
int esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersion);
#endif /* __ESX_VI_H__ */

View File

@ -1,154 +0,0 @@
/*
* esx_vmx.h: VMX related functions for the VMware ESX driver
*
* Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __ESX_VMX_H__
# define __ESX_VMX_H__
# include <stdbool.h>
# include "internal.h"
# include "conf.h"
# include "domain_conf.h"
# include "esx_vi.h"
typedef struct _esxVMX_Context esxVMX_Context;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
*/
typedef char * (*esxVMX_ParseFileName)(const char *fileName, void *opaque);
typedef char * (*esxVMX_FormatFileName)(const char *src, void *opaque);
typedef int (*esxVMX_AutodetectSCSIControllerModel)(virDomainDiskDefPtr def,
int *model, void *opaque);
/*
* esxVMX_ParseFileName is only used by esxVMX_ParseConfig.
* esxVMX_FormatFileName is only used by esxVMX_FormatConfig.
* esxVMX_AutodetectSCSIControllerModel is optionally used by esxVMX_FormatConfig.
*/
struct _esxVMX_Context {
void *opaque;
esxVMX_ParseFileName parseFileName;
esxVMX_FormatFileName formatFileName;
esxVMX_AutodetectSCSIControllerModel autodetectSCSIControllerModel;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Helpers
*/
int
esxVMX_SCSIDiskNameToControllerAndUnit(const char *name, int *controller,
int *unit);
int
esxVMX_IDEDiskNameToBusAndUnit(const char *name, int *bus, int *unit);
int
esxVMX_FloppyDiskNameToUnit(const char *name, int *unit);
int
esxVMX_VerifyDiskAddress(virCapsPtr caps, virDomainDiskDefPtr disk);
int
esxVMX_HandleLegacySCSIDiskDriverName(virDomainDefPtr def,
virDomainDiskDefPtr disk);
int
esxVMX_GatherSCSIControllers(esxVMX_Context *ctx, virDomainDefPtr def,
int virtualDev[4], bool present[4]);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VMX -> Domain XML
*/
virDomainDefPtr
esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
esxVI_ProductVersion productVersion);
int
esxVMX_ParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def);
int
esxVMX_ParseSCSIController(virConfPtr conf, int controller, bool *present,
int *virtualDev);
int
esxVMX_ParseDisk(esxVMX_Context *ctx, virCapsPtr caps, virConfPtr conf,
int device, int busType, int controllerOrBus, int unit,
virDomainDiskDefPtr *def);
int
esxVMX_ParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def);
int
esxVMX_ParseSerial(esxVMX_Context *ctx, virConfPtr conf, int port,
virDomainChrDefPtr *def);
int
esxVMX_ParseParallel(esxVMX_Context *ctx, virConfPtr conf, int port,
virDomainChrDefPtr *def);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Domain XML -> VMX
*/
char *
esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
esxVI_ProductVersion productVersion);
int
esxVMX_FormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer);
int
esxVMX_FormatHardDisk(esxVMX_Context *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer);
int
esxVMX_FormatCDROM(esxVMX_Context *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer);
int
esxVMX_FormatFloppy(esxVMX_Context *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer, bool floppy_present[2]);
int
esxVMX_FormatEthernet(virDomainNetDefPtr def, int controller,
virBufferPtr buffer);
int
esxVMX_FormatSerial(esxVMX_Context *ctx, virDomainChrDefPtr def,
virBufferPtr buffer);
int
esxVMX_FormatParallel(esxVMX_Context *ctx, virDomainChrDefPtr def,
virBufferPtr buffer);
#endif /* __ESX_VMX_H__ */

23
src/libvirt_vmx.syms Normal file
View File

@ -0,0 +1,23 @@
#
# These symbols are dependent upon --with-esx via WITH_ESX or --with-vmware via WITH_VMWARE.
#
# vmx.h
virVMXConvertToUTF8;
virVMXEscapeHex;
virVMXFormatCDROM;
virVMXFormatConfig;
virVMXFormatEthernet;
virVMXFormatFloppy;
virVMXFormatHardDisk;
virVMXFormatParallel;
virVMXFormatSerial;
virVMXFormatVNC;
virVMXParseConfig;
virVMXParseDisk;
virVMXParseEthernet;
virVMXParseParallel;
virVMXParseSCSIController;
virVMXParseSerial;
virVMXParseVNC;
virVMXUnescapeHex;

View File

@ -27,10 +27,10 @@
#include "dirname.h"
#include "memory.h"
#include "nodeinfo.h"
#include "util/files.h"
#include "files.h"
#include "uuid.h"
#include "virterror_internal.h"
#include "../esx/esx_vmx.h"
#include "vmx.h"
#include "vmware_conf.h"
@ -137,13 +137,13 @@ vmwareLoadDomains(struct vmware_driver *driver)
char *directoryName = NULL;
char *fileName = NULL;
int ret = -1;
esxVMX_Context ctx;
virVMXContext ctx;
char *outbuf = NULL;
char *str;
char *saveptr = NULL;
virCommandPtr cmd;
ctx.parseFileName = esxCopyVMXFileName;
ctx.parseFileName = vmwareCopyVMXFileName;
cmd = virCommandNewArgList(VMRUN, "-T",
driver->type == TYPE_PLAYER ? "player" : "ws",
@ -162,8 +162,7 @@ vmwareLoadDomains(struct vmware_driver *driver)
goto cleanup;
if ((vmdef =
esxVMX_ParseConfig(&ctx, driver->caps, vmx,
esxVI_ProductVersion_ESX4x)) == NULL) {
virVMXParseConfig(&ctx, driver->caps, vmx)) == NULL) {
goto cleanup;
}
@ -487,7 +486,7 @@ cleanup:
}
char *
esxCopyVMXFileName(const char *datastorePath, void *opaque ATTRIBUTE_UNUSED)
vmwareCopyVMXFileName(const char *datastorePath, void *opaque ATTRIBUTE_UNUSED)
{
char *path = strdup(datastorePath);

View File

@ -78,6 +78,6 @@ int vmwareMakePath(char *srcDir, char *srcName, char *srcExt,
int vmwareExtractPid(const char * vmxPath);
char * esxCopyVMXFileName(const char *datastorePath, void *opaque);
char *vmwareCopyVMXFileName(const char *datastorePath, void *opaque);
#endif

View File

@ -21,15 +21,17 @@
#include <fcntl.h>
#include "internal.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "files.h"
#include "memory.h"
#include "uuid.h"
#include "../esx/esx_vmx.h"
#include "vmx.h"
#include "vmware_conf.h"
#include "vmware_driver.h"
const char *vmw_types[] = { "player", "ws" };
static const char *vmw_types[] = { "player", "ws" };
static void
vmwareDriverLock(struct vmware_driver *driver)
@ -244,9 +246,9 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
char *fileName = NULL;
char *vmxPath = NULL;
vmwareDomainPtr pDomain = NULL;
esxVMX_Context ctx;
virVMXContext ctx;
ctx.formatFileName = esxCopyVMXFileName;
ctx.formatFileName = vmwareCopyVMXFileName;
vmwareDriverLock(driver);
if ((vmdef = virDomainDefParseString(driver->caps, xml,
@ -257,8 +259,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
goto cleanup;
/* generate vmx file */
vmx = esxVMX_FormatConfig(&ctx, driver->caps, vmdef,
esxVI_ProductVersion_ESX4x);
vmx = virVMXFormatConfig(&ctx, driver->caps, vmdef, 7);
if (vmx == NULL)
goto cleanup;
@ -497,9 +498,9 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
char *vmx = NULL;
char *vmxPath = NULL;
vmwareDomainPtr pDomain = NULL;
esxVMX_Context ctx;
virVMXContext ctx;
ctx.formatFileName = esxCopyVMXFileName;
ctx.formatFileName = vmwareCopyVMXFileName;
vmwareDriverLock(driver);
@ -511,8 +512,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
goto cleanup;
/* generate vmx file */
vmx = esxVMX_FormatConfig(&ctx, driver->caps, vmdef,
esxVI_ProductVersion_ESX4x);
vmx = virVMXFormatConfig(&ctx, driver->caps, vmdef, 7);
if (vmx == NULL)
goto cleanup;

File diff suppressed because it is too large Load Diff

132
src/vmx/vmx.h Normal file
View File

@ -0,0 +1,132 @@
/*
* vmx.h: VMware VMX parsing/formatting functions
*
* Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __VIR_VMX_H__
# define __VIR_VMX_H__
# include <stdbool.h>
# include "internal.h"
# include "conf.h"
# include "domain_conf.h"
typedef struct _virVMXContext virVMXContext;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
*/
typedef char * (*virVMXParseFileName)(const char *fileName, void *opaque);
typedef char * (*virVMXFormatFileName)(const char *src, void *opaque);
typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDefPtr def,
int *model, void *opaque);
/*
* virVMXParseFileName is only used by virVMXParseConfig.
* virVMXFormatFileName is only used by virVMXFormatConfig.
* virVMXAutodetectSCSIControllerModel is optionally used by virVMXFormatConfig.
*/
struct _virVMXContext {
void *opaque;
virVMXParseFileName parseFileName;
virVMXFormatFileName formatFileName;
virVMXAutodetectSCSIControllerModel autodetectSCSIControllerModel;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Helpers
*/
char *virVMXEscapeHex(const char *string, char escape, const char *special);
# define virVMXEscapeHexPipe(_string) virVMXEscapeHex(_string, '|', "\"")
# define virVMXEscapeHexPercent(_string) virVMXEscapeHex(_string, '%', "/\\")
int virVMXUnescapeHex(char *string, char escape);
# define virVMXUnescapeHexPipe(_string) virVMXUnescapeHex(_string, '|')
# define virVMXUnescapeHexPercent(_string) virVMXUnescapeHex(_string, '%')
char *virVMXConvertToUTF8(const char *encoding, const char *string);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VMX -> Domain XML
*/
virDomainDefPtr virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps,
const char *vmx);
int virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def);
int virVMXParseSCSIController(virConfPtr conf, int controller, bool *present,
int *virtualDev);
int virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf,
int device, int busType, int controllerOrBus, int unit,
virDomainDiskDefPtr *def);
int virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def);
int virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
virDomainChrDefPtr *def);
int virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port,
virDomainChrDefPtr *def);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Domain XML -> VMX
*/
char *virVMXFormatConfig(virVMXContext *ctx, virCapsPtr caps,
virDomainDefPtr def, int virtualHW_version);
int virVMXFormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer);
int virVMXFormatHardDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer);
int virVMXFormatCDROM(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer);
int virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer, bool floppy_present[2]);
int virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
virBufferPtr buffer);
int virVMXFormatSerial(virVMXContext *ctx, virDomainChrDefPtr def,
virBufferPtr buffer);
int virVMXFormatParallel(virVMXContext *ctx, virDomainChrDefPtr def,
virBufferPtr buffer);
#endif /* __VIR_VMX_H__ */

View File

@ -91,7 +91,11 @@ check_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuhelptest
endif
if WITH_ESX
check_PROGRAMS += esxutilstest vmx2xmltest xml2vmxtest
check_PROGRAMS += esxutilstest
endif
if WITH_VMX
check_PROGRAMS += vmx2xmltest xml2vmxtest
endif
if WITH_SECDRIVER_SELINUX
@ -180,7 +184,11 @@ TESTS += nwfilterxml2xmltest
endif
if WITH_ESX
TESTS += esxutilstest vmx2xmltest xml2vmxtest
TESTS += esxutilstest
endif
if WITH_VMX
TESTS += vmx2xmltest xml2vmxtest
endif
if WITH_SECDRIVER_SELINUX
@ -292,18 +300,22 @@ esxutilstest_SOURCES = \
esxutilstest.c \
testutils.c testutils.h
esxutilstest_LDADD = ../src/libvirt_driver_esx.la $(LDADDS)
else
EXTRA_DIST += esxutilstest.c
endif
if WITH_VMX
vmx2xmltest_SOURCES = \
vmx2xmltest.c \
testutils.c testutils.h
vmx2xmltest_LDADD = ../src/libvirt_driver_esx.la $(LDADDS)
vmx2xmltest_LDADD = ../src/libvirt_vmx.la $(LDADDS)
xml2vmxtest_SOURCES = \
xml2vmxtest.c \
testutils.c testutils.h
xml2vmxtest_LDADD = ../src/libvirt_driver_esx.la $(LDADDS)
xml2vmxtest_LDADD = ../src/libvirt_vmx.la $(LDADDS)
else
EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c
EXTRA_DIST += vmx2xmltest.c xml2vmxtest.c
endif
networkxml2xmltest_SOURCES = \

View File

@ -10,6 +10,7 @@
# include "memory.h"
# include "testutils.h"
# include "util.h"
# include "vmx/vmx.h"
# include "esx/esx_util.h"
# include "esx/esx_vi_types.h"
@ -303,8 +304,8 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
for (i = 0; i < ARRAY_CARDINALITY(windows1252ToUTF8); ++i) {
VIR_FREE(utf8);
utf8 = esxUtil_ConvertToUTF8("Windows-1252",
windows1252ToUTF8[i].windows1252);
utf8 = virVMXConvertToUTF8("Windows-1252",
windows1252ToUTF8[i].windows1252);
if (utf8 == NULL) {
return -1;

View File

@ -1,6 +1,6 @@
#include <config.h>
#ifdef WITH_ESX
#ifdef WITH_VMX
# include <stdio.h>
# include <string.h>
@ -9,12 +9,12 @@
# include "internal.h"
# include "memory.h"
# include "testutils.h"
# include "esx/esx_vmx.h"
# include "vmx/vmx.h"
static char *progname = NULL;
static char *abs_srcdir = NULL;
static virCapsPtr caps = NULL;
static esxVMX_Context ctx;
static virVMXContext ctx;
# define MAX_FILE 4096
@ -68,8 +68,7 @@ testCapsInit(void)
}
static int
testCompareFiles(const char *vmx, const char *xml,
esxVI_ProductVersion productVersion)
testCompareFiles(const char *vmx, const char *xml)
{
int result = -1;
char vmxData[MAX_FILE];
@ -88,7 +87,7 @@ testCompareFiles(const char *vmx, const char *xml,
goto failure;
}
def = esxVMX_ParseConfig(&ctx, caps, vmxData, productVersion);
def = virVMXParseConfig(&ctx, caps, vmxData);
if (def == NULL) {
err = virGetLastError();
@ -121,7 +120,6 @@ testCompareFiles(const char *vmx, const char *xml,
struct testInfo {
const char *input;
const char *output;
esxVI_ProductVersion version;
};
static int
@ -136,7 +134,7 @@ testCompareHelper(const void *data)
snprintf(xml, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
info->output);
return testCompareFiles(vmx, xml, info->version);
return testCompareFiles(vmx, xml);
}
static char *
@ -206,9 +204,9 @@ mymain(int argc, char **argv)
return EXIT_FAILURE;
}
# define DO_TEST(_in, _out, _version) \
# define DO_TEST(_in, _out) \
do { \
struct testInfo info = { _in, _out, _version }; \
struct testInfo info = { _in, _out }; \
virResetLastError(); \
if (virtTestRun("VMware VMX-2-XML "_in" -> "_out, 1, \
testCompareHelper, &info) < 0) { \
@ -227,65 +225,65 @@ mymain(int argc, char **argv)
ctx.formatFileName = NULL;
ctx.autodetectSCSIControllerModel = NULL;
DO_TEST("case-insensitive-1", "case-insensitive-1", esxVI_ProductVersion_ESX35);
DO_TEST("case-insensitive-2", "case-insensitive-2", esxVI_ProductVersion_ESX35);
DO_TEST("case-insensitive-1", "case-insensitive-1");
DO_TEST("case-insensitive-2", "case-insensitive-2");
DO_TEST("minimal", "minimal", esxVI_ProductVersion_ESX35);
DO_TEST("minimal-64bit", "minimal-64bit", esxVI_ProductVersion_ESX35);
DO_TEST("minimal", "minimal");
DO_TEST("minimal-64bit", "minimal-64bit");
DO_TEST("graphics-vnc", "graphics-vnc", esxVI_ProductVersion_ESX35);
DO_TEST("graphics-vnc", "graphics-vnc");
DO_TEST("scsi-driver", "scsi-driver", esxVI_ProductVersion_ESX35);
DO_TEST("scsi-writethrough", "scsi-writethrough", esxVI_ProductVersion_ESX35);
DO_TEST("scsi-driver", "scsi-driver");
DO_TEST("scsi-writethrough", "scsi-writethrough");
DO_TEST("harddisk-scsi-file", "harddisk-scsi-file", esxVI_ProductVersion_ESX35);
DO_TEST("harddisk-ide-file", "harddisk-ide-file", esxVI_ProductVersion_ESX35);
DO_TEST("harddisk-scsi-file", "harddisk-scsi-file");
DO_TEST("harddisk-ide-file", "harddisk-ide-file");
DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-ide-file", "cdrom-ide-file", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-ide-device", "cdrom-ide-device", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-scsi-file", "cdrom-scsi-file");
DO_TEST("cdrom-scsi-device", "cdrom-scsi-device");
DO_TEST("cdrom-ide-file", "cdrom-ide-file");
DO_TEST("cdrom-ide-device", "cdrom-ide-device");
DO_TEST("floppy-file", "floppy-file", esxVI_ProductVersion_ESX35);
DO_TEST("floppy-device", "floppy-device", esxVI_ProductVersion_ESX35);
DO_TEST("floppy-file", "floppy-file");
DO_TEST("floppy-device", "floppy-device");
DO_TEST("ethernet-e1000", "ethernet-e1000", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-e1000", "ethernet-e1000");
DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2");
DO_TEST("ethernet-custom", "ethernet-custom", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-bridged", "ethernet-bridged", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-custom", "ethernet-custom");
DO_TEST("ethernet-bridged", "ethernet-bridged");
DO_TEST("ethernet-generated", "ethernet-generated", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-static", "ethernet-static", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-vpx", "ethernet-vpx", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-other", "ethernet-other", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-generated", "ethernet-generated");
DO_TEST("ethernet-static", "ethernet-static");
DO_TEST("ethernet-vpx", "ethernet-vpx");
DO_TEST("ethernet-other", "ethernet-other");
DO_TEST("serial-file", "serial-file", esxVI_ProductVersion_ESX35);
DO_TEST("serial-device", "serial-device", esxVI_ProductVersion_ESX35);
DO_TEST("serial-pipe-client-app", "serial-pipe", esxVI_ProductVersion_ESX35);
DO_TEST("serial-pipe-server-vm", "serial-pipe", esxVI_ProductVersion_ESX35);
DO_TEST("serial-pipe-client-app", "serial-pipe", esxVI_ProductVersion_ESX35);
DO_TEST("serial-pipe-server-vm", "serial-pipe", esxVI_ProductVersion_ESX35);
DO_TEST("serial-network-server", "serial-network-server", esxVI_ProductVersion_ESX41);
DO_TEST("serial-network-client", "serial-network-client", esxVI_ProductVersion_ESX41);
DO_TEST("serial-file", "serial-file");
DO_TEST("serial-device", "serial-device");
DO_TEST("serial-pipe-client-app", "serial-pipe");
DO_TEST("serial-pipe-server-vm", "serial-pipe");
DO_TEST("serial-pipe-client-app", "serial-pipe");
DO_TEST("serial-pipe-server-vm", "serial-pipe");
DO_TEST("serial-network-server", "serial-network-server");
DO_TEST("serial-network-client", "serial-network-client");
DO_TEST("parallel-file", "parallel-file", esxVI_ProductVersion_ESX35);
DO_TEST("parallel-device", "parallel-device", esxVI_ProductVersion_ESX35);
DO_TEST("parallel-file", "parallel-file");
DO_TEST("parallel-device", "parallel-device");
DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", esxVI_ProductVersion_ESX40);
DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1");
DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2");
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3");
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4");
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5");
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1");
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2");
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("annotation", "annotation", esxVI_ProductVersion_ESX35);
DO_TEST("annotation", "annotation");
DO_TEST("smbios", "smbios", esxVI_ProductVersion_ESX35);
DO_TEST("smbios", "smbios");
virCapabilitiesFree(caps);
@ -301,4 +299,4 @@ int main (void)
return 77; /* means 'test skipped' for automake */
}
#endif /* WITH_ESX */
#endif /* WITH_VMX */

View File

@ -1,6 +1,6 @@
#include <config.h>
#ifdef WITH_ESX
#ifdef WITH_VMX
# include <stdio.h>
# include <string.h>
@ -9,12 +9,12 @@
# include "internal.h"
# include "memory.h"
# include "testutils.h"
# include "esx/esx_vmx.h"
# include "vmx/vmx.h"
static char *progname = NULL;
static char *abs_srcdir = NULL;
static virCapsPtr caps = NULL;
static esxVMX_Context ctx;
static virVMXContext ctx;
# define MAX_FILE 4096
@ -68,8 +68,7 @@ testCapsInit(void)
}
static int
testCompareFiles(const char *xml, const char *vmx,
esxVI_ProductVersion productVersion)
testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
{
int result = -1;
char xmlData[MAX_FILE];
@ -93,7 +92,7 @@ testCompareFiles(const char *xml, const char *vmx,
goto failure;
}
formatted = esxVMX_FormatConfig(&ctx, caps, def, productVersion);
formatted = virVMXFormatConfig(&ctx, caps, def, virtualHW_version);
if (formatted == NULL) {
goto failure;
@ -116,7 +115,7 @@ testCompareFiles(const char *xml, const char *vmx,
struct testInfo {
const char *input;
const char *output;
esxVI_ProductVersion version;
int virtualHW_version;
};
static int
@ -131,7 +130,7 @@ testCompareHelper(const void *data)
snprintf(vmx, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
info->output);
return testCompareFiles(xml, vmx, info->version);
return testCompareFiles(xml, vmx, info->virtualHW_version);
}
static int
@ -147,17 +146,35 @@ static char *
testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
{
bool success = false;
char *copyOfDatastorePath = NULL;
char *tmp = NULL;
char *saveptr = NULL;
char *datastoreName = NULL;
char *directoryAndFileName = NULL;
char *absolutePath = NULL;
if (STRPREFIX(src, "[")) {
/* Found potential datastore path */
if (esxUtil_ParseDatastorePath(src, &datastoreName, NULL,
&directoryAndFileName) < 0) {
copyOfDatastorePath = strdup(src);
if (copyOfDatastorePath == NULL) {
goto cleanup;
}
/* Expected format: '[<datastore>] <path>' where <path> is optional */
if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||
(datastoreName = strtok_r(tmp, "]", &saveptr)) == NULL) {
goto cleanup;
}
directoryAndFileName = strtok_r(NULL, "", &saveptr);
if (directoryAndFileName == NULL) {
directoryAndFileName = (char *)"";
} else {
directoryAndFileName += strspn(directoryAndFileName, " ");
}
virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName,
directoryAndFileName);
} else if (STRPREFIX(src, "/")) {
@ -175,8 +192,7 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
VIR_FREE(absolutePath);
}
VIR_FREE(datastoreName);
VIR_FREE(directoryAndFileName);
VIR_FREE(copyOfDatastorePath);
return absolutePath;
}
@ -226,59 +242,59 @@ mymain(int argc, char **argv)
ctx.formatFileName = testFormatVMXFileName;
ctx.autodetectSCSIControllerModel = testAutodetectSCSIControllerModel;
DO_TEST("minimal", "minimal", esxVI_ProductVersion_ESX35);
DO_TEST("minimal-64bit", "minimal-64bit", esxVI_ProductVersion_ESX35);
DO_TEST("minimal", "minimal", 4);
DO_TEST("minimal-64bit", "minimal-64bit", 4);
DO_TEST("graphics-vnc", "graphics-vnc", esxVI_ProductVersion_ESX35);
DO_TEST("graphics-vnc", "graphics-vnc", 4);
DO_TEST("scsi-driver", "scsi-driver", esxVI_ProductVersion_ESX35);
DO_TEST("scsi-writethrough", "scsi-writethrough", esxVI_ProductVersion_ESX35);
DO_TEST("scsi-driver", "scsi-driver", 4);
DO_TEST("scsi-writethrough", "scsi-writethrough", 4);
DO_TEST("harddisk-scsi-file", "harddisk-scsi-file", esxVI_ProductVersion_ESX35);
DO_TEST("harddisk-ide-file", "harddisk-ide-file", esxVI_ProductVersion_ESX35);
DO_TEST("harddisk-scsi-file", "harddisk-scsi-file", 4);
DO_TEST("harddisk-ide-file", "harddisk-ide-file", 4);
DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-ide-file", "cdrom-ide-file", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-ide-device", "cdrom-ide-device", esxVI_ProductVersion_ESX35);
DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", 4);
DO_TEST("cdrom-ide-file", "cdrom-ide-file", 4);
DO_TEST("cdrom-ide-device", "cdrom-ide-device", 4);
DO_TEST("floppy-file", "floppy-file", esxVI_ProductVersion_ESX35);
DO_TEST("floppy-device", "floppy-device", esxVI_ProductVersion_ESX35);
DO_TEST("floppy-file", "floppy-file", 4);
DO_TEST("floppy-device", "floppy-device", 4);
DO_TEST("ethernet-e1000", "ethernet-e1000", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-e1000", "ethernet-e1000", 4);
DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2", 4);
DO_TEST("ethernet-custom", "ethernet-custom", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-bridged", "ethernet-bridged", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-custom", "ethernet-custom", 4);
DO_TEST("ethernet-bridged", "ethernet-bridged", 4);
DO_TEST("ethernet-generated", "ethernet-generated", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-static", "ethernet-static", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-vpx", "ethernet-vpx", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-other", "ethernet-other", esxVI_ProductVersion_ESX35);
DO_TEST("ethernet-generated", "ethernet-generated", 4);
DO_TEST("ethernet-static", "ethernet-static", 4);
DO_TEST("ethernet-vpx", "ethernet-vpx", 4);
DO_TEST("ethernet-other", "ethernet-other", 4);
DO_TEST("serial-file", "serial-file", esxVI_ProductVersion_ESX35);
DO_TEST("serial-device", "serial-device", esxVI_ProductVersion_ESX35);
DO_TEST("serial-pipe", "serial-pipe", esxVI_ProductVersion_ESX35);
DO_TEST("serial-network-server", "serial-network-server", esxVI_ProductVersion_ESX41);
DO_TEST("serial-network-client", "serial-network-client", esxVI_ProductVersion_ESX41);
DO_TEST("serial-file", "serial-file", 4);
DO_TEST("serial-device", "serial-device", 4);
DO_TEST("serial-pipe", "serial-pipe", 4);
DO_TEST("serial-network-server", "serial-network-server", 7);
DO_TEST("serial-network-client", "serial-network-client", 7);
DO_TEST("parallel-file", "parallel-file", esxVI_ProductVersion_ESX35);
DO_TEST("parallel-device", "parallel-device", esxVI_ProductVersion_ESX35);
DO_TEST("parallel-file", "parallel-file", 4);
DO_TEST("parallel-device", "parallel-device", 4);
DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", esxVI_ProductVersion_ESX35);
DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1", 4);
DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2", 4);
DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", 4);
DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", 4);
DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", 4);
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4", esxVI_ProductVersion_ESX35);
DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", 4);
DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", 4);
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("annotation", "annotation", esxVI_ProductVersion_ESX35);
DO_TEST("annotation", "annotation", 4);
DO_TEST("smbios", "smbios", esxVI_ProductVersion_ESX35);
DO_TEST("smbios", "smbios", 4);
virCapabilitiesFree(caps);
@ -294,4 +310,4 @@ int main (void)
return 77; /* means 'test skipped' for automake */
}
#endif /* WITH_ESX */
#endif /* WITH_VMX */