First version of the driver for VMWare ESX

* src/esx/esx_*.[ch]: the driver, uses a remote minimal SOAP client
  to talk to the VI services on ESX nodes.
* configure.in include/libvirt/virterror.h src/Makefile.am src/driver.h
  src/libvirt.c src/virterror.c: glue in the new driver
This commit is contained in:
Matthias Bolte 2009-07-23 22:21:08 +02:00 committed by Daniel Veillard
parent f4c3acdf35
commit e2aeee6811
18 changed files with 12567 additions and 0 deletions

View File

@ -193,6 +193,8 @@ AC_ARG_WITH([lxc],
[ --with-lxc add Linux Container support (on)],[],[with_lxc=yes])
AC_ARG_WITH([one],
[ --with-one add ONE support (on)],[],[with_one=check])
AC_ARG_WITH([esx],
[ --with-esx add ESX support (on)],[],[with_esx=yes])
AC_ARG_WITH([test],
[ --with-test add test driver support (on)],[],[with_test=yes])
AC_ARG_WITH([remote],
@ -317,6 +319,11 @@ if test "$with_one" = "yes" ; then
fi
AM_CONDITIONAL([WITH_ONE],[test "$with_one" = "yes"])
if test "$with_esx" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_ESX], 1, [whether ESX driver is enabled])
fi
AM_CONDITIONAL([WITH_ESX], [test "$with_esx" = "yes"])
if test "$with_test" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_TEST], 1, [whether Test driver is enabled])
fi
@ -1084,6 +1091,26 @@ AM_CONDITIONAL([WITH_STORAGE_DISK], [test "$with_storage_disk" = "yes"])
AC_SUBST([LIBPARTED_CFLAGS])
AC_SUBST([LIBPARTED_LIBS])
dnl
dnl check for libcurl
dnl
LIBCURL_CFLAGS=""
LIBCURL_LIBS=""
LIBCURL_REQUIRED="7.18.0"
LIBCURL_FOUND="no"
if test "$with_esx" = "yes" ; then
PKG_CHECK_MODULES(LIBCURL, libcurl >= $LIBCURL_REQUIRED, [LIBCURL_FOUND=yes], [LIBCURL_FOUND=no])
if test "$LIBCURL_FOUND" = "no"; then
AC_MSG_CHECKING(for libcurl libraries >= $LIBCURL_REQUIRED)
AC_MSG_ERROR([libcurl >= $LIBCURL_REQUIRED is required for the ESX driver])
fi
fi
AC_SUBST([LIBCURL_CFLAGS])
AC_SUBST([LIBCURL_LIBS])
dnl
dnl check for python
@ -1492,6 +1519,7 @@ AC_MSG_NOTICE([ OpenVZ: $with_openvz])
AC_MSG_NOTICE([ VBox: $with_vbox])
AC_MSG_NOTICE([ LXC: $with_lxc])
AC_MSG_NOTICE([ ONE: $with_one])
AC_MSG_NOTICE([ ESX: $with_esx])
AC_MSG_NOTICE([ Test: $with_test])
AC_MSG_NOTICE([ Remote: $with_remote])
AC_MSG_NOTICE([ Network: $with_network])
@ -1519,6 +1547,11 @@ AC_MSG_NOTICE([ dlopen: $DRIVER_MODULES_CFLAGS $DRIVER_MODULES_LIBS])
else
AC_MSG_NOTICE([ dlopen: no])
fi
if test "$with_esx" = "yes" ; then
AC_MSG_NOTICE([ libcurl: $LIBCURL_CFLAGS $LIBCURL_LIBS])
else
AC_MSG_NOTICE([ libcurl: no])
fi
AC_MSG_NOTICE([])
AC_MSG_NOTICE([Libraries])
AC_MSG_NOTICE([])

View File

@ -65,6 +65,7 @@ typedef enum {
VIR_FROM_VBOX, /* Error from VirtualBox driver */
VIR_FROM_INTERFACE, /* Error when operating on an interface */
VIR_FROM_ONE, /* Error from OpenNebula driver */
VIR_FROM_ESX, /* Error from ESX driver */
} virErrorDomain;

View File

@ -157,6 +157,14 @@ ONE_DRIVER_SOURCES = \
./opennebula/one_client.c \
./opennebula/one_client.h
ESX_DRIVER_SOURCES = \
esx/esx_driver.c esx/esx_driver.h \
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
NETWORK_DRIVER_SOURCES = \
network_driver.h network_driver.c
@ -379,6 +387,21 @@ endif
if WITH_ESX
if WITH_DRIVER_MODULES
mod_LTLIBRARIES += libvirt_driver_esx.la
else
noinst_LTLIBRARIES += libvirt_driver_esx.la
libvirt_la_LIBADD += libvirt_driver_esx.la
endif
libvirt_driver_esx_la_CFLAGS = $(LIBCURL_CFLAGS)
libvirt_driver_esx_la_LDFLAGS = $(LIBCURL_LIBS)
if WITH_DRIVER_MODULES
libvirt_driver_esx_la_LDFLAGS += -module -avoid-version
endif
libvirt_driver_esx_la_SOURCES = $(ESX_DRIVER_SOURCES)
endif
if WITH_NETWORK
if WITH_DRIVER_MODULES
mod_LTLIBRARIES += libvirt_driver_network.la
@ -489,6 +512,7 @@ EXTRA_DIST += \
$(ONE_DRIVER_SOURCES) \
$(OPENVZ_DRIVER_SOURCES) \
$(VBOX_DRIVER_SOURCES) \
$(ESX_DRIVER_SOURCES) \
$(NETWORK_DRIVER_SOURCES) \
$(INTERFACE_DRIVER_SOURCES) \
$(STORAGE_DRIVER_SOURCES) \

View File

@ -22,6 +22,7 @@ typedef enum {
VIR_DRV_UML = 7,
VIR_DRV_VBOX = 8,
VIR_DRV_ONE = 9,
VIR_DRV_ESX = 10,
} virDrvNo;

2861
src/esx/esx_driver.c Normal file

File diff suppressed because it is too large Load Diff

29
src/esx/esx_driver.h Normal file
View File

@ -0,0 +1,29 @@
/*
* esx_driver.h: core driver methods for managing VMware ESX hosts
*
* Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
* Copyright (C) 2009 Maximilian Wilhelm <max@rfc2324.org>
*
* 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_DRIVER_H__
#define __ESX_DRIVER_H__
int esxRegister(void);
#endif /* __ESX_DRIVER_H__ */

488
src/esx/esx_util.c Normal file
View File

@ -0,0 +1,488 @@
/*
* esx_util.c: utility methods for the VMware ESX driver
*
* Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
* Copyright (C) 2009 Maximilian Wilhelm <max@rfc2324.org>
*
* 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
*
*/
#include <config.h>
#include <netdb.h>
#include "internal.h"
#include "virterror_internal.h"
#include "datatypes.h"
#include "qparams.h"
#include "util.h"
#include "memory.h"
#include "logging.h"
#include "uuid.h"
#include "esx_util.h"
#define VIR_FROM_THIS VIR_FROM_ESX
#define ESX_ERROR(conn, code, fmt...) \
virReportErrorHelper (conn, VIR_FROM_ESX, code, __FILE__, __FUNCTION__, \
__LINE__, fmt)
char *
esxUtil_RequestUsername(virConnectAuthPtr auth, const char *default_username,
const char *server)
{
unsigned int ncred;
virConnectCredential cred;
char *prompt = NULL;
memset(&cred, 0, sizeof(virConnectCredential));
if (virAsprintf(&prompt, "Enter username for %s [%s]", server,
default_username) < 0) {
return NULL;
}
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) {
continue;
}
cred.type = VIR_CRED_AUTHNAME;
cred.prompt = prompt;
cred.challenge = NULL;
cred.defresult = default_username;
cred.result = NULL;
cred.resultlen = 0;
if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
VIR_FREE(cred.result);
}
break;
}
VIR_FREE(prompt);
return cred.result;
}
char *
esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username,
const char *server)
{
unsigned int ncred;
virConnectCredential cred;
char *prompt;
memset(&cred, 0, sizeof(virConnectCredential));
if (virAsprintf(&prompt, "Enter %s password for %s", username,
server) < 0) {
return NULL;
}
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&
auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) {
continue;
}
cred.type = auth->credtype[ncred];
cred.prompt = prompt;
cred.challenge = NULL;
cred.defresult = NULL;
cred.result = NULL;
cred.resultlen = 0;
if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
VIR_FREE(cred.result);
}
break;
}
VIR_FREE(prompt);
return cred.result;
}
int
esxUtil_ParseQuery(virConnectPtr conn, char **transport, char **vcenter)
{
int result = 0;
int i;
struct qparam_set *queryParamSet = NULL;
struct qparam *queryParam = NULL;
if (transport != NULL) {
*transport = NULL;
}
if (vcenter != NULL) {
*vcenter = NULL;
}
#ifdef HAVE_XMLURI_QUERY_RAW
queryParamSet = qparam_query_parse(conn->uri->query_raw);
#else
queryParamSet = qparam_query_parse(conn->uri->query);
#endif
if (queryParamSet == NULL) {
goto failure;
}
for (i = 0; i < queryParamSet->n; i++) {
queryParam = &queryParamSet->p[i];
if (STRCASEEQ(queryParam->name, "transport") && transport != NULL) {
*transport = strdup(queryParam->value);
if (*transport == NULL) {
virReportOOMError(conn);
goto failure;
}
if (STRNEQ(*transport, "http") && STRNEQ(*transport, "https")) {
ESX_ERROR(conn, VIR_ERR_INVALID_ARG,
"Query parameter 'transport' has unexpected value "
"'%s' (should be http|https)", *transport);
goto failure;
}
} else if (STRCASEEQ(queryParam->name, "vcenter") && vcenter != NULL) {
*vcenter = strdup(queryParam->value);
if (*vcenter == NULL) {
virReportOOMError(conn);
goto failure;
}
} else {
VIR_WARN("Ignoring unexpected query parameter '%s'",
queryParam->name);
}
}
if (transport != NULL && *transport == NULL) {
*transport = strdup("https");
if (*transport == NULL) {
virReportOOMError(conn);
goto failure;
}
}
cleanup:
if (queryParamSet != NULL) {
free_qparam_set(queryParamSet);
}
return result;
failure:
if (transport != NULL) {
VIR_FREE(*transport);
}
if (vcenter != NULL) {
VIR_FREE(*vcenter);
}
result = -1;
goto cleanup;
}
int
esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id)
{
/* Try to parse an integer from the complete string. */
if (virStrToLong_i(id_string, NULL, 10, id) == 0) {
return 0;
}
/*
* If that fails try to parse an integer from the string tail
* assuming the naming scheme Virtual Center seems to use.
*/
if (STRPREFIX(id_string, "vm-")) {
if (virStrToLong_i(id_string + 3, NULL, 10, id) == 0) {
return 0;
}
}
return -1;
}
int
esxUtil_ResolveHostname(virConnectPtr conn, const char *hostname,
char *ip_address, size_t ip_address_length)
{
struct addrinfo hints;
struct addrinfo *result = NULL;
int errcode;
memset(&hints, 0, sizeof (struct addrinfo));
hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
errcode = getaddrinfo(hostname, NULL, &hints, &result);
if (errcode != 0) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"IP address lookup for host '%s' failed: %s", hostname,
gai_strerror(errcode));
return -1;
}
if (result == NULL) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"No IP address for host '%s' found: %s", hostname,
gai_strerror(errcode));
return -1;
}
errcode = getnameinfo(result->ai_addr, result->ai_addrlen, ip_address,
ip_address_length, NULL, 0, NI_NUMERICHOST);
if (errcode != 0) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Formating IP address for host '%s' failed: %s", hostname,
gai_strerror(errcode));
freeaddrinfo(result);
return -1;
}
freeaddrinfo(result);
return 0;
}
int
esxUtil_GetConfigString(virConnectPtr conn, virConfPtr conf, const char *name,
char **string, int optional)
{
virConfValuePtr value;
*string = NULL;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
}
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Missing essential config entry '%s'", name);
return -1;
}
if (value->type != VIR_CONF_STRING) {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Config entry '%s' must be a string", name);
return -1;
}
if (value->str == NULL) {
if (optional) {
return 0;
}
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Missing essential config entry '%s'", name);
return -1;
}
*string = strdup(value->str);
if (*string == NULL) {
virReportOOMError(conn);
return -1;
}
return 0;
}
int
esxUtil_GetConfigUUID(virConnectPtr conn, virConfPtr conf, const char *name,
unsigned char *uuid, int optional)
{
virConfValuePtr value;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Missing essential config entry '%s'", name);
return -1;
}
}
if (value->type != VIR_CONF_STRING) {
ESX_ERROR(conn, 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(conn, VIR_ERR_INTERNAL_ERROR,
"Missing essential config entry '%s'", name);
return -1;
}
}
virUUIDParse(value->str, uuid);
return 0;
}
int
esxUtil_GetConfigLong(virConnectPtr conn, virConfPtr conf, const char *name,
long long *number, long long default_, int optional)
{
virConfValuePtr value;
*number = default_;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(conn, 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(conn, 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(conn, VIR_ERR_INTERNAL_ERROR,
"Config entry '%s' must represent an integer value",
name);
return -1;
}
} else {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Config entry '%s' must be a string", name);
return -1;
}
return 0;
}
int
esxUtil_GetConfigBoolean(virConnectPtr conn, virConfPtr conf,
const char *name, int *boolean, int default_,
int optional)
{
virConfValuePtr value;
*boolean = default_;
value = virConfGetValue(conf, name);
if (value == NULL) {
if (optional) {
return 0;
} else {
ESX_ERROR(conn, 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(conn, 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(conn, VIR_ERR_INTERNAL_ERROR,
"Config entry '%s' must represent a boolean value "
"(true|false)", name);
return -1;
}
} else {
ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Config entry '%s' must be a string", name);
return -1;
}
return 0;
}
int
esxUtil_EqualSuffix(const char *string, const char* suffix)
{
int difference = (int)strlen(string) - (int)strlen(suffix);
if (difference < 0) {
return -1;
} else {
return STRCASEEQ(string + difference, suffix);
}
}

60
src/esx/esx_util.h Normal file
View File

@ -0,0 +1,60 @@
/*
* esx_util.h: utility methods 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_UTIL_H__
#define __ESX_UTIL_H__
#include <libxml/tree.h>
#include "internal.h"
#include "conf.h"
char *esxUtil_RequestUsername(virConnectAuthPtr auth,
const char *default_username,
const char *server);
char *esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username,
const char *server);
int esxUtil_ParseQuery(virConnectPtr conn, char **transport, char **vcenter);
int esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id);
int esxUtil_ResolveHostname(virConnectPtr conn, const char *hostname,
char *ip_address, size_t ip_address_length);
int esxUtil_GetConfigString(virConnectPtr conn, virConfPtr conf,
const char *name, char **string, int optional);
int esxUtil_GetConfigUUID(virConnectPtr conn, virConfPtr conf, const char *name,
unsigned char *uuid, int optional);
int esxUtil_GetConfigLong(virConnectPtr conn, virConfPtr conf, const char *name,
long long *number, long long default_, int optional);
int esxUtil_GetConfigBoolean(virConnectPtr conn, virConfPtr conf,
const char *name, int *boolean, int default_,
int optional);
int esxUtil_EqualSuffix(const char *string, const char* suffix);
#endif /* __ESX_UTIL_H__ */

1868
src/esx/esx_vi.c Normal file

File diff suppressed because it is too large Load Diff

251
src/esx/esx_vi.h Normal file
View File

@ -0,0 +1,251 @@
/*
* esx_vi.h: client for the VMware VI API 2.5 to manage ESX hosts
*
* 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_VI_H__
#define __ESX_VI_H__
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <curl/curl.h>
#include "internal.h"
#include "datatypes.h"
#include "esx_vi_types.h"
typedef struct _esxVI_Context esxVI_Context;
typedef struct _esxVI_RemoteResponse esxVI_RemoteResponse;
typedef struct _esxVI_RemoteRequest esxVI_RemoteRequest;
typedef struct _esxVI_Enumeration esxVI_Enumeration;
typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
typedef struct _esxVI_List esxVI_List;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
*/
struct _esxVI_Context {
char *url;
CURL *curl_handle;
struct curl_slist *curl_headers;
virMutex curl_lock;
char *username;
char *password;
esxVI_ServiceContent *service;
esxVI_UserSession *session;
esxVI_ManagedObjectReference *datacenter;
esxVI_ManagedObjectReference *vmFolder;
esxVI_ManagedObjectReference *hostFolder;
esxVI_SelectionSpec *fullTraversalSpecList;
};
int esxVI_Context_Alloc(virConnectPtr conn, esxVI_Context **ctx);
void esxVI_Context_Free(esxVI_Context **ctx);
int esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx,
const char *url, const char *username,
const char *password);
int esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx,
const char *url, char **content);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteRequest
*/
struct _esxVI_RemoteRequest {
char *request; /* required */
char *xpathExpression; /* optional */
};
int esxVI_RemoteRequest_Alloc(virConnectPtr conn,
esxVI_RemoteRequest **remoteRequest);
void esxVI_RemoteRequest_Free(esxVI_RemoteRequest **remoteRequest);
int esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
esxVI_RemoteRequest *remoteRequest,
esxVI_RemoteResponse **remoteResponse);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteResponse
*/
struct _esxVI_RemoteResponse {
long response_code; /* required */
char *response; /* required */
xmlDocPtr document; /* optional */
xmlXPathContextPtr xpathContext; /* optional */
xmlXPathObjectPtr xpathObject; /* optional */
};
typedef int (*esxVI_RemoteResponse_DeserializeFunc) (virConnectPtr conn,
xmlNodePtr node,
void **item);
typedef int (*esxVI_RemoteResponse_DeserializeListFunc) (virConnectPtr conn,
xmlNodePtr node,
esxVI_List **list);
int esxVI_RemoteResponse_Alloc(virConnectPtr conn,
esxVI_RemoteResponse **remoteResponse);
void esxVI_RemoteResponse_Free(esxVI_RemoteResponse **remoteResponse);
int esxVI_RemoteResponse_DeserializeXPathObject
(virConnectPtr conn, esxVI_RemoteResponse *remoteResponse,
esxVI_RemoteResponse_DeserializeFunc deserializeFunc, void **item);
int esxVI_RemoteResponse_DeserializeXPathObjectList
(virConnectPtr conn, esxVI_RemoteResponse *remoteResponse,
esxVI_RemoteResponse_DeserializeListFunc deserializeListFunc,
esxVI_List **list);
int esxVI_RemoteResponse_DeserializeXPathObjectAsManagedObjectReference
(virConnectPtr conn, esxVI_RemoteResponse *remoteResponse,
esxVI_ManagedObjectReference **managedObjectReference,
const char *expectedType);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Enumeration
*/
struct _esxVI_EnumerationValue {
const char *name;
int value;
};
struct _esxVI_Enumeration {
const char *type;
esxVI_EnumerationValue values[10];
};
int esxVI_Enumeration_CastFromAnyType(virConnectPtr conn,
const esxVI_Enumeration *enumeration,
esxVI_AnyType *anyType, int *boolean);
int esxVI_Enumeration_Serialize(virConnectPtr conn,
const esxVI_Enumeration *enumeration,
int value, const char *element,
virBufferPtr output, esxVI_Boolean required);
int esxVI_Enumeration_Deserialize(virConnectPtr conn,
const esxVI_Enumeration *enumeration,
xmlNodePtr node, int *value);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* List
*/
struct _esxVI_List {
esxVI_List *_next;
};
typedef int (*esxVI_List_FreeFunc) (esxVI_List **item);
typedef int (*esxVI_List_DeepCopyFunc) (virConnectPtr conn, esxVI_List **dest,
esxVI_List *src);
typedef int (*esxVI_List_SerializeFunc) (virConnectPtr conn, esxVI_List *item,
const char *element,
virBufferPtr output,
esxVI_Boolean required);
typedef int (*esxVI_List_DeserializeFunc) (virConnectPtr conn, xmlNodePtr node,
esxVI_List **item);
int esxVI_List_Append(virConnectPtr conn, esxVI_List **list, esxVI_List *item);
int esxVI_List_DeepCopy(virConnectPtr conn, esxVI_List **destList,
esxVI_List *srcList,
esxVI_List_DeepCopyFunc deepCopyFunc,
esxVI_List_FreeFunc freeFunc);
int esxVI_List_Serialize(virConnectPtr conn, esxVI_List *list,
const char *element, virBufferPtr output,
esxVI_Boolean required,
esxVI_List_SerializeFunc serializeFunc);
int esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node,
esxVI_List **list,
esxVI_List_DeserializeFunc deserializeFunc,
esxVI_List_FreeFunc freeFunc);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Utility and Convenience Functions
*/
int
esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
int
esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
esxVI_Boolean required);
int esxVI_BuildFullTraversalSpecItem
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList,
const char *name, const char *type, const char *path,
const char *selectSetNames);
int esxVI_BuildFullTraversalSpecList
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList);
int esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx);
int esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *root,
const char *type, esxVI_String *propertyNameList,
esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList);
int esxVI_GetVirtualMachinePowerState
(virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
esxVI_VirtualMachinePowerState *powerState);
int esxVI_GetNumberOfDomainsByPowerState
(virConnectPtr conn, esxVI_Context *ctx,
esxVI_VirtualMachinePowerState powerState, esxVI_Boolean inverse);
int esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
esxVI_ObjectContent *virtualMachine,
int *id, char **name, unsigned char *uuid);
int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
const char *ip, esxVI_String *propertyNameList,
esxVI_ObjectContent **hostSystem);
int esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
const unsigned char *uuid,
esxVI_String *propertyNameList,
esxVI_ObjectContent **virtualMachine);
int esxVI_StartVirtualMachineTask(virConnectPtr conn, esxVI_Context *ctx,
const char *name, const char *request,
esxVI_ManagedObjectReference **task);
int esxVI_StartSimpleVirtualMachineTask
(virConnectPtr conn, esxVI_Context *ctx, const char *name,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task);
int esxVI_SimpleVirtualMachineMethod
(virConnectPtr conn, esxVI_Context *ctx, const char *name,
esxVI_ManagedObjectReference *virtualMachine);
int esxVI_WaitForTaskCompletion(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *task,
esxVI_TaskInfoState *finalState);
#endif /* __ESX_VI_H__ */

1315
src/esx/esx_vi_methods.c Normal file

File diff suppressed because it is too large Load Diff

125
src/esx/esx_vi_methods.h Normal file
View File

@ -0,0 +1,125 @@
/*
* esx_vi_methods.h: client for the VMware VI API 2.5 to manage ESX hosts
*
* 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_VI_METHODS_H__
#define __ESX_VI_METHODS_H__
#include "esx_vi.h"
#include "esx_vi_types.h"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Methods
*/
int esxVI_RetrieveServiceContent(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ServiceContent **serviceContent);
int esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
const char *userName, const char *password,
esxVI_UserSession **userSession);
int esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx);
int esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
const char *sessionID, const char *userName,
esxVI_Boolean *active);
int esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PropertyFilterSpec *propertyFilterSpecList,
esxVI_ObjectContent **objectContentList);
int esxVI_PowerOnVM_Task(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task);
int esxVI_PowerOffVM_Task(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task);
int esxVI_SuspendVM_Task(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task);
int esxVI_MigrateVM_Task(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference *resourcePool,
esxVI_ManagedObjectReference *hostSystem,
esxVI_ManagedObjectReference **task);
int esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineConfigSpec *spec,
esxVI_ManagedObjectReference **task);
int esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PropertyFilterSpec *propertyFilterSpec,
esxVI_Boolean partialUpdates,
esxVI_ManagedObjectReference **propertyFilter);
int esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *propertyFilter);
int esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
const char *version, esxVI_UpdateSet **updateSet);
int esxVI_RebootGuest(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine);
int esxVI_ShutdownGuest(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine);
int esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachineList,
esxVI_VirtualMachinePowerState powerState,
esxVI_String *testTypeList, // FIXME: see ValidateMigrationTestType
esxVI_ManagedObjectReference *resourcePool,
esxVI_ManagedObjectReference *hostSystem,
esxVI_Event **eventList);
int esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *datacenter,
const char *ip, esxVI_Boolean vmSearch,
esxVI_ManagedObjectReference **managedObjectReference);
int esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *datacenter,
const unsigned char *uuid, esxVI_Boolean vmSearch,
esxVI_ManagedObjectReference **managedObjectReference);
int esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *entity,
esxVI_DateTime *beginTime,
esxVI_DateTime *endTime,
esxVI_Int *intervalId,
esxVI_PerfMetricId **perfMetricIdList);
int esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_Int *counterIdList,
esxVI_PerfCounterInfo **perfCounterInfoList);
int esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PerfQuerySpec *querySpecList,
esxVI_PerfEntityMetric **perfEntityMetricList);
#endif /* __ESX_VI_METHODS_H__ */

2581
src/esx/esx_vi_types.c Normal file

File diff suppressed because it is too large Load Diff

1195
src/esx/esx_vi_types.h Normal file

File diff suppressed because it is too large Load Diff

1666
src/esx/esx_vmx.c Normal file

File diff suppressed because it is too large Load Diff

55
src/esx/esx_vmx.h Normal file
View File

@ -0,0 +1,55 @@
/*
* esx_vmx.c: VMX related methods 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 "internal.h"
#include "domain_conf.h"
virDomainDefPtr
esxVMX_ParseConfig(virConnectPtr conn, const char *vmx);
int
esxVMX_ParseSCSIController(virConnectPtr conn, virConfPtr conf,
int controller, int *present, char **virtualDev);
char *
esxVMX_IndexToDiskName(virConnectPtr conn, int idx, const char *prefix);
int
esxVMX_ParseDisk(virConnectPtr conn, virConfPtr conf, int device, int bus,
int controller, int id, const char *virtualDev,
virDomainDiskDefPtr *def);
int
esxVMX_ParseEthernet(virConnectPtr conn, virConfPtr conf, int controller,
virDomainNetDefPtr *def);
int
esxVMX_ParseSerial(virConnectPtr conn, virConfPtr conf, int port,
virDomainChrDefPtr *def);
int
esxVMX_ParseParallel(virConnectPtr conn, virConfPtr conf, int port,
virDomainChrDefPtr *def);
#endif /* __ESX_VMX_H__ */

View File

@ -58,6 +58,9 @@
#ifdef WITH_VBOX
#include "vbox/vbox_driver.h"
#endif
#ifdef WITH_ESX
#include "esx/esx_driver.h"
#endif
#endif
#define VIR_FROM_THIS VIR_FROM_NONE
@ -308,6 +311,7 @@ virInitialize(void)
virDriverLoadModule("xen");
virDriverLoadModule("openvz");
virDriverLoadModule("vbox");
virDriverLoadModule("esx");
virDriverLoadModule("remote");
#else
#ifdef WITH_TEST
@ -322,6 +326,9 @@ virInitialize(void)
#ifdef WITH_VBOX
if (vboxRegister() == -1) return -1;
#endif
#ifdef WITH_ESX
if (esxRegister() == -1) return -1;
#endif
#ifdef WITH_REMOTE
if (remoteRegister () == -1) return -1;
#endif
@ -905,6 +912,10 @@ virGetVersion(unsigned long *libVer, const char *type,
if (STRCASEEQ(type, "ONE"))
*typeVer = LIBVIR_VERSION_NUMBER;
#endif
#if WITH_ESX
if (STRCASEEQ(type, "ESX"))
*typeVer = LIBVIR_VERSION_NUMBER;
#endif
#if WITH_REMOTE
if (STRCASEEQ(type, "Remote"))
*typeVer = remoteVersion();

View File

@ -163,6 +163,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
case VIR_FROM_ONE:
dom = "ONE ";
break;
case VIR_FROM_ESX:
dom = "ESX ";
break;
}
return(dom);
}