2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
/*
|
2010-03-02 21:19:24 +00:00
|
|
|
* esx_driver.c: core driver functions for managing VMware ESX hosts
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
2010-03-03 10:22:46 +00:00
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
2010-03-02 21:19:24 +00:00
|
|
|
* Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
|
2009-07-23 20:21:08 +00:00
|
|
|
* 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 "internal.h"
|
|
|
|
#include "domain_conf.h"
|
2010-03-14 19:50:14 +00:00
|
|
|
#include "authhelper.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "uuid.h"
|
|
|
|
#include "esx_driver.h"
|
2010-01-15 15:01:02 +00:00
|
|
|
#include "esx_interface_driver.h"
|
|
|
|
#include "esx_network_driver.h"
|
|
|
|
#include "esx_storage_driver.h"
|
|
|
|
#include "esx_device_monitor.h"
|
|
|
|
#include "esx_secret_driver.h"
|
2010-04-14 23:38:50 +00:00
|
|
|
#include "esx_nwfilter_driver.h"
|
2010-01-15 15:01:02 +00:00
|
|
|
#include "esx_private.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#include "esx_vi.h"
|
|
|
|
#include "esx_vi_methods.h"
|
|
|
|
#include "esx_util.h"
|
|
|
|
#include "esx_vmx.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
|
|
|
static int esxDomainGetMaxVcpus(virDomainPtr domain);
|
|
|
|
|
2010-08-05 15:43:19 +00:00
|
|
|
typedef struct _esxVMX_Data esxVMX_Data;
|
|
|
|
|
|
|
|
struct _esxVMX_Data {
|
|
|
|
esxVI_Context *ctx;
|
2010-08-25 09:44:57 +00:00
|
|
|
char *datastorePathWithoutFileName;
|
2010-08-05 15:43:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/*
|
|
|
|
* Parse a file name from a .vmx file and convert it to datastore path format.
|
|
|
|
* A .vmx file can contain file names in various formats:
|
|
|
|
*
|
|
|
|
* - A single name referencing a file in the same directory as the .vmx file:
|
|
|
|
*
|
|
|
|
* test1.vmdk
|
|
|
|
*
|
|
|
|
* - An absolute file name referencing a file in a datastore that is mounted at
|
|
|
|
* /vmfs/volumes/<datastore>:
|
|
|
|
*
|
|
|
|
* /vmfs/volumes/b24b7a78-9d82b4f5/test1/test1.vmdk
|
|
|
|
* /vmfs/volumes/datastore1/test1/test1.vmdk
|
|
|
|
*
|
|
|
|
* The actual mount directory is /vmfs/volumes/b24b7a78-9d82b4f5, the second
|
|
|
|
* form is a symlink to it using the datastore name. This is the typical
|
|
|
|
* setup on an ESX(i) server.
|
|
|
|
*
|
|
|
|
* - With GSX installed on Windows there are also Windows style file names
|
|
|
|
* including UNC file names:
|
|
|
|
*
|
|
|
|
* C:\Virtual Machines\test1\test1.vmdk
|
|
|
|
* \\nas1\storage1\test1\test1.vmdk
|
|
|
|
*
|
|
|
|
* The datastore path format typically looks like this:
|
|
|
|
*
|
|
|
|
* [datastore1] test1/test1.vmdk
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* file name. This mechanism covers the Windows style file names too.
|
|
|
|
*
|
|
|
|
* The symlinks using the datastore name (/vmfs/volumes/datastore1) are an
|
|
|
|
* exception and need special handling. Parse the datastore name and use it
|
|
|
|
* to lookup the datastore by name to verify that it exists.
|
|
|
|
*/
|
2010-08-05 15:43:19 +00:00
|
|
|
static char *
|
2010-08-07 17:58:29 +00:00
|
|
|
esxParseVMXFileName(const char *fileName, void *opaque)
|
2010-08-05 15:43:19 +00:00
|
|
|
{
|
2010-08-07 17:58:29 +00:00
|
|
|
char *datastorePath = NULL;
|
|
|
|
esxVMX_Data *data = opaque;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_ObjectContent *datastoreList = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVI_ObjectContent *datastore = NULL;
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_DatastoreHostMount *hostMount = NULL;
|
|
|
|
char *datastoreName;
|
|
|
|
char *tmp;
|
|
|
|
char *saveptr;
|
|
|
|
char *strippedFileName = NULL;
|
|
|
|
char *copyOfFileName = NULL;
|
|
|
|
char *directoryAndFileName;
|
|
|
|
|
|
|
|
if (strchr(fileName, '/') == NULL && strchr(fileName, '\\') == NULL) {
|
|
|
|
/* Plain file name, use same directory as for the .vmx file */
|
2010-08-25 09:44:57 +00:00
|
|
|
if (virAsprintf(&datastorePath, "%s/%s",
|
|
|
|
data->datastorePathWithoutFileName, fileName) < 0) {
|
2010-08-07 17:58:29 +00:00
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"summary.name") < 0 ||
|
|
|
|
esxVI_LookupDatastoreList(data->ctx, propertyNameList,
|
|
|
|
&datastoreList) < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Search for datastore by mount path */
|
|
|
|
for (datastore = datastoreList; datastore != NULL;
|
|
|
|
datastore = datastore->_next) {
|
|
|
|
esxVI_DatastoreHostMount_Free(&hostMount);
|
|
|
|
datastoreName = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
|
|
|
|
&hostMount) < 0 ||
|
|
|
|
esxVI_GetStringValue(datastore, "summary.name", &datastoreName,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
tmp = (char *)STRSKIP(fileName, hostMount->mountInfo->path);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (tmp == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Found a match. Strip leading separators */
|
|
|
|
while (*tmp == '/' || *tmp == '\\') {
|
|
|
|
++tmp;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (esxVI_String_DeepCopyValue(&strippedFileName, tmp) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
tmp = strippedFileName;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Convert \ to / */
|
|
|
|
while (*tmp != '\0') {
|
|
|
|
if (*tmp == '\\') {
|
|
|
|
*tmp = '/';
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
++tmp;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
|
|
|
|
strippedFileName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Fallback to direct datastore name match */
|
|
|
|
if (datastorePath == NULL && STRPREFIX(fileName, "/vmfs/volumes/")) {
|
|
|
|
if (esxVI_String_DeepCopyValue(©OfFileName, fileName) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
|
|
|
|
if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
|
|
|
|
(datastoreName = strtok_r(tmp, "/", &saveptr)) == NULL ||
|
|
|
|
(directoryAndFileName = strtok_r(NULL, "", &saveptr)) == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("File name '%s' doesn't have expected format "
|
|
|
|
"'/vmfs/volumes/<datastore>/<path>'"), fileName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_ObjectContent_Free(&datastoreList);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (esxVI_LookupDatastoreByName(data->ctx, datastoreName,
|
|
|
|
NULL, &datastoreList,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (datastoreList == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("File name '%s' refers to non-existing datastore '%s'"),
|
|
|
|
fileName, datastoreName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
|
|
|
|
directoryAndFileName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
if (datastorePath == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datastore for '%s'"), fileName);
|
|
|
|
goto cleanup;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
2010-08-07 17:58:29 +00:00
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastoreList);
|
|
|
|
esxVI_DatastoreHostMount_Free(&hostMount);
|
|
|
|
VIR_FREE(strippedFileName);
|
|
|
|
VIR_FREE(copyOfFileName);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
return datastorePath;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/*
|
|
|
|
* This function does the inverse of esxParseVMXFileName. It takes an file name
|
|
|
|
* in datastore path format and converts it to a file name that can be used in
|
|
|
|
* a .vmx file.
|
|
|
|
*
|
|
|
|
* The datastore path format and the formats found in a .vmx file are described
|
|
|
|
* in the documentation of esxParseVMXFileName.
|
|
|
|
*
|
|
|
|
* Firstly parse the datastore path. Then use the datastore name to lookup the
|
|
|
|
* datastore and it's mount path. Finally concatenate the mount path, directory
|
|
|
|
* and file name to an absolute path and return it. Detect the seperator type
|
|
|
|
* based on the mount path.
|
|
|
|
*/
|
2010-08-05 15:43:19 +00:00
|
|
|
static char *
|
2010-08-07 17:58:29 +00:00
|
|
|
esxFormatVMXFileName(const char *datastorePath, void *opaque)
|
2010-08-05 15:43:19 +00:00
|
|
|
{
|
|
|
|
bool success = false;
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVMX_Data *data = opaque;
|
2010-08-05 15:43:19 +00:00
|
|
|
char *datastoreName = NULL;
|
2010-08-25 09:44:57 +00:00
|
|
|
char *directoryAndFileName = NULL;
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_ObjectContent *datastore = NULL;
|
|
|
|
esxVI_DatastoreHostMount *hostMount = NULL;
|
|
|
|
char separator = '/';
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *tmp;
|
2010-08-25 09:44:57 +00:00
|
|
|
size_t length;
|
2010-08-05 15:43:19 +00:00
|
|
|
char *absolutePath = NULL;
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Parse datastore path and lookup datastore */
|
2010-08-25 09:44:57 +00:00
|
|
|
if (esxUtil_ParseDatastorePath(datastorePath, &datastoreName, NULL,
|
|
|
|
&directoryAndFileName) < 0) {
|
2010-08-07 17:58:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, NULL, &datastore,
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
|
|
|
|
&hostMount) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect separator type */
|
|
|
|
if (strchr(hostMount->mountInfo->path, '\\') != NULL) {
|
|
|
|
separator = '\\';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip trailing separators */
|
|
|
|
length = strlen(hostMount->mountInfo->path);
|
|
|
|
|
|
|
|
while (length > 0 && hostMount->mountInfo->path[length - 1] == separator) {
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
/* Format as <mount>[/<directory>]/<file>, convert / to \ when necessary */
|
2010-08-07 17:58:29 +00:00
|
|
|
virBufferAdd(&buffer, hostMount->mountInfo->path, length);
|
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
if (separator != '/') {
|
|
|
|
tmp = directoryAndFileName;
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
while (*tmp != '\0') {
|
|
|
|
if (*tmp == '/') {
|
|
|
|
*tmp = separator;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
++tmp;
|
|
|
|
}
|
2010-08-07 17:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddChar(&buffer, separator);
|
2010-08-25 09:44:57 +00:00
|
|
|
virBufferAdd(&buffer, directoryAndFileName, -1);
|
2010-08-07 17:58:29 +00:00
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
|
|
|
virReportOOMError();
|
2010-08-05 15:43:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
absolutePath = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-08-05 15:43:19 +00:00
|
|
|
/* FIXME: Check if referenced path/file really exists */
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (! success) {
|
2010-08-07 17:58:29 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2010-08-05 15:43:19 +00:00
|
|
|
VIR_FREE(absolutePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(datastoreName);
|
2010-08-25 09:44:57 +00:00
|
|
|
VIR_FREE(directoryAndFileName);
|
2010-08-07 17:58:29 +00:00
|
|
|
esxVI_ObjectContent_Free(&datastore);
|
|
|
|
esxVI_DatastoreHostMount_Free(&hostMount);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
return absolutePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxAutodetectSCSIControllerModel(virDomainDiskDefPtr def, int *model,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVMX_Data *data = opaque;
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_FileInfo *fileInfo = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVI_VmDiskFileInfo *vmDiskFileInfo = NULL;
|
|
|
|
|
|
|
|
if (def->device != VIR_DOMAIN_DISK_DEVICE_DISK ||
|
|
|
|
def->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
|
|
|
|
def->type != VIR_DOMAIN_DISK_TYPE_FILE ||
|
|
|
|
def->src == NULL ||
|
|
|
|
! STRPREFIX(def->src, "[")) {
|
|
|
|
/*
|
|
|
|
* This isn't a file-based SCSI disk device with a datastore related
|
|
|
|
* source path => do nothing.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
if (esxVI_LookupFileInfoByDatastorePath(data->ctx, def->src,
|
|
|
|
false, &fileInfo,
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-08-05 15:43:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
vmDiskFileInfo = esxVI_VmDiskFileInfo_DynamicCast(fileInfo);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
if (vmDiskFileInfo == NULL || vmDiskFileInfo->controllerType == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not lookup controller model for '%s'"), def->src);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualBusLogicController")) {
|
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_BUSLOGIC;
|
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualLsiLogicController")) {
|
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_LSILOGIC;
|
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualLsiLogicSASController")) {
|
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_LSISAS1068;
|
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"ParaVirtualSCSIController")) {
|
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_VMPVSCSI;
|
|
|
|
} else {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Found unexpected controller model '%s' for disk '%s'"),
|
|
|
|
vmDiskFileInfo->controllerType, def->src);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_FileInfo_Free(&fileInfo);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
static esxVI_Boolean
|
2010-01-15 22:05:26 +00:00
|
|
|
esxSupportsLongMode(esxPrivate *priv)
|
2009-09-23 12:29:39 +00:00
|
|
|
{
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_HostCpuIdInfo *hostCpuIdInfoList = NULL;
|
|
|
|
esxVI_HostCpuIdInfo *hostCpuIdInfo = NULL;
|
2010-04-13 22:03:12 +00:00
|
|
|
esxVI_ParsedHostCpuIdInfo parsedHostCpuIdInfo;
|
2009-09-23 12:29:39 +00:00
|
|
|
char edxLongModeBit = '?';
|
|
|
|
|
|
|
|
if (priv->supportsLongMode != esxVI_Boolean_Undefined) {
|
|
|
|
return priv->supportsLongMode;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return esxVI_Boolean_Undefined;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-09-23 12:29:39 +00:00
|
|
|
"hardware.cpuFeature") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
|
|
|
|
if (esxVI_HostCpuIdInfo_CastListFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, &hostCpuIdInfoList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo != NULL;
|
|
|
|
hostCpuIdInfo = hostCpuIdInfo->_next) {
|
|
|
|
if (hostCpuIdInfo->level->value == -2147483647) { /* 0x80000001 */
|
2010-04-13 22:03:12 +00:00
|
|
|
if (esxVI_ParseHostCpuIdInfo(&parsedHostCpuIdInfo,
|
|
|
|
hostCpuIdInfo) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 22:03:12 +00:00
|
|
|
edxLongModeBit = parsedHostCpuIdInfo.edx[29];
|
2009-09-23 12:29:39 +00:00
|
|
|
|
|
|
|
if (edxLongModeBit == '1') {
|
|
|
|
priv->supportsLongMode = esxVI_Boolean_True;
|
|
|
|
} else if (edxLongModeBit == '0') {
|
|
|
|
priv->supportsLongMode = esxVI_Boolean_False;
|
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Bit 29 (Long Mode) of HostSystem property "
|
|
|
|
"'hardware.cpuFeature[].edx' with value '%s' "
|
|
|
|
"has unexpected value '%c', expecting '0' "
|
|
|
|
"or '1'"), hostCpuIdInfo->edx, edxLongModeBit);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
/*
|
|
|
|
* If we goto cleanup in case of an error then priv->supportsLongMode
|
|
|
|
* is still esxVI_Boolean_Undefined, therefore we don't need to set it.
|
|
|
|
*/
|
2009-09-23 12:29:39 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_HostCpuIdInfo_Free(&hostCpuIdInfoList);
|
|
|
|
|
|
|
|
return priv->supportsLongMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-26 11:05:49 +00:00
|
|
|
static int
|
|
|
|
esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-26 11:05:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"hardware.systemInfo.uuid") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-26 11:05:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "hardware.systemInfo.uuid")) {
|
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
|
|
|
esxVI_Type_String) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(dynamicProperty->val->string) > 0) {
|
|
|
|
if (virUUIDParse(dynamicProperty->val->string, uuid) < 0) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse UUID from string '%s'"),
|
|
|
|
dynamicProperty->val->string);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* HostSystem has an empty UUID */
|
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
static virCapsPtr
|
2010-01-15 22:05:26 +00:00
|
|
|
esxCapsInit(esxPrivate *priv)
|
2009-09-04 16:25:27 +00:00
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Boolean supportsLongMode = esxSupportsLongMode(priv);
|
2009-09-04 16:25:27 +00:00
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
virCapsGuestPtr guest = NULL;
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
if (supportsLongMode == esxVI_Boolean_Undefined) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (supportsLongMode == esxVI_Boolean_True) {
|
|
|
|
caps = virCapabilitiesNew("x86_64", 1, 1);
|
|
|
|
} else {
|
|
|
|
caps = virCapabilitiesNew("i686", 1, 1);
|
|
|
|
}
|
2009-09-04 16:25:27 +00:00
|
|
|
|
|
|
|
if (caps == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-09-04 16:25:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-02 22:58:24 +00:00
|
|
|
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
|
2010-07-31 21:57:42 +00:00
|
|
|
virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr");
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2010-06-15 22:17:34 +00:00
|
|
|
caps->hasWideScsiBus = true;
|
|
|
|
|
2010-05-26 11:05:49 +00:00
|
|
|
if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
/* i686 */
|
|
|
|
guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32, NULL, NULL, 0,
|
|
|
|
NULL);
|
2009-09-04 16:25:27 +00:00
|
|
|
|
|
|
|
if (guest == NULL) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
/* x86_64 */
|
|
|
|
if (supportsLongMode == esxVI_Boolean_True) {
|
|
|
|
guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64, NULL, NULL,
|
|
|
|
0, NULL);
|
|
|
|
|
|
|
|
if (guest == NULL) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
return caps;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
virCapabilitiesFree(caps);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
static int
|
|
|
|
esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
|
|
|
|
const char *hostname, int port,
|
|
|
|
const char *predefinedUsername,
|
2010-07-30 20:08:35 +00:00
|
|
|
esxUtil_ParsedUri *parsedUri,
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_ProductVersion expectedProductVersion,
|
|
|
|
char **vCenterIpAddress)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char ipAddress[NI_MAXHOST] = "";
|
|
|
|
char *username = NULL;
|
|
|
|
char *password = NULL;
|
|
|
|
char *url = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_Boolean inMaintenanceMode = esxVI_Boolean_Undefined;
|
|
|
|
|
|
|
|
if (vCenterIpAddress == NULL || *vCenterIpAddress != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (predefinedUsername != NULL) {
|
|
|
|
username = strdup(predefinedUsername);
|
|
|
|
|
|
|
|
if (username == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
username = virRequestUsername(auth, "root", hostname);
|
|
|
|
|
|
|
|
if (username == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
password = virRequestPassword(auth, username, hostname);
|
|
|
|
|
|
|
|
if (password == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
|
|
|
|
port) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_Context_Alloc(&priv->host) < 0 ||
|
|
|
|
esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
|
2010-07-31 21:57:42 +00:00
|
|
|
parsedUri) < 0 ||
|
|
|
|
esxVI_Context_LookupObjectsByPath(priv->host, parsedUri) < 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedProductVersion == esxVI_ProductVersion_ESX) {
|
|
|
|
if (priv->host->productVersion != esxVI_ProductVersion_ESX35 &&
|
2010-07-21 23:19:04 +00:00
|
|
|
priv->host->productVersion != esxVI_ProductVersion_ESX40 &&
|
|
|
|
priv->host->productVersion != esxVI_ProductVersion_ESX41 &&
|
|
|
|
priv->host->productVersion != esxVI_ProductVersion_ESX4x) {
|
2010-07-18 15:27:05 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-07-21 23:19:04 +00:00
|
|
|
_("%s is neither an ESX 3.5 host nor an ESX 4.x host"),
|
2010-07-18 15:27:05 +00:00
|
|
|
hostname);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else { /* GSX */
|
|
|
|
if (priv->host->productVersion != esxVI_ProductVersion_GSX20) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s isn't a GSX 2.0 host"), hostname);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query the host for maintenance mode and vCenter IP address */
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"runtime.inMaintenanceMode\0"
|
|
|
|
"summary.managementServerIp\0") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->host, propertyNameList,
|
|
|
|
&hostSystem) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_GetBoolean(hostSystem, "runtime.inMaintenanceMode",
|
|
|
|
&inMaintenanceMode,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetStringValue(hostSystem, "summary.managementServerIp",
|
|
|
|
vCenterIpAddress,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Warn if host is in maintenance mode */
|
|
|
|
if (inMaintenanceMode == esxVI_Boolean_True) {
|
|
|
|
VIR_WARN0("The server is in maintenance mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*vCenterIpAddress != NULL) {
|
|
|
|
*vCenterIpAddress = strdup(*vCenterIpAddress);
|
|
|
|
|
|
|
|
if (*vCenterIpAddress == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(password);
|
|
|
|
VIR_FREE(username);
|
|
|
|
VIR_FREE(url);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
|
|
|
|
const char *hostname, int port,
|
|
|
|
const char *predefinedUsername,
|
2010-07-31 21:57:42 +00:00
|
|
|
const char *hostSystemIpAddress,
|
2010-07-30 20:08:35 +00:00
|
|
|
esxUtil_ParsedUri *parsedUri)
|
2010-07-18 15:27:05 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char ipAddress[NI_MAXHOST] = "";
|
|
|
|
char *username = NULL;
|
|
|
|
char *password = NULL;
|
|
|
|
char *url = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (hostSystemIpAddress == NULL &&
|
|
|
|
(parsedUri->path_datacenter == NULL ||
|
|
|
|
parsedUri->path_computeResource == NULL)) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Path has to specify the datacenter and compute resource"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (predefinedUsername != NULL) {
|
|
|
|
username = strdup(predefinedUsername);
|
|
|
|
|
|
|
|
if (username == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
username = virRequestUsername(auth, "administrator", hostname);
|
|
|
|
|
|
|
|
if (username == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
password = virRequestPassword(auth, username, hostname);
|
|
|
|
|
|
|
|
if (password == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
|
|
|
|
port) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
|
|
|
|
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
|
2010-07-30 20:08:35 +00:00
|
|
|
password, parsedUri) < 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->vCenter->productVersion != esxVI_ProductVersion_VPX25 &&
|
2010-07-21 23:19:04 +00:00
|
|
|
priv->vCenter->productVersion != esxVI_ProductVersion_VPX40 &&
|
|
|
|
priv->vCenter->productVersion != esxVI_ProductVersion_VPX41 &&
|
|
|
|
priv->vCenter->productVersion != esxVI_ProductVersion_VPX4x) {
|
2010-07-18 15:27:05 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s is neither a vCenter 2.5 server nor a vCenter "
|
2010-07-21 23:19:04 +00:00
|
|
|
"4.x server"), hostname);
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (hostSystemIpAddress != NULL) {
|
|
|
|
if (esxVI_Context_LookupObjectsByHostSystemIp(priv->vCenter,
|
|
|
|
hostSystemIpAddress) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (esxVI_Context_LookupObjectsByPath(priv->vCenter, parsedUri) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(password);
|
|
|
|
VIR_FREE(username);
|
|
|
|
VIR_FREE(url);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
/*
|
2010-07-31 21:57:42 +00:00
|
|
|
* URI format: {vpx|esx|gsx}://[<username>@]<hostname>[:<port>]/[<path>][?<query parameter> ...]
|
|
|
|
* <path> = <datacenter>/<computeresource>[/<hostsystem>]
|
2009-07-27 12:18:25 +00:00
|
|
|
*
|
2009-08-05 08:23:59 +00:00
|
|
|
* If no port is specified the default port is set dependent on the scheme and
|
|
|
|
* transport parameter:
|
2010-07-18 15:27:05 +00:00
|
|
|
* - vpx+http 80
|
|
|
|
* - vpx+https 443
|
2009-08-05 08:23:59 +00:00
|
|
|
* - esx+http 80
|
2009-11-13 21:43:10 +00:00
|
|
|
* - esx+https 443
|
2009-08-05 08:23:59 +00:00
|
|
|
* - gsx+http 8222
|
|
|
|
* - gsx+https 8333
|
|
|
|
*
|
2010-07-31 21:57:42 +00:00
|
|
|
* For a vpx:// connection <path> references a host managed by the vCenter.
|
|
|
|
* In case the host is part of a cluster then <computeresource> is the cluster
|
|
|
|
* name. Otherwise <computeresource> and <hostsystem> are equal and the later
|
|
|
|
* can be omitted.
|
|
|
|
*
|
2009-11-18 23:08:13 +00:00
|
|
|
* Optional query parameters:
|
|
|
|
* - transport={http|https}
|
2010-07-18 15:27:05 +00:00
|
|
|
* - vcenter={<vcenter>|*} only useful for an esx:// connection
|
2009-11-18 23:08:13 +00:00
|
|
|
* - no_verify={0|1}
|
|
|
|
* - auto_answer={0|1}
|
2010-06-03 21:09:12 +00:00
|
|
|
* - proxy=[{http|socks|socks4|socks4a|socks5}://]<hostname>[:<port>]
|
2009-11-18 23:08:13 +00:00
|
|
|
*
|
2009-07-27 12:18:25 +00:00
|
|
|
* If no transport parameter is specified https is used.
|
|
|
|
*
|
|
|
|
* The vcenter parameter is only necessary for migration, because the vCenter
|
2009-11-18 23:08:13 +00:00
|
|
|
* server is in charge to initiate a migration between two ESX hosts. The
|
2010-07-31 21:57:42 +00:00
|
|
|
* vcenter parameter can be set to an explicitly hostname or to *. If set to *,
|
2009-11-18 23:08:13 +00:00
|
|
|
* the driver will check if the ESX host is managed by a vCenter and connect to
|
|
|
|
* it. If the ESX host is not managed by a vCenter an error is reported.
|
2009-07-27 12:18:25 +00:00
|
|
|
*
|
|
|
|
* If the no_verify parameter is set to 1, this disables libcurl client checks
|
2009-08-05 08:23:59 +00:00
|
|
|
* of the server's certificate. The default value it 0.
|
2009-11-15 21:22:47 +00:00
|
|
|
*
|
|
|
|
* If the auto_answer parameter is set to 1, the driver will respond to all
|
|
|
|
* virtual machine questions with the default answer, otherwise virtual machine
|
|
|
|
* questions will be reported as errors. The default value it 0.
|
2010-06-03 21:09:12 +00:00
|
|
|
*
|
|
|
|
* The proxy parameter allows to specify a proxy for to be used by libcurl.
|
|
|
|
* The default for the optional <type> part is http and socks is synonymous for
|
|
|
|
* socks5. The optional <port> part allows to override the default port 1080.
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
static virDrvOpenStatus
|
|
|
|
esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxPrivate *priv = NULL;
|
2010-07-30 20:08:35 +00:00
|
|
|
esxUtil_ParsedUri *parsedUri = NULL;
|
2010-07-18 15:27:05 +00:00
|
|
|
char *potentialVCenterIpAddress = NULL;
|
2009-09-23 12:09:44 +00:00
|
|
|
char vCenterIpAddress[NI_MAXHOST] = "";
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/* Decline if the URI is NULL or the scheme is not one of {vpx|esx|gsx} */
|
2009-07-23 20:21:08 +00:00
|
|
|
if (conn->uri == NULL || conn->uri->scheme == NULL ||
|
2010-07-18 15:27:05 +00:00
|
|
|
(STRCASENEQ(conn->uri->scheme, "vpx") &&
|
|
|
|
STRCASENEQ(conn->uri->scheme, "esx") &&
|
2009-08-05 08:23:59 +00:00
|
|
|
STRCASENEQ(conn->uri->scheme, "gsx"))) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
}
|
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
/* Decline URIs without server part, or missing auth */
|
|
|
|
if (conn->uri->server == NULL || auth == NULL || auth->cb == NULL) {
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate per-connection private data */
|
|
|
|
if (VIR_ALLOC(priv) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 20:08:35 +00:00
|
|
|
if (esxUtil_ParseUri(&parsedUri, conn->uri) < 0) {
|
2010-06-03 18:04:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-07-30 20:08:35 +00:00
|
|
|
priv->transport = parsedUri->transport;
|
|
|
|
parsedUri->transport = NULL;
|
2010-06-03 18:04:15 +00:00
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
priv->maxVcpus = -1;
|
|
|
|
priv->supportsVMotion = esxVI_Boolean_Undefined;
|
2009-09-23 12:29:39 +00:00
|
|
|
priv->supportsLongMode = esxVI_Boolean_Undefined;
|
2010-07-30 20:08:35 +00:00
|
|
|
priv->autoAnswer = parsedUri->autoAnswer ? esxVI_Boolean_True
|
|
|
|
: esxVI_Boolean_False;
|
2009-07-23 20:21:08 +00:00
|
|
|
priv->usedCpuTimeCounterId = -1;
|
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
/*
|
|
|
|
* Set the port dependent on the transport protocol if no port is
|
|
|
|
* specified. This allows us to rely on the port parameter being
|
|
|
|
* correctly set when building URIs later on, without the need to
|
|
|
|
* distinguish between the situations port == 0 and port != 0
|
|
|
|
*/
|
|
|
|
if (conn->uri->port == 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
if (STRCASEEQ(conn->uri->scheme, "vpx") ||
|
|
|
|
STRCASEEQ(conn->uri->scheme, "esx")) {
|
2009-09-23 13:00:02 +00:00
|
|
|
if (STRCASEEQ(priv->transport, "https")) {
|
|
|
|
conn->uri->port = 443;
|
|
|
|
} else {
|
|
|
|
conn->uri->port = 80;
|
|
|
|
}
|
|
|
|
} else { /* GSX */
|
|
|
|
if (STRCASEEQ(priv->transport, "https")) {
|
|
|
|
conn->uri->port = 8333;
|
|
|
|
} else {
|
|
|
|
conn->uri->port = 8222;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2009-09-23 13:00:02 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (STRCASEEQ(conn->uri->scheme, "esx") ||
|
|
|
|
STRCASEEQ(conn->uri->scheme, "gsx")) {
|
|
|
|
/* Connect to host */
|
|
|
|
if (esxConnectToHost(priv, auth, conn->uri->server, conn->uri->port,
|
2010-07-30 20:08:35 +00:00
|
|
|
conn->uri->user, parsedUri,
|
2010-07-18 15:27:05 +00:00
|
|
|
STRCASEEQ(conn->uri->scheme, "esx")
|
|
|
|
? esxVI_ProductVersion_ESX
|
|
|
|
: esxVI_ProductVersion_GSX,
|
|
|
|
&potentialVCenterIpAddress) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2010-01-05 01:29:52 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/* Connect to vCenter */
|
2010-07-30 20:08:35 +00:00
|
|
|
if (parsedUri->vCenter != NULL) {
|
|
|
|
if (STREQ(parsedUri->vCenter, "*")) {
|
2010-07-18 15:27:05 +00:00
|
|
|
if (potentialVCenterIpAddress == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("This host is not managed by a vCenter"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-18 23:08:13 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (virStrcpyStatic(vCenterIpAddress,
|
|
|
|
potentialVCenterIpAddress) == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("vCenter IP address %s too big for destination"),
|
|
|
|
potentialVCenterIpAddress);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
2010-07-30 20:08:35 +00:00
|
|
|
if (esxUtil_ResolveHostname(parsedUri->vCenter,
|
2010-07-18 15:27:05 +00:00
|
|
|
vCenterIpAddress, NI_MAXHOST) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-11-18 23:08:13 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (potentialVCenterIpAddress != NULL &&
|
|
|
|
STRNEQ(vCenterIpAddress, potentialVCenterIpAddress)) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("This host is managed by a vCenter with IP "
|
|
|
|
"address %s, but a mismachting vCenter '%s' "
|
|
|
|
"(%s) has been specified"),
|
2010-07-30 20:08:35 +00:00
|
|
|
potentialVCenterIpAddress, parsedUri->vCenter,
|
2009-11-18 23:08:13 +00:00
|
|
|
vCenterIpAddress);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-18 23:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxConnectToVCenter(priv, auth, vCenterIpAddress,
|
2010-07-31 21:57:42 +00:00
|
|
|
conn->uri->port, NULL,
|
|
|
|
priv->host->ipAddress, parsedUri) < 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->primary = priv->host;
|
|
|
|
} else { /* VPX */
|
|
|
|
/* Connect to vCenter */
|
|
|
|
if (esxConnectToVCenter(priv, auth, conn->uri->server, conn->uri->port,
|
2010-07-31 21:57:42 +00:00
|
|
|
conn->uri->user, NULL, parsedUri) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->primary = priv->vCenter;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn->privateData = priv;
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
/* Setup capabilities */
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->caps = esxCapsInit(priv);
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
if (priv->caps == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = VIR_DRV_OPEN_SUCCESS;
|
2009-11-18 23:08:13 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
cleanup:
|
|
|
|
if (result == VIR_DRV_OPEN_ERROR && priv != NULL) {
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Context_Free(&priv->host);
|
2009-08-06 13:15:45 +00:00
|
|
|
esxVI_Context_Free(&priv->vCenter);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
virCapabilitiesFree(priv->caps);
|
|
|
|
|
2009-08-06 13:09:40 +00:00
|
|
|
VIR_FREE(priv->transport);
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(priv);
|
|
|
|
}
|
|
|
|
|
2010-07-30 20:08:35 +00:00
|
|
|
esxUtil_FreeParsedUri(&parsedUri);
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_FREE(potentialVCenterIpAddress);
|
2009-11-18 23:08:13 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return result;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxClose(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-03-03 10:22:46 +00:00
|
|
|
int result = 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (priv->host != NULL) {
|
|
|
|
if (esxVI_EnsureSession(priv->host) < 0 ||
|
|
|
|
esxVI_Logout(priv->host) < 0) {
|
|
|
|
result = -1;
|
|
|
|
}
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_Context_Free(&priv->host);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
if (priv->vCenter != NULL) {
|
2010-03-03 10:22:46 +00:00
|
|
|
if (esxVI_EnsureSession(priv->vCenter) < 0 ||
|
|
|
|
esxVI_Logout(priv->vCenter) < 0) {
|
|
|
|
result = -1;
|
|
|
|
}
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2009-09-23 13:00:02 +00:00
|
|
|
esxVI_Context_Free(&priv->vCenter);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
virCapabilitiesFree(priv->caps);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(priv->transport);
|
|
|
|
VIR_FREE(priv);
|
|
|
|
|
|
|
|
conn->privateData = NULL;
|
|
|
|
|
2010-03-03 10:22:46 +00:00
|
|
|
return result;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static esxVI_Boolean
|
2010-01-15 22:05:26 +00:00
|
|
|
esxSupportsVMotion(esxPrivate *priv)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (priv->supportsVMotion != esxVI_Boolean_Undefined) {
|
|
|
|
return priv->supportsVMotion;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return esxVI_Boolean_Undefined;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"capability.vmotionSupported") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
|
|
|
|
&priv->supportsVMotion,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
/*
|
|
|
|
* If we goto cleanup in case of an error then priv->supportsVMotion is
|
|
|
|
* still esxVI_Boolean_Undefined, therefore we don't need to set it.
|
|
|
|
*/
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
return priv->supportsVMotion;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxSupportsFeature(virConnectPtr conn, int feature)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-08-06 13:15:45 +00:00
|
|
|
esxVI_Boolean supportsVMotion = esxVI_Boolean_Undefined;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
switch (feature) {
|
|
|
|
case VIR_DRV_FEATURE_MIGRATION_V1:
|
2010-01-15 22:05:26 +00:00
|
|
|
supportsVMotion = esxSupportsVMotion(priv);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (supportsVMotion == esxVI_Boolean_Undefined) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
/* Migration is only possible via a vCenter and if VMotion is enabled */
|
|
|
|
return priv->vCenter != NULL &&
|
|
|
|
supportsVMotion == esxVI_Boolean_True ? 1 : 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
esxGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return "ESX";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxGetVersion(virConnectPtr conn, unsigned long *version)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (virParseVersionString(priv->primary->service->about->version,
|
2010-03-30 14:15:13 +00:00
|
|
|
version) < 0) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not parse version number from '%s'"),
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->primary->service->about->version);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-03-30 14:15:13 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
esxGetHostname(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
const char *hostName = NULL;
|
|
|
|
const char *domainName = NULL;
|
|
|
|
char *complete = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList
|
2010-01-15 22:05:26 +00:00
|
|
|
(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"config.network.dnsConfig.hostName\0"
|
|
|
|
"config.network.dnsConfig.domainName\0") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name,
|
|
|
|
"config.network.dnsConfig.hostName")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_String) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hostName = dynamicProperty->val->string;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.network.dnsConfig.domainName")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_String) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
domainName = dynamicProperty->val->string;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:37:26 +00:00
|
|
|
if (hostName == NULL || strlen(hostName) < 1) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or empty 'hostName' property"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 12:37:26 +00:00
|
|
|
if (domainName == NULL || strlen(domainName) < 1) {
|
2010-01-16 00:08:27 +00:00
|
|
|
complete = strdup(hostName);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-16 00:08:27 +00:00
|
|
|
if (complete == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-01-16 00:08:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-01-16 00:08:27 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
/*
|
|
|
|
* If we goto cleanup in case of an error then complete is still NULL,
|
|
|
|
* either strdup returned NULL or virAsprintf failed. When virAsprintf
|
|
|
|
* fails it guarantees setting complete to NULL
|
|
|
|
*/
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
int64_t cpuInfo_hz = 0;
|
|
|
|
int16_t cpuInfo_numCpuCores = 0;
|
|
|
|
int16_t cpuInfo_numCpuPackages = 0;
|
|
|
|
int16_t cpuInfo_numCpuThreads = 0;
|
|
|
|
int64_t memorySize = 0;
|
|
|
|
int32_t numaInfo_numNodes = 0;
|
|
|
|
char *ptr = NULL;
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
memset(nodeinfo, 0, sizeof (*nodeinfo));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"hardware.cpuInfo.hz\0"
|
|
|
|
"hardware.cpuInfo.numCpuCores\0"
|
|
|
|
"hardware.cpuInfo.numCpuPackages\0"
|
|
|
|
"hardware.cpuInfo.numCpuThreads\0"
|
|
|
|
"hardware.memorySize\0"
|
|
|
|
"hardware.numaInfo.numNodes\0"
|
|
|
|
"summary.hardware.cpuModel\0") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Long) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cpuInfo_hz = dynamicProperty->val->int64;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"hardware.cpuInfo.numCpuCores")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Short) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cpuInfo_numCpuCores = dynamicProperty->val->int16;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"hardware.cpuInfo.numCpuPackages")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Short) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cpuInfo_numCpuPackages = dynamicProperty->val->int16;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"hardware.cpuInfo.numCpuThreads")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Short) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cpuInfo_numCpuThreads = dynamicProperty->val->int16;
|
|
|
|
} else if (STREQ(dynamicProperty->name, "hardware.memorySize")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Long) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memorySize = dynamicProperty->val->int64;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"hardware.numaInfo.numNodes")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Int) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
numaInfo_numNodes = dynamicProperty->val->int32;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"summary.hardware.cpuModel")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_String) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = dynamicProperty->val->string;
|
|
|
|
|
|
|
|
/* Strip the string to fit more relevant information in 32 chars */
|
|
|
|
while (*ptr != '\0') {
|
2009-09-23 12:37:26 +00:00
|
|
|
if (STRPREFIX(ptr, " ")) {
|
|
|
|
memmove(ptr, ptr + 1, strlen(ptr + 1) + 1);
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
2009-09-14 12:20:07 +00:00
|
|
|
} else if (STRPREFIX(ptr, "(R)") || STRPREFIX(ptr, "(C)")) {
|
2009-09-23 12:37:26 +00:00
|
|
|
memmove(ptr, ptr + 3, strlen(ptr + 3) + 1);
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
2009-09-14 12:20:07 +00:00
|
|
|
} else if (STRPREFIX(ptr, "(TM)")) {
|
|
|
|
memmove(ptr, ptr + 4, strlen(ptr + 4) + 1);
|
|
|
|
continue;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
|
2009-08-03 12:37:44 +00:00
|
|
|
if (virStrncpy(nodeinfo->model, dynamicProperty->val->string,
|
|
|
|
sizeof(nodeinfo->model) - 1,
|
|
|
|
sizeof(nodeinfo->model)) == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("CPU Model %s too long for destination"),
|
2009-08-03 12:37:44 +00:00
|
|
|
dynamicProperty->val->string);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-08-03 12:37:44 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeinfo->memory = memorySize / 1024; /* Scale from bytes to kilobytes */
|
|
|
|
nodeinfo->cpus = cpuInfo_numCpuCores;
|
2009-11-14 21:52:27 +00:00
|
|
|
nodeinfo->mhz = cpuInfo_hz / (1000 * 1000); /* Scale from hz to mhz */
|
2009-07-23 20:21:08 +00:00
|
|
|
nodeinfo->nodes = numaInfo_numNodes;
|
|
|
|
nodeinfo->sockets = cpuInfo_numCpuPackages;
|
|
|
|
nodeinfo->cores = cpuInfo_numCpuPackages > 0
|
|
|
|
? cpuInfo_numCpuCores / cpuInfo_numCpuPackages
|
|
|
|
: 0;
|
|
|
|
nodeinfo->threads = cpuInfo_numCpuCores > 0
|
|
|
|
? cpuInfo_numCpuThreads / cpuInfo_numCpuCores
|
|
|
|
: 0;
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
static char *
|
|
|
|
esxGetCapabilities(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-09-23 13:00:02 +00:00
|
|
|
char *xml = virCapabilitiesFormatXML(priv->caps);
|
2009-09-04 16:25:27 +00:00
|
|
|
|
|
|
|
if (xml == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-09-04 16:25:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static int
|
|
|
|
esxListDomains(virConnectPtr conn, int *ids, int maxids)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
bool success = false;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (ids == NULL || maxids < 0) {
|
2010-04-07 08:55:00 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (maxids == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(priv->primary, propertyNameList,
|
|
|
|
&virtualMachineList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
|
|
|
|
virtualMachine = virtualMachine->_next) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
2009-07-23 20:21:08 +00:00
|
|
|
&powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxUtil_ParseVirtualMachineIDString(virtualMachine->obj->value,
|
|
|
|
&ids[count]) < 0 ||
|
|
|
|
ids[count] <= 0) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Failed to parse positive integer from '%s'"),
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine->obj->value);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (count >= maxids) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
success = true;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return success ? count : -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxNumberOfDomains(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
return esxVI_LookupNumberOfDomainsByPowerState
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, esxVI_VirtualMachinePowerState_PoweredOn,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
esxDomainLookupByID(virConnectPtr conn, int id)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
2009-08-06 13:15:45 +00:00
|
|
|
int id_candidate = -1;
|
|
|
|
char *name_candidate = NULL;
|
|
|
|
unsigned char uuid_candidate[VIR_UUID_BUFLEN];
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainPtr domain = NULL;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-09-04 16:03:22 +00:00
|
|
|
"configStatus\0"
|
2009-07-23 20:21:08 +00:00
|
|
|
"name\0"
|
|
|
|
"runtime.powerState\0"
|
2009-09-04 16:03:22 +00:00
|
|
|
"config.uuid\0") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(priv->primary, propertyNameList,
|
|
|
|
&virtualMachineList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
|
|
|
|
virtualMachine = virtualMachine->_next) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
2009-07-23 20:21:08 +00:00
|
|
|
&powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only running/suspended domains have an ID != -1 */
|
|
|
|
if (powerState == esxVI_VirtualMachinePowerState_PoweredOff) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
VIR_FREE(name_candidate);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine,
|
2009-08-06 13:15:45 +00:00
|
|
|
&id_candidate, &name_candidate,
|
|
|
|
uuid_candidate) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (id != id_candidate) {
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
domain = virGetDomain(conn, name_candidate, uuid_candidate);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (domain == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
domain->id = id;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (domain == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
2009-08-06 13:15:45 +00:00
|
|
|
VIR_FREE(name_candidate);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
2009-11-18 00:03:31 +00:00
|
|
|
int id = -1;
|
|
|
|
char *name = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainPtr domain = NULL;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"name\0"
|
2009-11-18 00:03:31 +00:00
|
|
|
"runtime.powerState\0") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, uuid, propertyNameList,
|
2010-01-15 22:05:26 +00:00
|
|
|
&virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, NULL) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 00:03:31 +00:00
|
|
|
domain = virGetDomain(conn, name, uuid);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (domain == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-18 00:03:31 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-11-18 00:03:31 +00:00
|
|
|
/* Only running/suspended virtual machines have an ID != -1 */
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
|
|
|
domain->id = id;
|
|
|
|
} else {
|
|
|
|
domain->id = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
2009-11-18 00:03:31 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
VIR_FREE(name);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
esxDomainLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
2010-03-02 23:57:57 +00:00
|
|
|
int id = -1;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainPtr domain = NULL;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-09-04 16:03:22 +00:00
|
|
|
"configStatus\0"
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState\0"
|
2009-09-04 16:03:22 +00:00
|
|
|
"config.uuid\0") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByName(priv->primary, name, propertyNameList,
|
2010-03-02 23:57:57 +00:00
|
|
|
&virtualMachine,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
if (virtualMachine == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_NO_DOMAIN, _("No domain with name '%s'"), name);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, uuid) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
domain = virGetDomain(conn, name, uuid);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
if (domain == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
/* Only running/suspended virtual machines have an ID != -1 */
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
|
|
|
domain->id = id;
|
|
|
|
} else {
|
|
|
|
domain->id = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
2010-03-02 23:57:57 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSuspend(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, propertyNameList, &virtualMachine,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered on"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_SuspendVM_Task(priv->primary, virtualMachine->obj, &task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not suspend domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainResume(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, propertyNameList, &virtualMachine,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_Suspended) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not suspended"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_PowerOnVM_Task(priv->primary, virtualMachine->obj, NULL,
|
2010-04-13 12:25:52 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not resume domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainShutdown(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered on"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_ShutdownGuest(priv->primary, virtualMachine->obj) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered on"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_RebootGuest(priv->primary, virtualMachine->obj) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainDestroy(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-12-12 19:51:35 +00:00
|
|
|
esxVI_Context *ctx = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2009-12-12 19:51:35 +00:00
|
|
|
if (priv->vCenter != NULL) {
|
|
|
|
ctx = priv->vCenter;
|
|
|
|
} else {
|
|
|
|
ctx = priv->host;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_EnsureSession(ctx) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-01-15 22:05:26 +00:00
|
|
|
(ctx, domain->uuid, propertyNameList, &virtualMachine,
|
2009-12-12 19:51:35 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered on"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_PowerOffVM_Task(ctx, virtualMachine->obj, &task) < 0 ||
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_WaitForTaskCompletion(ctx, task, domain->uuid,
|
|
|
|
esxVI_Occurrence_RequiredItem,
|
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not destroy domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 17:50:12 +00:00
|
|
|
domain->id = -1;
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2010-01-15 22:05:26 +00:00
|
|
|
esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2009-08-06 13:07:46 +00:00
|
|
|
char *osType = strdup("hvm");
|
|
|
|
|
|
|
|
if (osType == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-08-06 13:07:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return osType;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
esxDomainGetMaxMemory(virDomainPtr domain)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
unsigned long memoryMB = 0;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"config.hardware.memoryMB") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Int) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dynamicProperty->val->int32 < 0) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Got invalid memory size %d"),
|
2009-07-23 20:21:08 +00:00
|
|
|
dynamicProperty->val->int32);
|
|
|
|
} else {
|
|
|
|
memoryMB = dynamicProperty->val->int32;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return memoryMB * 1024; /* Scale from megabyte to kilobyte */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_Long_Alloc(&spec->memoryMB) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->memoryMB->value =
|
|
|
|
memory / 1024; /* Scale from kilobytes to megabytes */
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
2010-01-15 22:05:26 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set max-memory to %lu kilobytes"), memory);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0 ||
|
|
|
|
esxVI_Long_Alloc(&spec->memoryAllocation->limit) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->memoryAllocation->limit->value =
|
|
|
|
memory / 1024; /* Scale from kilobytes to megabytes */
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
2010-01-15 22:05:26 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set memory to %lu kilobytes"), memory);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
int64_t memory_limit = -1;
|
|
|
|
esxVI_PerfMetricId *perfMetricId = NULL;
|
|
|
|
esxVI_PerfMetricId *perfMetricIdList = NULL;
|
|
|
|
esxVI_Int *counterId = NULL;
|
|
|
|
esxVI_Int *counterIdList = NULL;
|
|
|
|
esxVI_PerfCounterInfo *perfCounterInfo = NULL;
|
|
|
|
esxVI_PerfCounterInfo *perfCounterInfoList = NULL;
|
|
|
|
esxVI_PerfQuerySpec *querySpec = NULL;
|
2010-04-13 12:25:52 +00:00
|
|
|
esxVI_PerfEntityMetricBase *perfEntityMetricBase = NULL;
|
|
|
|
esxVI_PerfEntityMetricBase *perfEntityMetricBaseList = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PerfEntityMetric *perfEntityMetric = NULL;
|
|
|
|
esxVI_PerfMetricIntSeries *perfMetricIntSeries = NULL;
|
|
|
|
esxVI_Long *value = NULL;
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
memset(info, 0, sizeof (*info));
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState\0"
|
|
|
|
"config.hardware.memoryMB\0"
|
|
|
|
"config.hardware.numCPU\0"
|
|
|
|
"config.memoryAllocation.limit\0") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info->state = VIR_DOMAIN_NOSTATE;
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
|
|
|
|
if (esxVI_VirtualMachinePowerState_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
info->state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
|
|
|
|
(powerState);
|
2009-07-23 20:21:08 +00:00
|
|
|
} else if (STREQ(dynamicProperty->name, "config.hardware.memoryMB")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Int) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info->maxMem = dynamicProperty->val->int32 * 1024; /* Scale from megabyte to kilobyte */
|
|
|
|
} else if (STREQ(dynamicProperty->name, "config.hardware.numCPU")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Int) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info->nrVirtCpu = dynamicProperty->val->int32;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.memoryAllocation.limit")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Long) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memory_limit = dynamicProperty->val->int64;
|
|
|
|
|
|
|
|
if (memory_limit > 0) {
|
|
|
|
memory_limit *= 1024; /* Scale from megabyte to kilobyte */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* memory_limit < 0 means no memory limit is set */
|
|
|
|
info->memory = memory_limit < 0 ? info->maxMem : memory_limit;
|
|
|
|
|
|
|
|
/* Verify the cached 'used CPU time' performance counter ID */
|
2010-07-18 15:27:05 +00:00
|
|
|
/* FIXME: Currently no host for a vpx:// connection */
|
|
|
|
if (priv->host != NULL) {
|
|
|
|
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) {
|
|
|
|
if (esxVI_Int_Alloc(&counterId) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
counterId->value = priv->usedCpuTimeCounterId;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_QueryPerfCounter(priv->host, counterIdList,
|
|
|
|
&perfCounterInfo) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (STRNEQ(perfCounterInfo->groupInfo->key, "cpu") ||
|
|
|
|
STRNEQ(perfCounterInfo->nameInfo->key, "used") ||
|
|
|
|
STRNEQ(perfCounterInfo->unitInfo->key, "millisecond")) {
|
|
|
|
VIR_DEBUG("Cached usedCpuTimeCounterId %d is invalid",
|
|
|
|
priv->usedCpuTimeCounterId);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->usedCpuTimeCounterId = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_Int_Free(&counterIdList);
|
|
|
|
esxVI_PerfCounterInfo_Free(&perfCounterInfo);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/*
|
|
|
|
* Query the PerformanceManager for the 'used CPU time' performance
|
|
|
|
* counter ID and cache it, if it's not already cached.
|
|
|
|
*/
|
|
|
|
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId < 0) {
|
|
|
|
if (esxVI_QueryAvailablePerfMetric(priv->host, virtualMachine->obj,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
&perfMetricIdList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (perfMetricId = perfMetricIdList; perfMetricId != NULL;
|
|
|
|
perfMetricId = perfMetricId->_next) {
|
|
|
|
VIR_DEBUG("perfMetricId counterId %d, instance '%s'",
|
|
|
|
perfMetricId->counterId->value, perfMetricId->instance);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
counterId = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_Int_DeepCopy(&counterId, perfMetricId->counterId) < 0 ||
|
|
|
|
esxVI_Int_AppendToList(&counterIdList, counterId) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_QueryPerfCounter(priv->host, counterIdList,
|
|
|
|
&perfCounterInfoList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (perfCounterInfo = perfCounterInfoList; perfCounterInfo != NULL;
|
|
|
|
perfCounterInfo = perfCounterInfo->_next) {
|
|
|
|
VIR_DEBUG("perfCounterInfo key %d, nameInfo '%s', groupInfo '%s', "
|
|
|
|
"unitInfo '%s', rollupType %d, statsType %d",
|
|
|
|
perfCounterInfo->key->value,
|
|
|
|
perfCounterInfo->nameInfo->key,
|
|
|
|
perfCounterInfo->groupInfo->key,
|
|
|
|
perfCounterInfo->unitInfo->key,
|
|
|
|
perfCounterInfo->rollupType,
|
|
|
|
perfCounterInfo->statsType);
|
|
|
|
|
|
|
|
if (STREQ(perfCounterInfo->groupInfo->key, "cpu") &&
|
|
|
|
STREQ(perfCounterInfo->nameInfo->key, "used") &&
|
|
|
|
STREQ(perfCounterInfo->unitInfo->key, "millisecond")) {
|
|
|
|
priv->usedCpuTimeCounterId = perfCounterInfo->key->value;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (priv->usedCpuTimeCounterId < 0) {
|
|
|
|
VIR_WARN0("Could not find 'used CPU time' performance counter");
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/*
|
|
|
|
* Query the PerformanceManager for the 'used CPU time' performance
|
|
|
|
* counter value.
|
|
|
|
*/
|
|
|
|
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) {
|
|
|
|
VIR_DEBUG("usedCpuTimeCounterId %d BEGIN", priv->usedCpuTimeCounterId);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_PerfQuerySpec_Alloc(&querySpec) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&querySpec->maxSample) < 0 ||
|
|
|
|
esxVI_PerfMetricId_Alloc(&querySpec->metricId) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&querySpec->metricId->counterId) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
querySpec->entity = virtualMachine->obj;
|
|
|
|
querySpec->maxSample->value = 1;
|
|
|
|
querySpec->metricId->counterId->value = priv->usedCpuTimeCounterId;
|
|
|
|
querySpec->metricId->instance = (char *)"";
|
|
|
|
querySpec->format = (char *)"normal";
|
|
|
|
|
|
|
|
if (esxVI_QueryPerf(priv->host, querySpec,
|
|
|
|
&perfEntityMetricBaseList) < 0) {
|
|
|
|
querySpec->entity = NULL;
|
|
|
|
querySpec->metricId->instance = NULL;
|
|
|
|
querySpec->format = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (perfEntityMetricBase = perfEntityMetricBaseList;
|
|
|
|
perfEntityMetricBase != NULL;
|
|
|
|
perfEntityMetricBase = perfEntityMetricBase->_next) {
|
|
|
|
VIR_DEBUG0("perfEntityMetric ...");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
perfEntityMetric =
|
|
|
|
esxVI_PerfEntityMetric_DynamicCast(perfEntityMetricBase);
|
2010-04-13 12:25:52 +00:00
|
|
|
|
2010-10-15 18:13:04 +00:00
|
|
|
if (perfEntityMetric == NULL) {
|
|
|
|
VIR_ERROR(_("QueryPerf returned object with unexpected type '%s'"),
|
|
|
|
esxVI_Type_ToString(perfEntityMetricBase->_type));
|
2010-07-18 15:27:05 +00:00
|
|
|
}
|
2010-04-13 12:25:52 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
perfMetricIntSeries =
|
|
|
|
esxVI_PerfMetricIntSeries_DynamicCast(perfEntityMetric->value);
|
2010-03-06 16:56:28 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (perfMetricIntSeries == NULL) {
|
2010-10-15 18:13:04 +00:00
|
|
|
VIR_ERROR(_("QueryPerf returned object with unexpected type '%s'"),
|
|
|
|
esxVI_Type_ToString(perfEntityMetric->value->_type));
|
2010-07-18 15:27:05 +00:00
|
|
|
}
|
2010-03-06 16:56:28 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (; perfMetricIntSeries != NULL;
|
|
|
|
perfMetricIntSeries = perfMetricIntSeries->_next) {
|
|
|
|
VIR_DEBUG0("perfMetricIntSeries ...");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (value = perfMetricIntSeries->value;
|
|
|
|
value != NULL;
|
|
|
|
value = value->_next) {
|
|
|
|
VIR_DEBUG("value %lld", (long long int)value->value);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
querySpec->entity = NULL;
|
|
|
|
querySpec->metricId->instance = NULL;
|
|
|
|
querySpec->format = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_DEBUG("usedCpuTimeCounterId %d END", priv->usedCpuTimeCounterId);
|
2010-05-19 20:59:32 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Cannot map between realtive used-cpu-time and absolute
|
|
|
|
* info->cpuTime
|
|
|
|
*/
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_PerfMetricId_Free(&perfMetricIdList);
|
|
|
|
esxVI_Int_Free(&counterIdList);
|
|
|
|
esxVI_PerfCounterInfo_Free(&perfCounterInfoList);
|
|
|
|
esxVI_PerfQuerySpec_Free(&querySpec);
|
2010-04-13 12:25:52 +00:00
|
|
|
esxVI_PerfEntityMetricBase_Free(&perfEntityMetricBaseList);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
esxDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
|
|
|
|
unsigned int flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-08-06 13:15:45 +00:00
|
|
|
int maxVcpus;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
if (flags != VIR_DOMAIN_VCPU_LIVE) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
if (nvcpus < 1) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Requested number of virtual CPUs must at least be 1"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
maxVcpus = esxDomainGetMaxVcpus(domain);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (maxVcpus < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (nvcpus > maxVcpus) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Requested number of virtual CPUs is greater than max "
|
|
|
|
"allowable number of virtual CPUs for the domain: %d > %d"),
|
2009-08-06 13:15:45 +00:00
|
|
|
nvcpus, maxVcpus);
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&spec->numCPUs) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->numCPUs->value = nvcpus;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
2010-01-15 22:05:26 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set number of virtual CPUs to %d"), nvcpus);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
|
|
|
|
{
|
|
|
|
return esxDomainSetVcpusFlags(domain, nvcpus, VIR_DOMAIN_VCPU_LIVE);
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
static int
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
esxDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
if (flags != (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (priv->maxVcpus > 0) {
|
|
|
|
return priv->maxVcpus;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
priv->maxVcpus = -1;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"capability.maxSupportedVcpus") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the HostSystem object"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Int) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
priv->maxVcpus = dynamicProperty->val->int32;
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
return priv->maxVcpus;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
static int
|
|
|
|
esxDomainGetMaxVcpus(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return esxDomainGetVcpusFlags(domain, (VIR_DOMAIN_VCPU_LIVE |
|
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM));
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
esxDomainDumpXML(virDomainPtr domain, int flags)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2010-08-20 18:42:45 +00:00
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
int id;
|
2010-07-31 21:57:42 +00:00
|
|
|
char *vmPathName = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
char *datastoreName = NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
char *directoryName = NULL;
|
2010-08-25 09:44:57 +00:00
|
|
|
char *directoryAndFileName = NULL;
|
2009-09-04 15:55:55 +00:00
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-07-23 20:21:08 +00:00
|
|
|
char *url = NULL;
|
|
|
|
char *vmx = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Context ctx;
|
|
|
|
esxVMX_Data data;
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 18:42:45 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"config.files.vmPathName\0"
|
|
|
|
"runtime.powerState\0") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-08-20 18:42:45 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0 ||
|
|
|
|
esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, NULL) < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_GetStringValue(virtualMachine, "config.files.vmPathName",
|
|
|
|
&vmPathName, esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
if (esxUtil_ParseDatastorePath(vmPathName, &datastoreName, &directoryName,
|
2010-08-25 09:44:57 +00:00
|
|
|
&directoryAndFileName) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 15:55:55 +00:00
|
|
|
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
|
|
|
|
domain->conn->uri->server, domain->conn->uri->port);
|
2010-08-25 09:44:57 +00:00
|
|
|
virBufferURIEncodeString(&buffer, directoryAndFileName);
|
2009-09-04 15:55:55 +00:00
|
|
|
virBufferAddLit(&buffer, "?dcPath=");
|
2010-07-31 21:57:42 +00:00
|
|
|
virBufferURIEncodeString(&buffer, priv->primary->datacenter->name);
|
2009-09-04 15:55:55 +00:00
|
|
|
virBufferAddLit(&buffer, "&dsName=");
|
|
|
|
virBufferURIEncodeString(&buffer, datastoreName);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 15:55:55 +00:00
|
|
|
url = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_Context_DownloadFile(priv->primary, url, &vmx) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:43:19 +00:00
|
|
|
data.ctx = priv->primary;
|
2010-08-25 09:44:57 +00:00
|
|
|
|
|
|
|
if (directoryName == NULL) {
|
|
|
|
if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]",
|
|
|
|
datastoreName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s",
|
|
|
|
datastoreName, directoryName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
ctx.opaque = &data;
|
|
|
|
ctx.parseFileName = esxParseVMXFileName;
|
|
|
|
ctx.formatFileName = NULL;
|
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
|
|
|
|
def = esxVMX_ParseConfig(&ctx, priv->caps, vmx,
|
|
|
|
priv->primary->productVersion);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (def != NULL) {
|
2010-08-20 18:42:45 +00:00
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
|
|
|
def->id = id;
|
|
|
|
}
|
|
|
|
|
2010-02-09 18:58:01 +00:00
|
|
|
xml = virDomainDefFormat(def, flags);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (url == NULL) {
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
2009-07-27 12:13:11 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(datastoreName);
|
2009-09-23 12:52:36 +00:00
|
|
|
VIR_FREE(directoryName);
|
2010-08-25 09:44:57 +00:00
|
|
|
VIR_FREE(directoryAndFileName);
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(url);
|
2010-08-25 09:44:57 +00:00
|
|
|
VIR_FREE(data.datastorePathWithoutFileName);
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(vmx);
|
2009-07-27 12:13:11 +00:00
|
|
|
virDomainDefFree(def);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
|
|
|
|
const char *nativeConfig,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Context ctx;
|
|
|
|
esxVMX_Data data;
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
|
|
|
if (STRNEQ(nativeFormat, "vmware-vmx")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Unsupported config format '%s'"), nativeFormat);
|
2009-07-27 12:13:11 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:43:19 +00:00
|
|
|
data.ctx = priv->primary;
|
2010-08-25 09:44:57 +00:00
|
|
|
data.datastorePathWithoutFileName = (char *)"[?] ?";
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
ctx.opaque = &data;
|
|
|
|
ctx.parseFileName = esxParseVMXFileName;
|
|
|
|
ctx.formatFileName = NULL;
|
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
|
|
|
|
def = esxVMX_ParseConfig(&ctx, priv->caps, nativeConfig,
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->primary->productVersion);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (def != NULL) {
|
2010-02-09 18:58:01 +00:00
|
|
|
xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-23 12:16:41 +00:00
|
|
|
static char *
|
|
|
|
esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
|
|
|
|
const char *domainXml,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Context ctx;
|
|
|
|
esxVMX_Data data;
|
2009-09-23 12:16:41 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *vmx = NULL;
|
|
|
|
|
|
|
|
if (STRNEQ(nativeFormat, "vmware-vmx")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Unsupported config format '%s'"), nativeFormat);
|
2009-09-23 12:16:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-09 18:58:01 +00:00
|
|
|
def = virDomainDefParseString(priv->caps, domainXml, 0);
|
2009-09-23 12:16:41 +00:00
|
|
|
|
|
|
|
if (def == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-05 15:43:19 +00:00
|
|
|
data.ctx = priv->primary;
|
2010-08-25 09:44:57 +00:00
|
|
|
data.datastorePathWithoutFileName = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
ctx.opaque = &data;
|
|
|
|
ctx.parseFileName = NULL;
|
|
|
|
ctx.formatFileName = esxFormatVMXFileName;
|
|
|
|
ctx.autodetectSCSIControllerModel = esxAutodetectSCSIControllerModel;
|
|
|
|
|
|
|
|
vmx = esxVMX_FormatConfig(&ctx, priv->caps, def,
|
2010-07-18 15:27:05 +00:00
|
|
|
priv->primary->productVersion);
|
2009-09-23 12:16:41 +00:00
|
|
|
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return vmx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static int
|
|
|
|
esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
bool success = false;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
int count = 0;
|
2009-11-08 21:08:54 +00:00
|
|
|
int i;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (names == NULL || maxnames < 0) {
|
2010-04-07 08:55:00 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (maxnames == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"name\0"
|
|
|
|
"runtime.powerState\0") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(priv->primary, propertyNameList,
|
|
|
|
&virtualMachineList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
|
|
|
|
virtualMachine = virtualMachine->_next) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
2009-07-23 20:21:08 +00:00
|
|
|
&powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
names[count] = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine, NULL, &names[count],
|
|
|
|
NULL) < 0) {
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
++count;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
if (count >= maxnames) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
success = true;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
cleanup:
|
|
|
|
if (! success) {
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
count = -1;
|
2009-11-08 21:08:54 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return count;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxNumberOfDefinedDomains(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-18 19:31:46 +00:00
|
|
|
return esxVI_LookupNumberOfDomainsByPowerState
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, esxVI_VirtualMachinePowerState_PoweredOn,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-06-10 15:55:36 +00:00
|
|
|
esxDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
2010-07-30 15:06:20 +00:00
|
|
|
int id = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, propertyNameList, &virtualMachine,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-07-30 15:06:20 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0 ||
|
|
|
|
esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, NULL) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered off"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_PowerOnVM_Task(priv->primary, virtualMachine->obj, NULL,
|
2010-04-13 12:25:52 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not start domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 15:06:20 +00:00
|
|
|
domain->id = id;
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
|
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
static int
|
|
|
|
esxDomainCreate(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return esxDomainCreateWithFlags(domain, 0);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
static virDomainPtr
|
2010-10-12 17:37:39 +00:00
|
|
|
esxDomainDefineXML(virConnectPtr conn, const char *xml)
|
2009-09-23 12:52:36 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-09-23 12:52:36 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *vmx = NULL;
|
2009-10-18 19:21:46 +00:00
|
|
|
int i;
|
|
|
|
virDomainDiskDefPtr disk = NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Context ctx;
|
|
|
|
esxVMX_Data data;
|
2009-09-23 12:52:36 +00:00
|
|
|
char *datastoreName = NULL;
|
|
|
|
char *directoryName = NULL;
|
2010-10-12 17:37:39 +00:00
|
|
|
char *escapedName = NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *url = NULL;
|
|
|
|
char *datastoreRelatedPath = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_ManagedObjectReference *resourcePool = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
virDomainPtr domain = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse domain XML */
|
2010-02-09 18:58:01 +00:00
|
|
|
def = virDomainDefParseString(priv->caps, xml,
|
2009-09-23 12:52:36 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
|
|
|
|
if (def == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if an existing domain should be edited */
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_LookupVirtualMachineByUuid(priv->primary, def->uuid, NULL,
|
2009-09-23 12:52:36 +00:00
|
|
|
&virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
if (virtualMachine == NULL &&
|
|
|
|
esxVI_LookupVirtualMachineByName(priv->primary, def->name, NULL,
|
|
|
|
&virtualMachine,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
if (virtualMachine != NULL) {
|
|
|
|
/* FIXME */
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain already exists, editing existing domains is not "
|
|
|
|
"supported yet"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Build VMX from domain XML */
|
2010-08-05 15:43:19 +00:00
|
|
|
data.ctx = priv->primary;
|
2010-08-25 09:44:57 +00:00
|
|
|
data.datastorePathWithoutFileName = NULL;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
ctx.opaque = &data;
|
|
|
|
ctx.parseFileName = NULL;
|
|
|
|
ctx.formatFileName = esxFormatVMXFileName;
|
|
|
|
ctx.autodetectSCSIControllerModel = esxAutodetectSCSIControllerModel;
|
|
|
|
|
|
|
|
vmx = esxVMX_FormatConfig(&ctx, priv->caps, def,
|
2010-07-31 21:57:42 +00:00
|
|
|
priv->primary->productVersion);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
if (vmx == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 19:21:46 +00:00
|
|
|
/*
|
|
|
|
* Build VMX datastore URL. Use the source of the first file-based harddisk
|
|
|
|
* to deduce the datastore and path for the VMX file. Don't just use the
|
|
|
|
* first disk, because it may be CDROM disk and ISO images are normaly not
|
|
|
|
* located in the virtual machine's directory. This approach to deduce the
|
|
|
|
* datastore isn't perfect but should work in the majority of cases.
|
|
|
|
*/
|
2009-09-23 12:52:36 +00:00
|
|
|
if (def->ndisks < 1) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain XML doesn't contain any disks, cannot deduce "
|
|
|
|
"datastore and path for VMX file"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-10-18 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < def->ndisks; ++i) {
|
|
|
|
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
|
|
|
|
def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_FILE) {
|
|
|
|
disk = def->disks[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disk == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain XML doesn't contain any file-based harddisks, "
|
|
|
|
"cannot deduce datastore and path for VMX file"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 19:21:46 +00:00
|
|
|
if (disk->src == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("First file-based harddisk has no source, cannot deduce "
|
|
|
|
"datastore and path for VMX file"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
if (esxUtil_ParseDatastorePath(disk->src, &datastoreName, &directoryName,
|
2010-08-25 09:44:57 +00:00
|
|
|
NULL) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
if (! virFileHasSuffix(disk->src, ".vmdk")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting source '%s' of first file-based harddisk to "
|
|
|
|
"be a VMDK image"), disk->src);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBufferVSprintf(&buffer, "%s://%s:%d/folder/", priv->transport,
|
|
|
|
conn->uri->server, conn->uri->port);
|
|
|
|
|
|
|
|
if (directoryName != NULL) {
|
|
|
|
virBufferURIEncodeString(&buffer, directoryName);
|
|
|
|
virBufferAddChar(&buffer, '/');
|
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
escapedName = esxUtil_EscapeDatastoreItem(def->name);
|
|
|
|
|
|
|
|
if (escapedName == NULL) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferURIEncodeString(&buffer, escapedName);
|
2009-09-23 12:52:36 +00:00
|
|
|
virBufferAddLit(&buffer, ".vmx?dcPath=");
|
2010-07-31 21:57:42 +00:00
|
|
|
virBufferURIEncodeString(&buffer, priv->primary->datacenter->name);
|
2009-09-23 12:52:36 +00:00
|
|
|
virBufferAddLit(&buffer, "&dsName=");
|
|
|
|
virBufferURIEncodeString(&buffer, datastoreName);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
url = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
/* Check, if VMX file already exists */
|
|
|
|
/* FIXME */
|
|
|
|
|
|
|
|
/* Upload VMX file */
|
|
|
|
VIR_DEBUG("Uploading .vmx config, url='%s' vmx='%s'", url, vmx);
|
|
|
|
|
|
|
|
if (esxVI_Context_UploadFile(priv->primary, url, vmx) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the domain */
|
2009-09-23 12:52:36 +00:00
|
|
|
if (directoryName != NULL) {
|
|
|
|
if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
|
2010-10-12 17:37:39 +00:00
|
|
|
directoryName, escapedName) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
|
2010-10-12 17:37:39 +00:00
|
|
|
escapedName) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_RegisterVM_Task(priv->primary, priv->primary->datacenter->vmFolder,
|
2009-09-23 12:52:36 +00:00
|
|
|
datastoreRelatedPath, NULL, esxVI_Boolean_False,
|
2010-07-31 21:57:42 +00:00
|
|
|
priv->primary->computeResource->resourcePool,
|
|
|
|
priv->primary->hostSystem->_reference,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, def->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_OptionalItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not define domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
domain = virGetDomain(conn, def->name, def->uuid);
|
|
|
|
|
|
|
|
if (domain != NULL) {
|
|
|
|
domain->id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Add proper rollback in case of an error */
|
|
|
|
|
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (url == NULL) {
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
virDomainDefFree(def);
|
|
|
|
VIR_FREE(vmx);
|
|
|
|
VIR_FREE(datastoreName);
|
|
|
|
VIR_FREE(directoryName);
|
2010-10-12 17:37:39 +00:00
|
|
|
VIR_FREE(escapedName);
|
2009-09-23 12:52:36 +00:00
|
|
|
VIR_FREE(url);
|
|
|
|
VIR_FREE(datastoreRelatedPath);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_ManagedObjectReference_Free(&resourcePool);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:30:10 +00:00
|
|
|
static int
|
|
|
|
esxDomainUndefine(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-12-06 23:59:56 +00:00
|
|
|
esxVI_Context *ctx = NULL;
|
2009-09-04 16:30:10 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
|
2009-12-06 23:59:56 +00:00
|
|
|
if (priv->vCenter != NULL) {
|
|
|
|
ctx = priv->vCenter;
|
|
|
|
} else {
|
|
|
|
ctx = priv->host;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_EnsureSession(ctx) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-09-04 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-09-04 16:30:10 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(ctx, domain->uuid, propertyNameList,
|
|
|
|
&virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_Suspended &&
|
|
|
|
powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not suspended or powered off"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-09-04 16:30:10 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 11:41:04 +00:00
|
|
|
/*
|
|
|
|
* The scheduler interface exposes basically the CPU ResourceAllocationInfo:
|
|
|
|
*
|
|
|
|
* - http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.ResourceAllocationInfo.html
|
|
|
|
* - http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.SharesInfo.html
|
|
|
|
* - http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.SharesInfo.Level.html
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Available parameters:
|
|
|
|
*
|
|
|
|
* - reservation (VIR_DOMAIN_SCHED_FIELD_LLONG >= 0, in megaherz)
|
|
|
|
*
|
2009-11-13 21:43:10 +00:00
|
|
|
* The amount of CPU resource that is guaranteed to be available to the domain.
|
2009-07-30 11:41:04 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* - limit (VIR_DOMAIN_SCHED_FIELD_LLONG >= 0, or -1, in megaherz)
|
|
|
|
*
|
2009-11-13 21:43:10 +00:00
|
|
|
* The CPU utilization of the domain will be limited to this value, even if
|
|
|
|
* more CPU resources are available. If the limit is set to -1, the CPU
|
2009-07-30 11:41:04 +00:00
|
|
|
* utilization of the domain is unlimited. If the limit is not set to -1, it
|
|
|
|
* must be greater than or equal to the reservation.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* - shares (VIR_DOMAIN_SCHED_FIELD_INT >= 0, or in {-1, -2, -3}, no unit)
|
|
|
|
*
|
|
|
|
* Shares are used to determine relative CPU allocation between domains. In
|
|
|
|
* general, a domain with more shares gets proportionally more of the CPU
|
|
|
|
* resource. The special values -1, -2 and -3 represent the predefined
|
|
|
|
* SharesLevel 'low', 'normal' and 'high'.
|
|
|
|
*/
|
2009-07-23 20:21:08 +00:00
|
|
|
static char *
|
2010-01-15 22:05:26 +00:00
|
|
|
esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
char *type = strdup("allocation");
|
|
|
|
|
|
|
|
if (type == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-30 11:41:04 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*nparams = 3; /* reservation, limit, shares */
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainGetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virSchedParameterPtr params, int *nparams)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_SharesInfo *sharesInfo = NULL;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (*nparams < 3) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Parameter array must have space for 3 items"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"config.cpuAllocation.reservation\0"
|
|
|
|
"config.cpuAllocation.limit\0"
|
|
|
|
"config.cpuAllocation.shares\0") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
|
|
|
dynamicProperty != NULL && mask != 7 && i < 3;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.cpuAllocation.reservation") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 0))) {
|
2009-07-23 20:21:08 +00:00
|
|
|
snprintf (params[i].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s",
|
|
|
|
"reservation");
|
|
|
|
|
|
|
|
params[i].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Long) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
params[i].value.l = dynamicProperty->val->int64;
|
|
|
|
mask |= 1 << 0;
|
|
|
|
++i;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.cpuAllocation.limit") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 1))) {
|
2009-07-23 20:21:08 +00:00
|
|
|
snprintf (params[i].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s",
|
|
|
|
"limit");
|
|
|
|
|
|
|
|
params[i].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Type_Long) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
params[i].value.l = dynamicProperty->val->int64;
|
|
|
|
mask |= 1 << 1;
|
|
|
|
++i;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.cpuAllocation.shares") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 2))) {
|
2009-07-23 20:21:08 +00:00
|
|
|
snprintf (params[i].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s",
|
|
|
|
"shares");
|
|
|
|
|
|
|
|
params[i].type = VIR_DOMAIN_SCHED_FIELD_INT;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_SharesInfo_CastFromAnyType(dynamicProperty->val,
|
2009-07-23 20:21:08 +00:00
|
|
|
&sharesInfo) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (sharesInfo->level) {
|
|
|
|
case esxVI_SharesLevel_Custom:
|
|
|
|
params[i].value.i = sharesInfo->shares->value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_SharesLevel_Low:
|
|
|
|
params[i].value.i = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_SharesLevel_Normal:
|
|
|
|
params[i].value.i = -2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_SharesLevel_High:
|
|
|
|
params[i].value.i = -3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Shares level has unknown value %d"),
|
2009-07-30 15:40:29 +00:00
|
|
|
(int)sharesInfo->level);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_SharesInfo_Free(&sharesInfo);
|
|
|
|
|
|
|
|
mask |= 1 << 2;
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*nparams = i;
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virSchedParameterPtr params, int nparams)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_SharesInfo *sharesInfo = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
int i;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_ResourceAllocationInfo_Alloc(&spec->cpuAllocation) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; ++i) {
|
|
|
|
if (STREQ (params[i].field, "reservation") &&
|
|
|
|
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (params[i].value.l < 0) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set reservation to %lld MHz, expecting "
|
|
|
|
"positive value"), params[i].value.l);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->cpuAllocation->reservation->value = params[i].value.l;
|
|
|
|
} else if (STREQ (params[i].field, "limit") &&
|
|
|
|
params[i].type == VIR_DOMAIN_SCHED_FIELD_LLONG) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (params[i].value.l < -1) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set limit to %lld MHz, expecting "
|
|
|
|
"positive value or -1 (unlimited)"),
|
2009-07-23 20:21:08 +00:00
|
|
|
params[i].value.l);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->cpuAllocation->limit->value = params[i].value.l;
|
|
|
|
} else if (STREQ (params[i].field, "shares") &&
|
2009-07-30 11:41:04 +00:00
|
|
|
params[i].type == VIR_DOMAIN_SCHED_FIELD_INT) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_SharesInfo_Alloc(&sharesInfo) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&sharesInfo->shares) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->cpuAllocation->shares = sharesInfo;
|
|
|
|
|
2009-07-30 11:41:04 +00:00
|
|
|
if (params[i].value.i >= 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
spec->cpuAllocation->shares->level = esxVI_SharesLevel_Custom;
|
2009-07-30 11:41:04 +00:00
|
|
|
spec->cpuAllocation->shares->shares->value = params[i].value.i;
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
2009-07-30 11:41:04 +00:00
|
|
|
switch (params[i].value.i) {
|
2009-07-23 20:21:08 +00:00
|
|
|
case -1:
|
|
|
|
spec->cpuAllocation->shares->level = esxVI_SharesLevel_Low;
|
|
|
|
spec->cpuAllocation->shares->shares->value = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
spec->cpuAllocation->shares->level =
|
|
|
|
esxVI_SharesLevel_Normal;
|
|
|
|
spec->cpuAllocation->shares->shares->value = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -3:
|
|
|
|
spec->cpuAllocation->shares->level =
|
|
|
|
esxVI_SharesLevel_High;
|
|
|
|
spec->cpuAllocation->shares->shares->value = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not set shares to %d, expecting positive "
|
|
|
|
"value or -1 (low), -2 (normal) or -3 (high)"),
|
2009-07-23 20:21:08 +00:00
|
|
|
params[i].value.i);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
|
2010-01-15 22:05:26 +00:00
|
|
|
params[i].field);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
2010-01-15 22:05:26 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not change scheduler parameters"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainMigratePrepare(virConnectPtr dconn,
|
|
|
|
char **cookie ATTRIBUTE_UNUSED,
|
|
|
|
int *cookielen ATTRIBUTE_UNUSED,
|
2010-07-31 21:57:42 +00:00
|
|
|
const char *uri_in ATTRIBUTE_UNUSED,
|
|
|
|
char **uri_out,
|
2009-07-23 20:21:08 +00:00
|
|
|
unsigned long flags ATTRIBUTE_UNUSED,
|
|
|
|
const char *dname ATTRIBUTE_UNUSED,
|
|
|
|
unsigned long resource ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-07-31 21:57:42 +00:00
|
|
|
esxPrivate *priv = dconn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (uri_in == NULL) {
|
2010-07-31 21:57:42 +00:00
|
|
|
if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s",
|
|
|
|
priv->vCenter->ipAddress,
|
|
|
|
priv->vCenter->computeResource->resourcePool->value,
|
|
|
|
priv->vCenter->hostSystem->_reference->value) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainMigratePerform(virDomainPtr domain,
|
|
|
|
const char *cookie ATTRIBUTE_UNUSED,
|
|
|
|
int cookielen ATTRIBUTE_UNUSED,
|
|
|
|
const char *uri,
|
|
|
|
unsigned long flags ATTRIBUTE_UNUSED,
|
|
|
|
const char *dname,
|
|
|
|
unsigned long bandwidth ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2010-07-31 21:57:42 +00:00
|
|
|
xmlURIPtr parsedUri = NULL;
|
|
|
|
char *saveptr;
|
|
|
|
char *path_resourcePool;
|
|
|
|
char *path_hostSystem;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_ManagedObjectReference resourcePool;
|
|
|
|
esxVI_ManagedObjectReference hostSystem;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Event *eventList = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2009-08-06 13:15:45 +00:00
|
|
|
if (priv->vCenter == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Migration not possible without a vCenter"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dname != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Renaming domains on migration not supported"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_EnsureSession(priv->vCenter) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* Parse migration URI */
|
|
|
|
parsedUri = xmlParseURI(uri);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (parsedUri == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (parsedUri->scheme == NULL || STRCASENEQ(parsedUri->scheme, "vpxmigr")) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Only vpxmigr:// migration URIs are supported"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (STRCASENEQ(priv->vCenter->ipAddress, parsedUri->server)) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Migration source and destination have to refer to "
|
|
|
|
"the same vCenter"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_resourcePool = strtok_r(parsedUri->path, "/", &saveptr);
|
|
|
|
path_hostSystem = strtok_r(NULL, "", &saveptr);
|
|
|
|
|
|
|
|
if (path_resourcePool == NULL || path_hostSystem == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Migration URI has to specify resource pool and host system"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
resourcePool._next = NULL;
|
|
|
|
resourcePool._type = esxVI_Type_ManagedObjectReference;
|
|
|
|
resourcePool.type = (char *)"ResourcePool";
|
|
|
|
resourcePool.value = path_resourcePool;
|
|
|
|
|
|
|
|
hostSystem._next = NULL;
|
|
|
|
hostSystem._type = esxVI_Type_ManagedObjectReference;
|
|
|
|
hostSystem.type = (char *)"HostSystem";
|
|
|
|
hostSystem.value = path_hostSystem;
|
|
|
|
|
|
|
|
/* Lookup VirtualMachine */
|
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
|
|
|
(priv->vCenter, domain->uuid, NULL, &virtualMachine,
|
|
|
|
priv->autoAnswer) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the purposed migration */
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ValidateMigration(priv->vCenter, virtualMachine->obj,
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_VirtualMachinePowerState_Undefined, NULL,
|
|
|
|
&resourcePool, &hostSystem, &eventList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eventList != NULL) {
|
|
|
|
/*
|
|
|
|
* FIXME: Need to report the complete list of events. Limit reporting
|
|
|
|
* to the first event for now.
|
|
|
|
*/
|
|
|
|
if (eventList->fullFormattedMessage != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not migrate domain, validation reported a "
|
|
|
|
"problem: %s"), eventList->fullFormattedMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not migrate domain, validation reported a "
|
|
|
|
"problem"));
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the purposed migration */
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_MigrateVM_Task(priv->vCenter, virtualMachine->obj,
|
|
|
|
&resourcePool, &hostSystem,
|
2010-02-23 00:06:58 +00:00
|
|
|
esxVI_VirtualMachineMovePriority_DefaultPriority,
|
|
|
|
esxVI_VirtualMachinePowerState_Undefined,
|
|
|
|
&task) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->vCenter, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-01-15 22:05:26 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not migrate domain, migration task finished with "
|
|
|
|
"an error"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
2010-07-31 21:57:42 +00:00
|
|
|
xmlFreeURI(parsedUri);
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_Event_Free(&eventList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
esxDomainMigrateFinish(virConnectPtr dconn, const char *dname,
|
|
|
|
const char *cookie ATTRIBUTE_UNUSED,
|
|
|
|
int cookielen ATTRIBUTE_UNUSED,
|
|
|
|
const char *uri ATTRIBUTE_UNUSED,
|
|
|
|
unsigned long flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
return esxDomainLookupByName(dconn, dname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-23 12:09:44 +00:00
|
|
|
static unsigned long long
|
|
|
|
esxNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
unsigned long long result = 0;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-09-23 12:09:44 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *resourcePool = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return 0;
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get memory usage of resource pool */
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-09-23 12:09:44 +00:00
|
|
|
"runtime.memory") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupObjectContentByType(priv->primary,
|
|
|
|
priv->primary->computeResource->resourcePool,
|
2009-10-18 19:31:46 +00:00
|
|
|
"ResourcePool", propertyNameList,
|
|
|
|
&resourcePool) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = resourcePool->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.memory")) {
|
|
|
|
if (esxVI_ResourcePoolResourceUsage_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, &resourcePoolResourceUsage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resourcePoolResourceUsage == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve memory usage of resource pool"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = resourcePoolResourceUsage->unreservedForVm->value;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&resourcePool);
|
|
|
|
esxVI_ResourcePoolResourceUsage_Free(&resourcePoolResourceUsage);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-18 00:03:31 +00:00
|
|
|
static int
|
|
|
|
esxIsEncrypted(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-11-18 00:03:31 +00:00
|
|
|
|
|
|
|
if (STRCASEEQ(priv->transport, "https")) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxIsSecure(virConnectPtr conn)
|
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-11-18 00:03:31 +00:00
|
|
|
|
|
|
|
if (STRCASEEQ(priv->transport, "https")) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainIsActive(virDomainPtr domain)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
2009-11-18 00:03:31 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-11-18 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-11-18 00:03:31 +00:00
|
|
|
"runtime.powerState") < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
2010-01-15 22:05:26 +00:00
|
|
|
propertyNameList, &virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-18 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
|
|
|
result = 1;
|
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainIsPersistent(virDomainPtr domain ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* ESX has no concept of transient domains, so all of them are persistent */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
static virDomainSnapshotPtr
|
|
|
|
esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
|
2010-04-16 12:04:31 +00:00
|
|
|
unsigned int flags)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
virDomainSnapshotDefPtr def = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def = virDomainSnapshotDefParseString(xmlDesc, 1);
|
|
|
|
|
|
|
|
if (def == NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-07-18 15:27:05 +00:00
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2010-04-07 09:23:53 +00:00
|
|
|
priv->autoAnswer) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, def->name,
|
|
|
|
&snapshotTree, &snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (snapshotTree != NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Snapshot '%s' already exists"), def->name);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_CreateSnapshot_Task(priv->primary, virtualMachine->obj,
|
2010-04-07 09:23:53 +00:00
|
|
|
def->name, def->description,
|
|
|
|
esxVI_Boolean_True,
|
|
|
|
esxVI_Boolean_False, &task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-04-07 09:23:53 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create snapshot"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, def->name);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainSnapshotDefFree(def);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
esxDomainSnapshotDumpXML(virDomainSnapshotPtr snapshot,
|
2010-04-16 12:04:31 +00:00
|
|
|
unsigned int flags)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
virDomainSnapshotDef def;
|
|
|
|
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
memset(&def, 0, sizeof (def));
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, &snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def.name = snapshot->name;
|
|
|
|
def.description = snapshotTree->description;
|
|
|
|
def.parent = snapshotTreeParent != NULL ? snapshotTreeParent->name : NULL;
|
|
|
|
|
|
|
|
if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime,
|
|
|
|
&def.creationTime) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def.state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
|
|
|
|
(snapshotTree->state);
|
|
|
|
|
|
|
|
virUUIDFormat(snapshot->domain->uuid, uuid_string);
|
|
|
|
|
|
|
|
xml = virDomainSnapshotDefFormat(uuid_string, &def, 0);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-04-16 12:04:31 +00:00
|
|
|
esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int count;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotTreeList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return count;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,
|
2010-04-16 12:04:31 +00:00
|
|
|
unsigned int flags)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
if (names == NULL || nameslen < 0) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameslen == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotTreeList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen);
|
|
|
|
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name,
|
2010-04-16 12:04:31 +00:00
|
|
|
unsigned int flags)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotTreeList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotTreeList, name, &snapshotTree,
|
|
|
|
&snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, name);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupCurrentSnapshotTree(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
¤tSnapshotTree,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentSnapshotTree != NULL) {
|
2010-05-19 20:59:32 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
|
|
|
|
return 1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return 0;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainSnapshotPtr
|
|
|
|
esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
|
2010-05-19 20:59:32 +00:00
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, NULL);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupCurrentSnapshotTree(priv->primary, domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
¤tSnapshotTree,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, currentSnapshotTree->name);
|
|
|
|
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
|
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, &snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_RevertToSnapshot_Task(priv->primary, snapshotTree->snapshot, NULL,
|
2010-04-07 09:23:53 +00:00
|
|
|
&task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, snapshot->domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-04-07 09:23:53 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not revert to snapshot '%s'"), snapshot->name);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
esxVI_Boolean removeChildren = esxVI_Boolean_False;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1);
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) {
|
|
|
|
removeChildren = esxVI_Boolean_True;
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
2010-04-07 09:23:53 +00:00
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, &snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_RemoveSnapshot_Task(priv->primary, snapshotTree->snapshot,
|
2010-04-07 09:23:53 +00:00
|
|
|
removeChildren, &task) < 0 ||
|
2010-07-18 15:27:05 +00:00
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, snapshot->domain->uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence_RequiredItem,
|
2010-04-07 09:23:53 +00:00
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not delete snapshot '%s'"), snapshot->name);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-06 17:53:39 +00:00
|
|
|
static int
|
|
|
|
esxDomainSetMemoryParameters(virDomainPtr domain, virMemoryParameterPtr params,
|
|
|
|
int nparams, unsigned int flags)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
|
|
|
priv->autoAnswer) < 0 ||
|
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; ++i) {
|
|
|
|
if (STREQ (params[i].field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE) &&
|
|
|
|
params[i].type == VIR_DOMAIN_SCHED_FIELD_ULLONG) {
|
|
|
|
if (esxVI_Long_Alloc(&spec->memoryAllocation->reservation) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
spec->memoryAllocation->reservation->value =
|
|
|
|
params[i].value.ul / 1024; /* Scale from kilobytes to megabytes */
|
|
|
|
} else {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, _("Unknown field '%s'"),
|
|
|
|
params[i].field);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
|
|
|
esxVI_Occurrence_RequiredItem,
|
|
|
|
priv->autoAnswer, &taskInfoState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not change memory parameters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainGetMemoryParameters(virDomainPtr domain, virMemoryParameterPtr params,
|
|
|
|
int *nparams, unsigned int flags)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_Long *reservation = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (*nparams == 0) {
|
|
|
|
*nparams = 1; /* min_guarantee */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*nparams < 1) {
|
|
|
|
ESX_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Parameter array must have space for 1 item"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList
|
|
|
|
(&propertyNameList, "config.memoryAllocation.reservation") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
propertyNameList, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetLong(virtualMachine, "config.memoryAllocation.reservation",
|
|
|
|
&reservation, esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrcpyStatic(params[0].field,
|
|
|
|
VIR_DOMAIN_MEMORY_MIN_GUARANTEE) == NULL) {
|
|
|
|
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Field %s too big for destination"),
|
|
|
|
VIR_DOMAIN_MEMORY_MIN_GUARANTEE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
|
|
|
|
params[0].value.ul = reservation->value * 1024; /* Scale from megabytes to kilobytes */
|
|
|
|
|
|
|
|
*nparams = 1;
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_Long_Free(&reservation);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static virDriver esxDriver = {
|
|
|
|
VIR_DRV_ESX,
|
|
|
|
"ESX",
|
|
|
|
esxOpen, /* open */
|
|
|
|
esxClose, /* close */
|
|
|
|
esxSupportsFeature, /* supports_feature */
|
|
|
|
esxGetType, /* type */
|
|
|
|
esxGetVersion, /* version */
|
2009-11-12 15:53:26 +00:00
|
|
|
NULL, /* libvirtVersion (impl. in libvirt.c) */
|
2009-07-23 20:21:08 +00:00
|
|
|
esxGetHostname, /* hostname */
|
|
|
|
NULL, /* getMaxVcpus */
|
|
|
|
esxNodeGetInfo, /* nodeGetInfo */
|
2009-09-04 16:25:27 +00:00
|
|
|
esxGetCapabilities, /* getCapabilities */
|
2009-07-23 20:21:08 +00:00
|
|
|
esxListDomains, /* listDomains */
|
|
|
|
esxNumberOfDomains, /* numOfDomains */
|
|
|
|
NULL, /* domainCreateXML */
|
|
|
|
esxDomainLookupByID, /* domainLookupByID */
|
|
|
|
esxDomainLookupByUUID, /* domainLookupByUUID */
|
|
|
|
esxDomainLookupByName, /* domainLookupByName */
|
|
|
|
esxDomainSuspend, /* domainSuspend */
|
|
|
|
esxDomainResume, /* domainResume */
|
|
|
|
esxDomainShutdown, /* domainShutdown */
|
|
|
|
esxDomainReboot, /* domainReboot */
|
|
|
|
esxDomainDestroy, /* domainDestroy */
|
|
|
|
esxDomainGetOSType, /* domainGetOSType */
|
|
|
|
esxDomainGetMaxMemory, /* domainGetMaxMemory */
|
|
|
|
esxDomainSetMaxMemory, /* domainSetMaxMemory */
|
|
|
|
esxDomainSetMemory, /* domainSetMemory */
|
|
|
|
esxDomainGetInfo, /* domainGetInfo */
|
|
|
|
NULL, /* domainSave */
|
|
|
|
NULL, /* domainRestore */
|
|
|
|
NULL, /* domainCoreDump */
|
|
|
|
esxDomainSetVcpus, /* domainSetVcpus */
|
vcpu: make old API trivially wrap to new API
Note - this wrapping is completely mechanical; the old API will
function identically, since the new API validates that the exact
same flags are provided by the old API. On a per-driver basis,
it may make sense to have the old API pass a different set of flags,
but that should be done in the per-driver patch that implements
the full range of flag support in the new API.
* src/esx/esx_driver.c (esxDomainSetVcpus, escDomainGetMaxVpcus):
Move guts...
(esxDomainSetVcpusFlags, esxDomainGetVcpusFlags): ...to new
functions.
(esxDriver): Trivially support the new API.
* src/openvz/openvz_driver.c (openvzDomainSetVcpus)
(openvzDomainSetVcpusFlags, openvzDomainGetMaxVcpus)
(openvzDomainGetVcpusFlags, openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDomainSetCPU)
(phypDomainSetVcpusFlags, phypGetLparCPUMAX)
(phypDomainGetVcpusFlags, phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSetVcpus)
(qemudDomainSetVcpusFlags, qemudDomainGetMaxVcpus)
(qemudDomainGetVcpusFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testSetVcpus, testDomainSetVcpusFlags)
(testDomainGetMaxVcpus, testDomainGetVcpusFlags, testDriver):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSetVcpus)
(vboxDomainSetVcpusFlags, virDomainGetMaxVcpus)
(virDomainGetVcpusFlags, virDriver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSetVcpus)
(xenUnifiedDomainSetVcpusFlags, xenUnifiedDomainGetMaxVcpus)
(xenUnifiedDomainGetVcpusFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainSetVcpus)
(xenapiDomainSetVcpusFlags, xenapiDomainGetMaxVcpus)
(xenapiDomainGetVcpusFlags, xenapiDriver): Likewise.
(xenapiError): New helper macro.
2010-09-27 22:37:53 +00:00
|
|
|
esxDomainSetVcpusFlags, /* domainSetVcpusFlags */
|
|
|
|
esxDomainGetVcpusFlags, /* domainGetVcpusFlags */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainPinVcpu */
|
|
|
|
NULL, /* domainGetVcpus */
|
|
|
|
esxDomainGetMaxVcpus, /* domainGetMaxVcpus */
|
|
|
|
NULL, /* domainGetSecurityLabel */
|
|
|
|
NULL, /* nodeGetSecurityModel */
|
|
|
|
esxDomainDumpXML, /* domainDumpXML */
|
2009-09-06 14:03:06 +00:00
|
|
|
esxDomainXMLFromNative, /* domainXMLFromNative */
|
2009-09-23 12:16:41 +00:00
|
|
|
esxDomainXMLToNative, /* domainXMLToNative */
|
2009-07-23 20:21:08 +00:00
|
|
|
esxListDefinedDomains, /* listDefinedDomains */
|
|
|
|
esxNumberOfDefinedDomains, /* numOfDefinedDomains */
|
|
|
|
esxDomainCreate, /* domainCreate */
|
2010-06-10 15:55:36 +00:00
|
|
|
esxDomainCreateWithFlags, /* domainCreateWithFlags */
|
2009-09-23 12:52:36 +00:00
|
|
|
esxDomainDefineXML, /* domainDefineXML */
|
2009-09-04 16:30:10 +00:00
|
|
|
esxDomainUndefine, /* domainUndefine */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainAttachDevice */
|
2010-01-14 01:44:26 +00:00
|
|
|
NULL, /* domainAttachDeviceFlags */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainDetachDevice */
|
2010-01-14 01:44:26 +00:00
|
|
|
NULL, /* domainDetachDeviceFlags */
|
Introduce a new virDomainUpdateDeviceFlags public API
The current virDomainAttachDevice API can be (ab)used to change
the media of an existing CDROM/Floppy device. Going forward there
will be more devices that can be configured on the fly and overloading
virDomainAttachDevice for this is not too pleasant. This patch adds
a new virDomainUpdateDeviceFlags() explicitly just for modifying
existing devices.
* include/libvirt/libvirt.h.in: Add virDomainUpdateDeviceFlags
* src/driver.h: Internal API for virDomainUpdateDeviceFlags
* src/libvirt.c, src/libvirt_public.syms: Glue public API to
driver API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
src/remote/remote_driver.c, src/test/test_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Add
stubs for new driver entry point
2010-03-22 12:23:41 +00:00
|
|
|
NULL, /* domainUpdateDeviceFlags */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainGetAutostart */
|
|
|
|
NULL, /* domainSetAutostart */
|
|
|
|
esxDomainGetSchedulerType, /* domainGetSchedulerType */
|
|
|
|
esxDomainGetSchedulerParameters, /* domainGetSchedulerParameters */
|
|
|
|
esxDomainSetSchedulerParameters, /* domainSetSchedulerParameters */
|
|
|
|
esxDomainMigratePrepare, /* domainMigratePrepare */
|
|
|
|
esxDomainMigratePerform, /* domainMigratePerform */
|
|
|
|
esxDomainMigrateFinish, /* domainMigrateFinish */
|
|
|
|
NULL, /* domainBlockStats */
|
|
|
|
NULL, /* domainInterfaceStats */
|
2009-12-20 12:28:42 +00:00
|
|
|
NULL, /* domainMemoryStats */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainBlockPeek */
|
|
|
|
NULL, /* domainMemoryPeek */
|
Internal driver API infrastructure for virDomainGetBlockInfo
This defines the internal driver API and stubs out each driver
* src/driver.h: Define virDrvDomainGetBlockInfo signature
* src/libvirt.c, src/libvirt_public.syms: Glue public API to drivers
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub out driver
2010-04-27 19:27:34 +00:00
|
|
|
NULL, /* domainGetBlockInfo */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* nodeGetCellsFreeMemory */
|
2009-09-23 12:09:44 +00:00
|
|
|
esxNodeGetFreeMemory, /* nodeGetFreeMemory */
|
2009-07-23 20:21:08 +00:00
|
|
|
NULL, /* domainEventRegister */
|
|
|
|
NULL, /* domainEventDeregister */
|
|
|
|
NULL, /* domainMigratePrepare2 */
|
|
|
|
NULL, /* domainMigrateFinish2 */
|
|
|
|
NULL, /* nodeDeviceDettach */
|
|
|
|
NULL, /* nodeDeviceReAttach */
|
|
|
|
NULL, /* nodeDeviceReset */
|
2009-09-30 10:51:54 +00:00
|
|
|
NULL, /* domainMigratePrepareTunnel */
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
esxIsEncrypted, /* isEncrypted */
|
|
|
|
esxIsSecure, /* isSecure */
|
|
|
|
esxDomainIsActive, /* domainIsActive */
|
|
|
|
esxDomainIsPersistent, /* domainIsPersistent */
|
2009-12-18 13:59:39 +00:00
|
|
|
NULL, /* cpuCompare */
|
2010-02-02 11:34:01 +00:00
|
|
|
NULL, /* cpuBaseline */
|
2010-04-07 09:23:53 +00:00
|
|
|
NULL, /* domainGetJobInfo */
|
|
|
|
NULL, /* domainAbortJob */
|
|
|
|
NULL, /* domainMigrateSetMaxDowntime */
|
|
|
|
NULL, /* domainEventRegisterAny */
|
|
|
|
NULL, /* domainEventDeregisterAny */
|
|
|
|
NULL, /* domainManagedSave */
|
|
|
|
NULL, /* domainHasManagedSaveImage */
|
|
|
|
NULL, /* domainManagedSaveRemove */
|
|
|
|
esxDomainSnapshotCreateXML, /* domainSnapshotCreateXML */
|
|
|
|
esxDomainSnapshotDumpXML, /* domainSnapshotDumpXML */
|
|
|
|
esxDomainSnapshotNum, /* domainSnapshotNum */
|
|
|
|
esxDomainSnapshotListNames, /* domainSnapshotListNames */
|
|
|
|
esxDomainSnapshotLookupByName, /* domainSnapshotLookupByName */
|
|
|
|
esxDomainHasCurrentSnapshot, /* domainHasCurrentSnapshot */
|
|
|
|
esxDomainSnapshotCurrent, /* domainSnapshotCurrent */
|
|
|
|
esxDomainRevertToSnapshot, /* domainRevertToSnapshot */
|
|
|
|
esxDomainSnapshotDelete, /* domainSnapshotDelete */
|
2010-04-13 18:02:46 +00:00
|
|
|
NULL, /* qemuDomainMonitorCommand */
|
2010-11-06 17:53:39 +00:00
|
|
|
esxDomainSetMemoryParameters, /* domainSetMemoryParameters */
|
|
|
|
esxDomainGetMemoryParameters, /* domainGetMemoryParameters */
|
2009-07-23 20:21:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxRegister(void)
|
|
|
|
{
|
2010-01-15 15:01:02 +00:00
|
|
|
if (virRegisterDriver(&esxDriver) < 0 ||
|
|
|
|
esxInterfaceRegister() < 0 ||
|
|
|
|
esxNetworkRegister() < 0 ||
|
|
|
|
esxStorageRegister() < 0 ||
|
|
|
|
esxDeviceRegister() < 0 ||
|
2010-04-14 23:38:50 +00:00
|
|
|
esxSecretRegister() < 0 ||
|
|
|
|
esxNWFilterRegister() < 0) {
|
2010-01-15 15:01:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|