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
|
|
|
*
|
2015-01-15 14:02:44 +00:00
|
|
|
* Copyright (C) 2010-2015 Red Hat, Inc.
|
2014-03-30 18:45:07 +00:00
|
|
|
* Copyright (C) 2009-2014 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "domain_conf.h"
|
2012-08-14 00:09:12 +00:00
|
|
|
#include "snapshot_conf.h"
|
2012-03-19 16:21:12 +00:00
|
|
|
#include "virauth.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2013-05-09 18:59:04 +00:00
|
|
|
#include "virfile.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "vmx.h"
|
2012-01-07 12:47:43 +00:00
|
|
|
#include "virtypedparam.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#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_private.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#include "esx_vi.h"
|
|
|
|
#include "esx_vi_methods.h"
|
|
|
|
#include "esx_util.h"
|
2014-03-30 18:45:07 +00:00
|
|
|
#include "esx_stream.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-05-09 18:59:04 +00:00
|
|
|
#include "viruri.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("esx.esx_driver");
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
static void
|
|
|
|
esxFreePrivate(esxPrivate **priv)
|
|
|
|
{
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!priv || !(*priv))
|
2011-04-10 15:18:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
esxVI_Context_Free(&(*priv)->host);
|
|
|
|
esxVI_Context_Free(&(*priv)->vCenter);
|
|
|
|
esxUtil_FreeParsedUri(&(*priv)->parsedUri);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref((*priv)->caps);
|
2013-03-31 18:03:42 +00:00
|
|
|
virObjectUnref((*priv)->xmlopt);
|
2011-04-10 15:18:32 +00:00
|
|
|
VIR_FREE(*priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/*
|
2011-05-26 15:40:51 +00:00
|
|
|
* Parse a file name from a .vmx file and convert it to datastore path format
|
|
|
|
* if possbile. A .vmx file can contain file names in various formats:
|
2010-08-07 17:58:29 +00:00
|
|
|
*
|
|
|
|
* - 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
|
|
|
|
*
|
2011-05-26 15:40:51 +00:00
|
|
|
* - There might also be absolute file names referencing files outside of a
|
|
|
|
* datastore:
|
|
|
|
*
|
|
|
|
* /usr/lib/vmware/isoimages/linux.iso
|
|
|
|
*
|
|
|
|
* Such file names are left as is and are not converted to datastore path
|
|
|
|
* format because this is not possible.
|
|
|
|
*
|
2010-08-07 17:58:29 +00:00
|
|
|
* 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
|
2010-12-21 21:39:55 +00:00
|
|
|
* function via the opaque parameter by the caller of virVMXParseConfig.
|
2010-08-07 17:58:29 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2011-05-26 15:40:51 +00:00
|
|
|
char *result = NULL;
|
2010-08-07 17:58:29 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Plain file name, use same directory as for the .vmx file */
|
2011-05-26 15:40:51 +00:00
|
|
|
if (virAsprintf(&result, "%s/%s",
|
2013-07-04 10:05:43 +00:00
|
|
|
data->datastorePathWithoutFileName, fileName) < 0)
|
2010-08-07 17:58:29 +00:00
|
|
|
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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (datastore = datastoreList; datastore;
|
2010-08-07 17:58:29 +00:00
|
|
|
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,
|
2012-11-10 07:18:07 +00:00
|
|
|
&hostMount,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-08-07 17:58:29 +00:00
|
|
|
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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!tmp)
|
2010-08-07 17:58:29 +00:00
|
|
|
continue;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Found a match. Strip leading separators */
|
2014-11-13 14:22:05 +00:00
|
|
|
while (*tmp == '/' || *tmp == '\\')
|
2010-08-07 17:58:29 +00:00
|
|
|
++tmp;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (VIR_STRDUP(strippedFileName, tmp) < 0)
|
2010-08-07 17:58:29 +00:00
|
|
|
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') {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (*tmp == '\\')
|
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
|
|
|
++tmp;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
if (virAsprintf(&result, "[%s] %s", datastoreName,
|
2013-07-04 10:05:43 +00:00
|
|
|
strippedFileName) < 0)
|
2010-08-07 17:58:29 +00:00
|
|
|
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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (VIR_STRDUP(copyOfFileName, fileName) < 0)
|
2010-08-07 17:58:29 +00:00
|
|
|
goto cleanup;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) ||
|
|
|
|
!(datastoreName = strtok_r(tmp, "/", &saveptr)) ||
|
|
|
|
!(directoryAndFileName = strtok_r(NULL, "", &saveptr))) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("File name '%s' doesn't have expected format "
|
|
|
|
"'/vmfs/volumes/<datastore>/<path>'"), fileName);
|
2010-08-07 17:58:29 +00:00
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!datastoreList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("File name '%s' refers to non-existing datastore '%s'"),
|
|
|
|
fileName, datastoreName);
|
2010-08-07 17:58:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
if (virAsprintf(&result, "[%s] %s", datastoreName,
|
2013-07-04 10:05:43 +00:00
|
|
|
directoryAndFileName) < 0)
|
2010-08-07 17:58:29 +00:00
|
|
|
goto cleanup;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
/* If it's an absolute path outside of a datastore just use it as is */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!result && *fileName == '/') {
|
2011-05-26 15:40:51 +00:00
|
|
|
/* FIXME: need to deal with Windows paths here too */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (VIR_STRDUP(result, fileName) < 0)
|
2011-05-26 15:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!result) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not handle file name '%s'"), fileName);
|
2010-08-07 17:58:29 +00:00
|
|
|
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
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-07 17:58:29 +00:00
|
|
|
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
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
return result;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 17:58:29 +00:00
|
|
|
/*
|
2011-12-04 00:06:07 +00:00
|
|
|
* This function does the inverse of esxParseVMXFileName. It takes a file name
|
2011-05-26 15:40:51 +00:00
|
|
|
* in datastore path format or in absolute format and converts it to a file
|
|
|
|
* name that can be used in a .vmx file.
|
2010-08-07 17:58:29 +00:00
|
|
|
*
|
|
|
|
* 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
|
2015-06-03 10:10:36 +00:00
|
|
|
* datastore and its mount path. Finally concatenate the mount path, directory
|
2011-10-10 20:02:06 +00:00
|
|
|
* and file name to an absolute path and return it. Detect the separator type
|
2010-08-07 17:58:29 +00:00
|
|
|
* based on the mount path.
|
|
|
|
*/
|
2010-08-05 15:43:19 +00:00
|
|
|
static char *
|
2011-05-26 15:40:51 +00:00
|
|
|
esxFormatVMXFileName(const char *fileName, void *opaque)
|
2010-08-05 15:43:19 +00:00
|
|
|
{
|
|
|
|
bool success = false;
|
2011-05-26 15:40:51 +00:00
|
|
|
char *result = NULL;
|
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
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
if (*fileName == '[') {
|
|
|
|
/* Parse datastore path and lookup datastore */
|
|
|
|
if (esxUtil_ParseDatastorePath(fileName, &datastoreName, NULL,
|
|
|
|
&directoryAndFileName) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
if (esxVI_LookupDatastoreByName(data->ctx, datastoreName, NULL, &datastore,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_LookupDatastoreHostMount(data->ctx, datastore->obj,
|
2012-11-10 07:18:07 +00:00
|
|
|
&hostMount,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2011-05-26 15:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
/* Detect separator type */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (strchr(hostMount->mountInfo->path, '\\'))
|
2011-05-26 15:40:51 +00:00
|
|
|
separator = '\\';
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
/* Strip trailing separators */
|
|
|
|
length = strlen(hostMount->mountInfo->path);
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
while (length > 0 && hostMount->mountInfo->path[length - 1] == separator)
|
2011-05-26 15:40:51 +00:00
|
|
|
--length;
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
/* Format as <mount>[/<directory>]/<file>, convert / to \ when necessary */
|
|
|
|
virBufferAdd(&buffer, hostMount->mountInfo->path, length);
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
if (separator != '/') {
|
|
|
|
tmp = directoryAndFileName;
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
while (*tmp != '\0') {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (*tmp == '/')
|
2011-05-26 15:40:51 +00:00
|
|
|
*tmp = separator;
|
2010-08-05 15:43:19 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
++tmp;
|
|
|
|
}
|
2010-08-25 09:44:57 +00:00
|
|
|
}
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
virBufferAddChar(&buffer, separator);
|
|
|
|
virBufferAdd(&buffer, directoryAndFileName, -1);
|
2010-08-07 17:58:29 +00:00
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2011-05-26 15:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = virBufferContentAndReset(&buffer);
|
|
|
|
} else if (*fileName == '/') {
|
|
|
|
/* FIXME: need to deal with Windows paths here too */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (VIR_STRDUP(result, fileName) < 0)
|
2011-05-26 15:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not handle file name '%s'"), fileName);
|
2010-08-05 15:43:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Check if referenced path/file really exists */
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-05 15:43:19 +00:00
|
|
|
if (! success) {
|
2010-08-07 17:58:29 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2011-05-26 15:40:51 +00:00
|
|
|
VIR_FREE(result);
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-05-26 15:40:51 +00:00
|
|
|
return result;
|
2010-08-05 15:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2014-03-17 19:04:43 +00:00
|
|
|
const char *src = virDomainDiskGetSource(def);
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
if (def->device != VIR_DOMAIN_DISK_DEVICE_DISK ||
|
|
|
|
def->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskGetType(def) != VIR_STORAGE_TYPE_FILE ||
|
2014-03-17 19:04:43 +00:00
|
|
|
!src || !STRPREFIX(src, "[")) {
|
2010-08-05 15:43:19 +00:00
|
|
|
/*
|
|
|
|
* This isn't a file-based SCSI disk device with a datastore related
|
|
|
|
* source path => do nothing.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-17 19:04:43 +00:00
|
|
|
if (esxVI_LookupFileInfoByDatastorePath(data->ctx, src,
|
2010-08-28 19:49:07 +00:00
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!vmDiskFileInfo || !vmDiskFileInfo->controllerType) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-03-17 19:04:43 +00:00
|
|
|
_("Could not lookup controller model for '%s'"), src);
|
2010-08-05 15:43:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualBusLogicController")) {
|
2011-09-02 13:06:15 +00:00
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_BUSLOGIC;
|
2010-08-05 15:43:19 +00:00
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualLsiLogicController")) {
|
2011-09-02 13:06:15 +00:00
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC;
|
2010-08-05 15:43:19 +00:00
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"VirtualLsiLogicSASController")) {
|
2011-09-02 13:06:15 +00:00
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1068;
|
2010-08-05 15:43:19 +00:00
|
|
|
} else if (STRCASEEQ(vmDiskFileInfo->controllerType,
|
|
|
|
"ParaVirtualSCSIController")) {
|
2011-09-02 13:06:15 +00:00
|
|
|
*model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VMPVSCSI;
|
2010-08-05 15:43:19 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Found unexpected controller model '%s' for disk '%s'"),
|
2014-03-17 19:04:43 +00:00
|
|
|
vmDiskFileInfo->controllerType, src);
|
2010-08-05 15:43:19 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
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 = '?';
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (priv->supportsLongMode != esxVI_Boolean_Undefined)
|
2009-09-23 12:29:39 +00:00
|
|
|
return priv->supportsLongMode;
|
|
|
|
|
2014-11-13 14:22:05 +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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2009-09-23 12:29:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (hostCpuIdInfo = hostCpuIdInfoList; hostCpuIdInfo;
|
2009-09-23 12:29:39 +00:00
|
|
|
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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
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;
|
2012-08-05 11:47:05 +00:00
|
|
|
char *uuid_string = NULL;
|
2010-05-26 11:05:49 +00:00
|
|
|
|
2014-11-13 14:22:05 +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,
|
2012-08-05 11:47:05 +00:00
|
|
|
&hostSystem) < 0 ||
|
|
|
|
esxVI_GetStringValue(hostSystem, "hardware.systemInfo.uuid",
|
|
|
|
&uuid_string, esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-26 11:05:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-08-05 11:47:05 +00:00
|
|
|
if (strlen(uuid_string) > 0) {
|
|
|
|
if (virUUIDParse(uuid_string, uuid) < 0) {
|
|
|
|
VIR_WARN("Could not parse host UUID from string '%s'", uuid_string);
|
2011-02-18 09:09:32 +00:00
|
|
|
|
2012-08-05 11:47:05 +00:00
|
|
|
/* HostSystem has an invalid UUID, ignore it */
|
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
2010-05-26 11:05:49 +00:00
|
|
|
}
|
2012-08-05 11:47:05 +00:00
|
|
|
} else {
|
|
|
|
/* HostSystem has an empty UUID */
|
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
2010-05-26 11:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-05-26 11:05:49 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (supportsLongMode == esxVI_Boolean_Undefined)
|
2009-09-23 12:29:39 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (supportsLongMode == esxVI_Boolean_True) {
|
2014-07-14 12:56:13 +00:00
|
|
|
caps = virCapabilitiesNew(VIR_ARCH_X86_64, true, true);
|
2009-09-23 12:29:39 +00:00
|
|
|
} else {
|
2014-07-14 12:56:13 +00:00
|
|
|
caps = virCapabilitiesNew(VIR_ARCH_I686, true, true);
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!caps)
|
2009-09-04 16:25:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0)
|
2010-05-26 11:05:49 +00:00
|
|
|
goto failure;
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
/* i686 */
|
2015-04-17 22:09:16 +00:00
|
|
|
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
|
2012-12-10 22:28:09 +00:00
|
|
|
VIR_ARCH_I686,
|
|
|
|
NULL, NULL, 0,
|
2009-09-23 12:29:39 +00:00
|
|
|
NULL);
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!guest)
|
2009-09-04 16:25:27 +00:00
|
|
|
goto failure;
|
|
|
|
|
2015-04-17 22:38:10 +00:00
|
|
|
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL))
|
2009-09-04 16:25:27 +00:00
|
|
|
goto failure;
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
/* x86_64 */
|
|
|
|
if (supportsLongMode == esxVI_Boolean_True) {
|
2015-04-17 22:09:16 +00:00
|
|
|
guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
|
2012-12-10 22:28:09 +00:00
|
|
|
VIR_ARCH_X86_64,
|
|
|
|
NULL, NULL,
|
2009-09-23 12:29:39 +00:00
|
|
|
0, NULL);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!guest)
|
2009-09-23 12:29:39 +00:00
|
|
|
goto failure;
|
|
|
|
|
2015-04-17 22:38:10 +00:00
|
|
|
if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL))
|
2009-09-23 12:29:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
return caps;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
failure:
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2009-09-04 16:25:27 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
static int
|
2013-01-10 21:32:13 +00:00
|
|
|
esxConnectToHost(esxPrivate *priv,
|
|
|
|
virConnectPtr conn,
|
2012-03-20 11:11:10 +00:00
|
|
|
virConnectAuthPtr auth,
|
2010-07-18 15:27:05 +00:00
|
|
|
char **vCenterIpAddress)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char ipAddress[NI_MAXHOST] = "";
|
|
|
|
char *username = NULL;
|
2011-03-03 21:11:24 +00:00
|
|
|
char *unescapedPassword = NULL;
|
2010-07-18 15:27:05 +00:00
|
|
|
char *password = NULL;
|
|
|
|
char *url = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_Boolean inMaintenanceMode = esxVI_Boolean_Undefined;
|
2014-10-18 22:11:13 +00:00
|
|
|
esxVI_ProductLine expectedProductLine = STRCASEEQ(conn->uri->scheme, "esx")
|
|
|
|
? esxVI_ProductLine_ESX
|
|
|
|
: esxVI_ProductLine_GSX;
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!vCenterIpAddress || *vCenterIpAddress) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-07-18 15:27:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxUtil_ResolveHostname(conn->uri->server, ipAddress, NI_MAXHOST) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (conn->uri->user) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(username, conn->uri->user) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
2012-03-20 11:11:10 +00:00
|
|
|
username = virAuthGetUsername(conn, auth, "esx", "root", conn->uri->server);
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!username) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 11:11:10 +00:00
|
|
|
unescapedPassword = virAuthGetPassword(conn, auth, "esx", username, conn->uri->server);
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!unescapedPassword) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:11:24 +00:00
|
|
|
password = esxUtil_EscapeForXml(unescapedPassword);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!password)
|
2011-03-03 21:11:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
|
2013-07-04 10:05:43 +00:00
|
|
|
conn->uri->server, conn->uri->port) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (esxVI_Context_Alloc(&priv->host) < 0 ||
|
|
|
|
esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
|
2011-04-10 15:18:32 +00:00
|
|
|
priv->parsedUri) < 0 ||
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Context_LookupManagedObjects(priv->host) < 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
if (priv->host->productLine != expectedProductLine) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting '%s' to be a %s host but found a %s host"),
|
|
|
|
conn->uri->server,
|
|
|
|
esxVI_ProductLineToDisplayName(expectedProductLine),
|
|
|
|
esxVI_ProductLineToDisplayName(priv->host->productLine));
|
|
|
|
goto cleanup;
|
2010-07-18 15:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (inMaintenanceMode == esxVI_Boolean_True)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("The server is in maintenance mode");
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0)
|
|
|
|
goto cleanup;
|
2010-07-18 15:27:05 +00:00
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_FREE(username);
|
2011-03-03 21:11:24 +00:00
|
|
|
VIR_FREE(unescapedPassword);
|
|
|
|
VIR_FREE(password);
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_FREE(url);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-01-10 21:32:13 +00:00
|
|
|
esxConnectToVCenter(esxPrivate *priv,
|
|
|
|
virConnectPtr conn,
|
2012-03-20 11:11:10 +00:00
|
|
|
virConnectAuthPtr auth,
|
|
|
|
const char *hostname,
|
2011-04-10 15:18:32 +00:00
|
|
|
const char *hostSystemIpAddress)
|
2010-07-18 15:27:05 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char ipAddress[NI_MAXHOST] = "";
|
|
|
|
char *username = NULL;
|
2011-03-03 21:11:24 +00:00
|
|
|
char *unescapedPassword = NULL;
|
2010-07-18 15:27:05 +00:00
|
|
|
char *password = NULL;
|
|
|
|
char *url = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostSystemIpAddress &&
|
|
|
|
(!priv->parsedUri->path || STREQ(priv->parsedUri->path, "/"))) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Path has to specify the datacenter and compute resource"));
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (conn->uri->user) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (VIR_STRDUP(username, conn->uri->user) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
2012-03-20 11:11:10 +00:00
|
|
|
username = virAuthGetUsername(conn, auth, "esx", "administrator", hostname);
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!username) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed"));
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 11:11:10 +00:00
|
|
|
unescapedPassword = virAuthGetPassword(conn, auth, "esx", username, hostname);
|
2010-07-18 15:27:05 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!unescapedPassword) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-03-03 21:11:24 +00:00
|
|
|
password = esxUtil_EscapeForXml(unescapedPassword);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!password)
|
2011-03-03 21:11:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
|
2013-07-04 10:05:43 +00:00
|
|
|
hostname, conn->uri->port) < 0)
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
|
|
|
|
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
|
2011-04-10 15:18:32 +00:00
|
|
|
password, priv->parsedUri) < 0) {
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
if (priv->vCenter->productLine != esxVI_ProductLine_VPX) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-10-18 22:11:13 +00:00
|
|
|
_("Expecting '%s' to be a %s host but found a %s host"),
|
|
|
|
hostname,
|
|
|
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
|
|
|
esxVI_ProductLineToDisplayName(priv->vCenter->productLine));
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (hostSystemIpAddress) {
|
2011-11-01 16:12:37 +00:00
|
|
|
if (esxVI_Context_LookupManagedObjectsByHostSystemIp
|
|
|
|
(priv->vCenter, hostSystemIpAddress) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-01 16:12:37 +00:00
|
|
|
if (esxVI_Context_LookupManagedObjectsByPath(priv->vCenter,
|
|
|
|
priv->parsedUri->path) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_FREE(username);
|
2011-03-03 21:11:24 +00:00
|
|
|
VIR_FREE(unescapedPassword);
|
|
|
|
VIR_FREE(password);
|
2010-07-18 15:27:05 +00:00
|
|
|
VIR_FREE(url);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
/*
|
2011-11-01 16:12:37 +00:00
|
|
|
* URI format: {vpx|esx|gsx}://[<username>@]<hostname>[:<port>]/[<path>][?<query parameter>...]
|
|
|
|
* <path> = [<folder>/...]<datacenter>/[<folder>/...]<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
|
2011-11-01 16:12:37 +00:00
|
|
|
* can be omitted. As datacenters and computeresources can be organized in
|
|
|
|
* folders those have to be included in <path>.
|
2010-07-31 21:57:42 +00:00
|
|
|
*
|
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
|
2014-05-05 09:49:24 +00:00
|
|
|
* of the server's certificate. The default value is 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
|
2014-05-05 09:49:24 +00:00
|
|
|
* questions will be reported as errors. The default value is 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
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
|
|
|
unsigned int flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
|
2011-09-27 11:08:09 +00:00
|
|
|
char *plus;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxPrivate *priv = 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
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2011-09-27 11:08:09 +00:00
|
|
|
/* Decline if the URI is NULL or the scheme is NULL */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!conn->uri || !conn->uri->scheme)
|
2009-07-23 20:21:08 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
2011-09-27 11:08:09 +00:00
|
|
|
/* Decline if the scheme is not one of {vpx|esx|gsx} */
|
|
|
|
plus = strchr(conn->uri->scheme, '+');
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!plus) {
|
2011-09-27 11:08:09 +00:00
|
|
|
if (STRCASENEQ(conn->uri->scheme, "vpx") &&
|
|
|
|
STRCASENEQ(conn->uri->scheme, "esx") &&
|
|
|
|
STRCASENEQ(conn->uri->scheme, "gsx")) {
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (plus - conn->uri->scheme != 3 ||
|
|
|
|
(STRCASENEQLEN(conn->uri->scheme, "vpx", 3) &&
|
|
|
|
STRCASENEQLEN(conn->uri->scheme, "esx", 3) &&
|
|
|
|
STRCASENEQLEN(conn->uri->scheme, "gsx", 3))) {
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Transport '%s' in URI scheme is not supported, try again "
|
|
|
|
"without the transport part"), plus + 1);
|
2011-09-27 11:08:09 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-11-01 16:12:37 +00:00
|
|
|
if (STRCASENEQ(conn->uri->scheme, "vpx") &&
|
2013-10-17 17:04:11 +00:00
|
|
|
conn->uri->path && STRNEQ(conn->uri->path, "/")) {
|
2011-11-01 16:12:37 +00:00
|
|
|
VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'",
|
|
|
|
conn->uri->path, conn->uri->scheme);
|
|
|
|
}
|
|
|
|
|
2011-05-25 13:52:34 +00:00
|
|
|
/* Require server part */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!conn->uri->server) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("URI is missing the server part"));
|
2011-05-25 13:52:34 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Require auth */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!auth || !auth->cb) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Missing or invalid auth pointer"));
|
2011-05-25 13:52:34 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate per-connection private data */
|
2013-07-04 10:05:43 +00:00
|
|
|
if (VIR_ALLOC(priv) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0)
|
2010-06-03 18:04:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
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;
|
2014-03-30 18:45:07 +00:00
|
|
|
priv->supportsScreenshot = esxVI_Boolean_Undefined;
|
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")) {
|
2011-04-10 15:18:32 +00:00
|
|
|
if (STRCASEEQ(priv->parsedUri->transport, "https")) {
|
2009-09-23 13:00:02 +00:00
|
|
|
conn->uri->port = 443;
|
|
|
|
} else {
|
|
|
|
conn->uri->port = 80;
|
|
|
|
}
|
|
|
|
} else { /* GSX */
|
2011-04-10 15:18:32 +00:00
|
|
|
if (STRCASEEQ(priv->parsedUri->transport, "https")) {
|
2009-09-23 13:00:02 +00:00
|
|
|
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 */
|
2013-01-10 21:32:13 +00:00
|
|
|
if (esxConnectToHost(priv, conn, auth,
|
2010-07-18 15:27:05 +00:00
|
|
|
&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 */
|
2013-10-18 18:36:39 +00:00
|
|
|
if (priv->parsedUri->vCenter) {
|
2011-04-10 15:18:32 +00:00
|
|
|
if (STREQ(priv->parsedUri->vCenter, "*")) {
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!potentialVCenterIpAddress) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virStrcpyStatic(vCenterIpAddress,
|
|
|
|
potentialVCenterIpAddress)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("vCenter IP address %s too big for destination"),
|
|
|
|
potentialVCenterIpAddress);
|
2010-07-18 15:27:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
2011-04-10 15:18:32 +00:00
|
|
|
if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
|
2010-07-18 15:27:05 +00:00
|
|
|
vCenterIpAddress, NI_MAXHOST) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-11-18 23:08:13 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (potentialVCenterIpAddress &&
|
2010-07-18 15:27:05 +00:00
|
|
|
STRNEQ(vCenterIpAddress, potentialVCenterIpAddress)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("This host is managed by a vCenter with IP "
|
|
|
|
"address %s, but a mismachting vCenter '%s' "
|
|
|
|
"(%s) has been specified"),
|
|
|
|
potentialVCenterIpAddress, priv->parsedUri->vCenter,
|
|
|
|
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
|
|
|
|
2013-01-10 21:32:13 +00:00
|
|
|
if (esxConnectToVCenter(priv, conn, auth,
|
2012-03-20 11:11:10 +00:00
|
|
|
vCenterIpAddress,
|
2011-04-10 15:18:32 +00:00
|
|
|
priv->host->ipAddress) < 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 */
|
2013-01-10 21:32:13 +00:00
|
|
|
if (esxConnectToVCenter(priv, conn, auth,
|
2012-03-20 11:11:10 +00:00
|
|
|
conn->uri->server,
|
|
|
|
NULL) < 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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!priv->caps)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
if (!(priv->xmlopt = virVMXDomainXMLConfInit()))
|
2013-03-05 15:17:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-10 21:32:13 +00:00
|
|
|
conn->privateData = priv;
|
|
|
|
priv = NULL;
|
2010-05-19 20:59:32 +00:00
|
|
|
result = VIR_DRV_OPEN_SUCCESS;
|
2009-11-18 23:08:13 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2013-01-10 21:32:13 +00:00
|
|
|
esxFreePrivate(&priv);
|
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
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectClose(virConnectPtr conn)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (priv->host) {
|
2010-07-18 15:27:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->host) < 0 ||
|
|
|
|
esxVI_Logout(priv->host) < 0) {
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (priv->vCenter) {
|
2010-03-03 10:22:46 +00:00
|
|
|
if (esxVI_EnsureSession(priv->vCenter) < 0 ||
|
|
|
|
esxVI_Logout(priv->vCenter) < 0) {
|
|
|
|
result = -1;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
esxFreePrivate(&priv);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (priv->supportsVMotion != esxVI_Boolean_Undefined)
|
2009-08-06 13:15:45 +00:00
|
|
|
return priv->supportsVMotion;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +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,
|
2012-08-05 11:47:05 +00:00
|
|
|
&hostSystem) < 0 ||
|
|
|
|
esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
|
2010-07-31 21:57:42 +00:00
|
|
|
&priv->supportsVMotion,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-30 18:45:07 +00:00
|
|
|
static esxVI_Boolean
|
|
|
|
esxSupportsScreenshot(esxPrivate *priv)
|
|
|
|
{
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
|
|
|
|
if (priv->supportsScreenshot != esxVI_Boolean_Undefined)
|
|
|
|
return priv->supportsScreenshot;
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
|
|
|
return esxVI_Boolean_Undefined;
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"capability.screenshotSupported") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0 ||
|
|
|
|
esxVI_GetBoolean(hostSystem, "capability.screenshotSupported",
|
|
|
|
&priv->supportsScreenshot,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/*
|
|
|
|
* If we goto cleanup in case of an error then priv->supportsScreenshot is
|
|
|
|
* still esxVI_Boolean_Undefined, therefore we don't need to set it.
|
|
|
|
*/
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return priv->supportsScreenshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectSupportsFeature(virConnectPtr conn, int feature)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
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
|
|
|
|
2014-11-13 14:22:05 +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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
return priv->vCenter &&
|
2009-08-06 13:15:45 +00:00
|
|
|
supportsVMotion == esxVI_Boolean_True ? 1 : 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
return "ESX";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectGetVersion(virConnectPtr conn, unsigned long *version)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
*version = priv->primary->productVersion;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectGetHostname(virConnectPtr conn)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostName || strlen(hostName) < 1) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!domainName || strlen(domainName) < 1) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(complete, hostName) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-01-16 00:08:27 +00:00
|
|
|
} else {
|
2013-07-04 10:05:43 +00:00
|
|
|
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +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,
|
2013-05-03 12:41:53 +00:00
|
|
|
* either VIR_STRDUP returned -1 or virAsprintf failed. When virAsprintf
|
2010-05-19 20:59:32 +00:00
|
|
|
* 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;
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(nodeinfo, 0, sizeof(*nodeinfo));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
"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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virStrncpy(nodeinfo->model, dynamicProperty->val->string,
|
|
|
|
sizeof(nodeinfo->model) - 1,
|
|
|
|
sizeof(nodeinfo->model))) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU Model %s too long for destination"),
|
|
|
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:25:27 +00:00
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectGetCapabilities(virConnectPtr conn)
|
2009-09-04 16:25:27 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-09-04 16:25:27 +00:00
|
|
|
|
2014-06-27 07:55:44 +00:00
|
|
|
return virCapabilitiesFormatXML(priv->caps);
|
2009-09-04 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectListDomains(virConnectPtr conn, int *ids, int maxids)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (maxids == 0)
|
2009-07-23 20:21:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn)
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (esxUtil_ParseVirtualMachineIDString(virtualMachine->obj->value,
|
|
|
|
&ids[count]) < 0 ||
|
|
|
|
ids[count] <= 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to parse positive integer from '%s'"),
|
|
|
|
virtualMachine->obj->value);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (count >= maxids)
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
success = true;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectNumOfDomains(virConnectPtr conn)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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
|
2011-05-01 19:57:45 +00:00
|
|
|
(priv->primary, esxVI_VirtualMachinePowerState_PoweredOn, false);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
2009-07-23 20:21:08 +00:00
|
|
|
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 */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (powerState == esxVI_VirtualMachinePowerState_PoweredOff)
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!domain)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
domain->id = id;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!domain)
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!domain)
|
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
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virtualMachine) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!domain)
|
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
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
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-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not suspend domain: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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_Suspended) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not resume domain: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-10-05 17:31:55 +00:00
|
|
|
esxDomainShutdownFlags(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;
|
|
|
|
|
2011-10-05 17:31:55 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22: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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22: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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-05 17:31:55 +00:00
|
|
|
static int
|
|
|
|
esxDomainShutdown(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return esxDomainShutdownFlags(domain, 0);
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
static int
|
2011-07-06 22:14:33 +00:00
|
|
|
esxDomainReboot(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;
|
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22: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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22: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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-07-20 16:45:21 +00:00
|
|
|
esxDomainDestroyFlags(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-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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-07-20 16:45:21 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (priv->vCenter) {
|
2009-12-12 19:51:35 +00:00
|
|
|
ctx = priv->vCenter;
|
|
|
|
} else {
|
|
|
|
ctx = priv->host;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not destroy domain: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-20 16:45:21 +00:00
|
|
|
static int
|
|
|
|
esxDomainDestroy(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return esxDomainDestroyFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
static char *
|
2010-01-15 22:05:26 +00:00
|
|
|
esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2013-05-03 12:41:53 +00:00
|
|
|
char *osType;
|
2009-08-06 13:07:46 +00:00
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
ignore_value(VIR_STRDUP(osType, "hvm"));
|
2009-08-06 13:07:46 +00:00
|
|
|
return osType;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
xml: use long long internally, to centralize overflow checks
On 64-bit platforms, unsigned long and unsigned long long are
identical, so we don't have to worry about overflow checks.
On 32-bit platforms, anywhere we narrow unsigned long long back
to unsigned long, we have to worry about overflow; it's easier
to do this in one place by having most of the code use the same
or wider types, and only doing the narrowing at the last minute.
Therefore, the memory set commands remain unsigned long, and
the memory get command now centralizes the overflow check into
libvirt.c, so that drivers don't have to repeat the work.
This also fixes a bug where xen returned the wrong value on
failure (most APIs return -1 on failure, but getMaxMemory
must return 0 on failure).
* src/driver.h (virDrvDomainGetMaxMemory): Use long long.
* src/libvirt.c (virDomainGetMaxMemory): Raise overflow.
* src/test/test_driver.c (testGetMaxMemory): Fix driver.
* src/rpc/gendispatch.pl (name_to_ProcName): Likewise.
* src/xen/xen_hypervisor.c (xenHypervisorGetMaxMemory): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetMaxMemory): Likewise.
* src/xen/xend_internal.c (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xend_internal.h (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xm_internal.c (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.c (xenStoreDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.h (xenStoreDomainGetMaxMemory): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainGetMaxMemory):
Likewise.
* src/esx/esx_driver.c (esxDomainGetMaxMemory): Likewise.
* src/libxl/libxl_driver.c (libxlDomainGetMaxMemory): Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetMaxMemory): Likewise.
* src/lxc/lxc_driver.c (lxcDomainGetMaxMemory): Likewise.
* src/uml/uml_driver.c (umlDomainGetMaxMemory): Likewise.
2012-03-03 00:47:16 +00:00
|
|
|
static unsigned long long
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Got invalid memory size %d"),
|
|
|
|
dynamicProperty->val->int32);
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
|
|
|
memoryMB = dynamicProperty->val->int32;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2011-01-27 21:01:43 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2011-01-27 21:01:43 +00:00
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2011-01-27 21:01:43 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"runtime.powerState") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
|
|
|
(priv->primary, domain->uuid, propertyNameList, &virtualMachine,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer) < 0 ||
|
2011-01-27 21:01:43 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered off"));
|
2011-01-27 21:01:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Long_Alloc(&spec->memoryMB) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:19:59 +00:00
|
|
|
/* max-memory must be a multiple of 4096 kilobyte */
|
2009-07-23 20:21:08 +00:00
|
|
|
spec->memoryMB->value =
|
2011-01-28 20:19:59 +00:00
|
|
|
VIR_DIV_UP(memory, 4096) * 4; /* Scale from kilobytes to megabytes */
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not set max-memory to %lu kilobytes: %s"), memory,
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-01-27 21:01:43 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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 =
|
2011-01-28 21:03:24 +00:00
|
|
|
VIR_DIV_UP(memory, 1024); /* Scale from kilobytes to megabytes */
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not set memory to %lu kilobytes: %s"), memory,
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-04 06:34:31 +00:00
|
|
|
/*
|
|
|
|
* libvirt exposed virtual CPU usage in absolute time, ESX doesn't provide this
|
|
|
|
* information in this format. It exposes it in 20 seconds slots, but it's hard
|
|
|
|
* to get a reliable absolute time from this. Therefore, disable the code that
|
|
|
|
* queries the performance counters here for now, but keep it as example for how
|
|
|
|
* to query a selected performance counter for its values.
|
|
|
|
*/
|
|
|
|
#define ESX_QUERY_FOR_USED_CPU_TIME 0
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2011-05-04 06:34:31 +00:00
|
|
|
#if ESX_QUERY_FOR_USED_CPU_TIME
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2011-05-04 06:34:31 +00:00
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(info, 0, sizeof(*info));
|
2010-05-19 20:59:32 +00:00
|
|
|
|
2014-11-13 14:22: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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (memory_limit > 0)
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2011-05-04 06:34:31 +00:00
|
|
|
#if ESX_QUERY_FOR_USED_CPU_TIME
|
2009-07-23 20:21:08 +00:00
|
|
|
/* 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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (priv->host) {
|
2010-07-18 15:27:05 +00:00
|
|
|
if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_Int_Alloc(&counterId) < 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
|
|
|
counterId->value = priv->usedCpuTimeCounterId;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_Int_AppendToList(&counterIdList, counterId) < 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
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (perfMetricId = perfMetricIdList; perfMetricId;
|
2010-07-18 15:27:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (perfCounterInfo = perfCounterInfoList; perfCounterInfo;
|
2010-07-18 15:27:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (priv->usedCpuTimeCounterId < 0)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("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) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (perfEntityMetricBase = perfEntityMetricBaseList;
|
2013-10-17 17:04:11 +00:00
|
|
|
perfEntityMetricBase;
|
2010-07-18 15:27:05 +00:00
|
|
|
perfEntityMetricBase = perfEntityMetricBase->_next) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!perfEntityMetric) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("QueryPerf returned object with unexpected type '%s'"),
|
|
|
|
esxVI_Type_ToString(perfEntityMetricBase->_type));
|
2011-05-04 06:27:57 +00:00
|
|
|
goto cleanup;
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!perfMetricIntSeries) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("QueryPerf returned object with unexpected type '%s'"),
|
|
|
|
esxVI_Type_ToString(perfEntityMetric->value->_type));
|
2011-05-04 06:27:57 +00:00
|
|
|
goto cleanup;
|
2010-07-18 15:27:05 +00:00
|
|
|
}
|
2010-03-06 16:56:28 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (; perfMetricIntSeries;
|
2010-07-18 15:27:05 +00:00
|
|
|
perfMetricIntSeries = perfMetricIntSeries->_next) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("perfMetricIntSeries ...");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
for (value = perfMetricIntSeries->value;
|
2013-10-17 17:04:11 +00:00
|
|
|
value;
|
2010-07-18 15:27:05 +00:00
|
|
|
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
|
|
|
VIR_DEBUG("usedCpuTimeCounterId %d END", priv->usedCpuTimeCounterId);
|
2010-05-19 20:59:32 +00:00
|
|
|
|
2010-07-18 15:27:05 +00:00
|
|
|
/*
|
2011-04-28 14:14:09 +00:00
|
|
|
* FIXME: Cannot map between relative used-cpu-time and absolute
|
2010-07-18 15:27:05 +00:00
|
|
|
* info->cpuTime
|
|
|
|
*/
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2011-05-04 06:34:31 +00:00
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-05-04 06:34:31 +00:00
|
|
|
#if ESX_QUERY_FOR_USED_CPU_TIME
|
2011-05-04 06:27:57 +00:00
|
|
|
/*
|
|
|
|
* Remove values owned by data structures to prevent them from being freed
|
|
|
|
* by the call to esxVI_PerfQuerySpec_Free().
|
|
|
|
*/
|
2013-10-17 17:04:11 +00:00
|
|
|
if (querySpec) {
|
2011-05-04 06:27:57 +00:00
|
|
|
querySpec->entity = NULL;
|
|
|
|
querySpec->format = NULL;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (querySpec->metricId)
|
2011-05-04 06:27:57 +00:00
|
|
|
querySpec->metricId->instance = NULL;
|
|
|
|
}
|
2011-05-04 06:34:31 +00:00
|
|
|
#endif
|
2011-05-04 06:27:57 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
2011-05-04 06:34:31 +00:00
|
|
|
#if ESX_QUERY_FOR_USED_CPU_TIME
|
2009-07-23 20:21:08 +00:00
|
|
|
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);
|
2011-05-04 06:34:31 +00:00
|
|
|
#endif
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-02 09:35:29 +00:00
|
|
|
static int
|
|
|
|
esxDomainGetState(virDomainPtr domain,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2011-05-02 09:35:29 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"runtime.powerState") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
propertyNameList, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
*state = esxVI_VirtualMachinePowerState_ConvertToLibvirt(powerState);
|
|
|
|
|
|
|
|
if (reason)
|
|
|
|
*reason = 0;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-05-02 09:35:29 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-30 18:45:07 +00:00
|
|
|
static char *
|
|
|
|
esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
|
|
|
|
unsigned int screen, unsigned int flags)
|
|
|
|
{
|
|
|
|
char *mimeType = NULL;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_Boolean supportsScreenshot = esxVI_Boolean_Undefined;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *url = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (screen != 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Screen cannot be selected"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
supportsScreenshot = esxSupportsScreenshot(priv);
|
|
|
|
|
|
|
|
if (supportsScreenshot == esxVI_Boolean_Undefined)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (supportsScreenshot != esxVI_Boolean_True) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("Screenshot feature is unsupported"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"runtime.powerState") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
propertyNameList, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Domain is not powered on"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build URL */
|
|
|
|
virBufferAsprintf(&buffer, "%s://%s:%d/screen?id=", priv->parsedUri->transport,
|
|
|
|
domain->conn->uri->server, domain->conn->uri->port);
|
|
|
|
virBufferURIEncodeString(&buffer, virtualMachine->obj->value);
|
|
|
|
|
|
|
|
if (virBufferCheckError(&buffer))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
url = virBufferContentAndReset(&buffer);
|
|
|
|
|
|
|
|
if (VIR_STRDUP(mimeType, "image/png") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (esxStreamOpenDownload(stream, priv, url, 0, 0) < 0) {
|
|
|
|
VIR_FREE(mimeType);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
if (flags != VIR_DOMAIN_AFFECT_LIVE) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
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
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
if (nvcpus < 1) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2014-11-13 14:22:05 +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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Requested number of virtual CPUs is greater than max "
|
|
|
|
"allowable number of virtual CPUs for the domain: %d > %d"),
|
|
|
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not set number of virtual CPUs to %d: %s"), nvcpus,
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-30 11:54:20 +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
|
|
|
|
esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return esxDomainSetVcpusFlags(domain, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
|
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
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-12-30 11:54:20 +00:00
|
|
|
|
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;
|
|
|
|
|
2011-06-08 06:33:33 +00:00
|
|
|
if (flags != (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
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
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (priv->maxVcpus > 0)
|
2009-08-06 13:15:45 +00:00
|
|
|
return priv->maxVcpus;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
priv->maxVcpus = -1;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
"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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
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->maxVcpus;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 11:54:20 +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)
|
|
|
|
{
|
2011-06-08 06:33:33 +00:00
|
|
|
return esxDomainGetVcpusFlags(domain, (VIR_DOMAIN_AFFECT_LIVE |
|
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
|
|
|
VIR_DOMAIN_VCPU_MAXIMUM));
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-12-30 11:54:20 +00:00
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static char *
|
2011-07-06 20:40:19 +00:00
|
|
|
esxDomainGetXMLDesc(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 *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-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Data data;
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
/* Flags checked by virDomainDefFormat */
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2011-07-12 09:34:55 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
|
2009-09-04 15:55:55 +00:00
|
|
|
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=");
|
2011-11-01 16:12:37 +00:00
|
|
|
virBufferURIEncodeString(&buffer, priv->primary->datacenterPath);
|
2009-09-04 15:55:55 +00:00
|
|
|
virBufferAddLit(&buffer, "&dsName=");
|
|
|
|
virBufferURIEncodeString(&buffer, datastoreName);
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 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
|
|
|
url = virBufferContentAndReset(&buffer);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_CURL_Download(priv->primary->curl, url, &vmx, 0, NULL) < 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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!directoryName) {
|
2010-08-25 09:44:57 +00:00
|
|
|
if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]",
|
2013-07-04 10:05:43 +00:00
|
|
|
datastoreName) < 0)
|
2010-08-25 09:44:57 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s",
|
2013-07-04 10:05:43 +00:00
|
|
|
datastoreName, directoryName) < 0)
|
2010-08-25 09:44:57 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-05 15:43:19 +00:00
|
|
|
|
|
|
|
ctx.opaque = &data;
|
|
|
|
ctx.parseFileName = esxParseVMXFileName;
|
|
|
|
ctx.formatFileName = NULL;
|
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
def = virVMXParseConfig(&ctx, priv->xmlopt, vmx);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (def) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff)
|
2010-08-20 18:42:45 +00:00
|
|
|
def->id = id;
|
|
|
|
|
2014-11-18 16:44:00 +00:00
|
|
|
xml = virDomainDefFormat(def,
|
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!url)
|
2010-05-19 20:59:32 +00:00
|
|
|
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 *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
|
|
|
|
const char *nativeConfig,
|
|
|
|
unsigned int flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Data data;
|
2009-07-23 20:21:08 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2011-07-12 09:34:55 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
if (STRNEQ(nativeFormat, "vmware-vmx")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("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;
|
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (def)
|
2014-11-18 16:44:00 +00:00
|
|
|
xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-23 12:16:41 +00:00
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
|
|
|
|
const char *domainXml,
|
|
|
|
unsigned int flags)
|
2009-09-23 12:16:41 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-12-21 21:39:55 +00:00
|
|
|
int virtualHW_version;
|
|
|
|
virVMXContext ctx;
|
2010-08-05 15:43:19 +00:00
|
|
|
esxVMX_Data data;
|
2009-09-23 12:16:41 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *vmx = NULL;
|
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2011-07-12 09:34:55 +00:00
|
|
|
|
2009-09-23 12:16:41 +00:00
|
|
|
if (STRNEQ(nativeFormat, "vmware-vmx")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Unsupported config format '%s'"), nativeFormat);
|
2009-09-23 12:16:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion
|
2014-10-18 22:11:13 +00:00
|
|
|
(priv->primary->productLine, priv->primary->productVersion);
|
2010-12-21 21:39:55 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (virtualHW_version < 0)
|
2010-12-21 21:39:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
def = virDomainDefParseString(domainXml, priv->caps, priv->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
2009-09-23 12:16:41 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!def)
|
2009-09-23 12:16:41 +00:00
|
|
|
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;
|
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
vmx = virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version);
|
2009-09-23 12:16:41 +00:00
|
|
|
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return vmx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
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;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (maxnames == 0)
|
2009-07-23 20:21:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (powerState == esxVI_VirtualMachinePowerState_PoweredOn)
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (count >= maxnames)
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
success = true;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (! success) {
|
2014-11-13 14:22:05 +00:00
|
|
|
for (i = 0; i < count; ++i)
|
2010-05-19 20:59:32 +00:00
|
|
|
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
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectNumOfDefinedDomains(virConnectPtr conn)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22: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
|
2011-05-01 19:57:45 +00:00
|
|
|
(priv->primary, esxVI_VirtualMachinePowerState_PoweredOn, true);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-06-10 15:55:36 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22: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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not start domain: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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
|
2014-11-18 14:19:38 +00:00
|
|
|
esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
|
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;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-10-18 19:21:46 +00:00
|
|
|
virDomainDiskDefPtr disk = NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
int virtualHW_version;
|
|
|
|
virVMXContext ctx;
|
2010-08-05 15:43:19 +00:00
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-09-23 12:52:36 +00:00
|
|
|
virDomainPtr domain = NULL;
|
2014-03-17 19:04:43 +00:00
|
|
|
const char *src;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2009-09-23 12:52:36 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2011-07-12 09:34:55 +00:00
|
|
|
|
2014-11-13 14:22:05 +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 */
|
2013-03-28 13:55:55 +00:00
|
|
|
def = virDomainDefParseString(xml, priv->caps, priv->xmlopt,
|
2014-11-18 17:34:42 +00:00
|
|
|
parse_flags);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!def)
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virtualMachine &&
|
2010-10-12 17:37:39 +00:00
|
|
|
esxVI_LookupVirtualMachineByName(priv->primary, def->name, NULL,
|
|
|
|
&virtualMachine,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (virtualMachine) {
|
2009-09-23 12:52:36 +00:00
|
|
|
/* FIXME */
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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-12-21 21:39:55 +00:00
|
|
|
virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion
|
2014-10-18 22:11:13 +00:00
|
|
|
(priv->primary->productLine, priv->primary->productVersion);
|
2010-12-21 21:39:55 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (virtualHW_version < 0)
|
2010-12-21 21:39:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
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;
|
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
vmx = virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!vmx)
|
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
|
2014-04-20 20:07:46 +00:00
|
|
|
* first disk, because it may be CDROM disk and ISO images are normally not
|
2009-10-18 19:21:46 +00:00
|
|
|
* 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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 &&
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskGetType(def->disks[i]) == VIR_STORAGE_TYPE_FILE) {
|
2009-10-18 19:21:46 +00:00
|
|
|
disk = def->disks[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!disk) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-03-17 19:04:43 +00:00
|
|
|
src = virDomainDiskGetSource(disk);
|
|
|
|
if (!src) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-03-17 19:04:43 +00:00
|
|
|
if (esxUtil_ParseDatastorePath(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
|
|
|
}
|
|
|
|
|
2014-03-17 19:04:43 +00:00
|
|
|
if (! virFileHasSuffix(src, ".vmdk")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting source '%s' of first file-based harddisk to "
|
2014-03-17 19:04:43 +00:00
|
|
|
"be a VMDK image"), src);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
|
2009-09-23 12:52:36 +00:00
|
|
|
conn->uri->server, conn->uri->port);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (directoryName) {
|
2009-09-23 12:52:36 +00:00
|
|
|
virBufferURIEncodeString(&buffer, directoryName);
|
|
|
|
virBufferAddChar(&buffer, '/');
|
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
escapedName = esxUtil_EscapeDatastoreItem(def->name);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!escapedName)
|
2010-10-12 17:37:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virBufferURIEncodeString(&buffer, escapedName);
|
2009-09-23 12:52:36 +00:00
|
|
|
virBufferAddLit(&buffer, ".vmx?dcPath=");
|
2011-11-01 16:12:37 +00:00
|
|
|
virBufferURIEncodeString(&buffer, priv->primary->datacenterPath);
|
2009-09-23 12:52:36 +00:00
|
|
|
virBufferAddLit(&buffer, "&dsName=");
|
|
|
|
virBufferURIEncodeString(&buffer, datastoreName);
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
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);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_CURL_Upload(priv->primary->curl, url, vmx) < 0)
|
2010-10-12 17:37:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Register the domain */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (directoryName) {
|
2009-09-23 12:52:36 +00:00
|
|
|
if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
|
2013-07-04 10:05:43 +00:00
|
|
|
directoryName, escapedName) < 0)
|
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,
|
2013-07-04 10:05:43 +00:00
|
|
|
escapedName) < 0)
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not define domain: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (domain)
|
2009-09-23 12:52:36 +00:00
|
|
|
domain->id = -1;
|
|
|
|
|
|
|
|
/* FIXME: Add proper rollback in case of an error */
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!url)
|
2010-05-19 20:59:32 +00:00
|
|
|
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);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
esxDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
return esxDomainDefineXMLFlags(conn, xml, 0);
|
|
|
|
}
|
2009-09-23 12:52:36 +00:00
|
|
|
|
2009-09-04 16:30:10 +00:00
|
|
|
static int
|
2011-07-20 03:08:21 +00:00
|
|
|
esxDomainUndefineFlags(virDomainPtr domain,
|
|
|
|
unsigned int flags)
|
2009-09-04 16:30:10 +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-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;
|
|
|
|
|
2011-08-12 15:07:08 +00:00
|
|
|
/* No managed save, so we explicitly reject
|
|
|
|
* VIR_DOMAIN_UNDEFINE_MANAGED_SAVE. No snapshot metadata for
|
|
|
|
* ESX, so we can trivially ignore that flag. */
|
|
|
|
virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
|
2011-07-20 03:08:21 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (priv->vCenter) {
|
2009-12-06 23:59:56 +00:00
|
|
|
ctx = priv->vCenter;
|
|
|
|
} else {
|
|
|
|
ctx = priv->host;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-09-04 16:30:10 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
static int
|
|
|
|
esxDomainUndefine(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
return esxDomainUndefineFlags(domain, 0);
|
|
|
|
}
|
2009-09-04 16:30:10 +00:00
|
|
|
|
2010-12-30 00:36:31 +00:00
|
|
|
static int
|
|
|
|
esxDomainGetAutostart(virDomainPtr domain, int *autostart)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_AutoStartDefaults *defaults = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfo = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfoList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
|
|
|
|
*autostart = 0;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check general autostart config */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (defaults->enabled != esxVI_Boolean_True) {
|
|
|
|
/* Autostart is disabled in general, exit early here */
|
|
|
|
result = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check specific autostart config */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_LookupAutoStartPowerInfoList(priv->primary, &powerInfoList) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!powerInfoList) {
|
2010-12-30 00:36:31 +00:00
|
|
|
/* powerInfo list is empty, exit early here */
|
|
|
|
result = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
NULL, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (powerInfo = powerInfoList; powerInfo;
|
2010-12-30 00:36:31 +00:00
|
|
|
powerInfo = powerInfo->_next) {
|
|
|
|
if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (STRCASEEQ(powerInfo->startAction, "powerOn"))
|
2010-12-30 00:36:31 +00:00
|
|
|
*autostart = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-12-30 00:36:31 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_AutoStartDefaults_Free(&defaults);
|
|
|
|
esxVI_AutoStartPowerInfo_Free(&powerInfoList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSetAutostart(virDomainPtr domain, int autostart)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_HostAutoStartManagerConfig *spec = NULL;
|
|
|
|
esxVI_AutoStartDefaults *defaults = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfoList = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfo = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *newPowerInfo = NULL;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
NULL, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_HostAutoStartManagerConfig_Alloc(&spec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autostart) {
|
|
|
|
/*
|
|
|
|
* There is a general autostart option that affects the autostart
|
|
|
|
* behavior of all domains. If it's disabled then no domain does
|
|
|
|
* autostart. If it's enabled then the autostart behavior depends on
|
|
|
|
* the per-domain autostart config.
|
|
|
|
*/
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (defaults->enabled != esxVI_Boolean_True) {
|
|
|
|
/*
|
|
|
|
* Autostart is disabled in general. Check if no other domain is
|
|
|
|
* in the list of autostarted domains, so it's safe to enable the
|
|
|
|
* general autostart option without affecting the autostart
|
|
|
|
* behavior of other domains.
|
|
|
|
*/
|
|
|
|
if (esxVI_LookupAutoStartPowerInfoList(priv->primary,
|
|
|
|
&powerInfoList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (powerInfo = powerInfoList; powerInfo;
|
2010-12-30 00:36:31 +00:00
|
|
|
powerInfo = powerInfo->_next) {
|
|
|
|
if (STRNEQ(powerInfo->key->value, virtualMachine->obj->value)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Cannot enable general autostart option "
|
|
|
|
"without affecting other domains"));
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable autostart in general */
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_AutoStartDefaults_Alloc(&spec->defaults) < 0)
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
spec->defaults->enabled = esxVI_Boolean_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_AutoStartPowerInfo_Alloc(&newPowerInfo) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&newPowerInfo->startOrder) < 0 ||
|
|
|
|
esxVI_Int_Alloc(&newPowerInfo->startDelay) < 0 ||
|
2012-05-06 17:33:59 +00:00
|
|
|
esxVI_Int_Alloc(&newPowerInfo->stopDelay) < 0) {
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
newPowerInfo->key = virtualMachine->obj;
|
|
|
|
newPowerInfo->startOrder->value = -1; /* no specific start order */
|
|
|
|
newPowerInfo->startDelay->value = -1; /* use system default */
|
|
|
|
newPowerInfo->waitForHeartbeat = esxVI_AutoStartWaitHeartbeatSetting_SystemDefault;
|
|
|
|
newPowerInfo->startAction = autostart ? (char *)"powerOn" : (char *)"none";
|
|
|
|
newPowerInfo->stopDelay->value = -1; /* use system default */
|
|
|
|
newPowerInfo->stopAction = (char *)"none";
|
|
|
|
|
2012-05-06 17:33:59 +00:00
|
|
|
if (esxVI_AutoStartPowerInfo_AppendToList(&spec->powerInfo,
|
|
|
|
newPowerInfo) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-03 11:20:34 +00:00
|
|
|
newPowerInfo = NULL;
|
2012-05-06 17:33:59 +00:00
|
|
|
|
2010-12-30 00:36:31 +00:00
|
|
|
if (esxVI_ReconfigureAutostart
|
|
|
|
(priv->primary,
|
|
|
|
priv->primary->hostSystem->configManager->autoStartManager,
|
|
|
|
spec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2013-10-17 17:04:11 +00:00
|
|
|
if (newPowerInfo) {
|
2010-12-30 00:36:31 +00:00
|
|
|
newPowerInfo->key = NULL;
|
|
|
|
newPowerInfo->startAction = NULL;
|
|
|
|
newPowerInfo->stopAction = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_HostAutoStartManagerConfig_Free(&spec);
|
|
|
|
esxVI_AutoStartDefaults_Free(&defaults);
|
|
|
|
esxVI_AutoStartPowerInfo_Free(&powerInfoList);
|
|
|
|
|
2013-09-03 11:20:34 +00:00
|
|
|
esxVI_AutoStartPowerInfo_Free(&newPowerInfo);
|
2012-05-06 17:33:59 +00:00
|
|
|
|
2010-12-30 00:36:31 +00:00
|
|
|
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:
|
|
|
|
*
|
2011-05-26 17:39:04 +00:00
|
|
|
* - reservation (VIR_TYPED_PARAM_LLONG >= 0, in megaherz)
|
2009-07-30 11:41:04 +00:00
|
|
|
*
|
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
|
|
|
*
|
|
|
|
*
|
2011-05-26 17:39:04 +00:00
|
|
|
* - limit (VIR_TYPED_PARAM_LLONG >= 0, or -1, in megaherz)
|
2009-07-30 11:41:04 +00:00
|
|
|
*
|
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.
|
|
|
|
*
|
|
|
|
*
|
2011-05-26 17:39:04 +00:00
|
|
|
* - shares (VIR_TYPED_PARAM_INT >= 0, or in {-1, -2, -3}, no unit)
|
2009-07-30 11:41:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2013-05-03 12:41:53 +00:00
|
|
|
char *type;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(type, "allocation") < 0)
|
2009-07-30 11:41:04 +00:00
|
|
|
return NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (nparams)
|
2011-05-18 07:55:32 +00:00
|
|
|
*nparams = 3; /* reservation, limit, shares */
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-05-17 22:33:53 +00:00
|
|
|
esxDomainGetSchedulerParametersFlags(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params, int *nparams,
|
|
|
|
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_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_SharesInfo *sharesInfo = NULL;
|
|
|
|
unsigned int mask = 0;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i = 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22: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;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty && mask != 7 && i < 3 && i < *nparams;
|
2009-07-23 20:21:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.cpuAllocation.reservation") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 0))) {
|
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
|
|
|
}
|
2012-01-07 12:47:43 +00:00
|
|
|
if (virTypedParameterAssign(¶ms[i],
|
|
|
|
VIR_DOMAIN_SCHEDULER_RESERVATION,
|
|
|
|
VIR_TYPED_PARAM_LLONG,
|
|
|
|
dynamicProperty->val->int64) < 0)
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
mask |= 1 << 0;
|
|
|
|
++i;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.cpuAllocation.limit") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 1))) {
|
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
|
|
|
}
|
2012-01-07 12:47:43 +00:00
|
|
|
if (virTypedParameterAssign(¶ms[i],
|
|
|
|
VIR_DOMAIN_SCHEDULER_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_LLONG,
|
|
|
|
dynamicProperty->val->int64) < 0)
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
mask |= 1 << 1;
|
|
|
|
++i;
|
|
|
|
} else if (STREQ(dynamicProperty->name,
|
|
|
|
"config.cpuAllocation.shares") &&
|
2009-09-23 12:37:26 +00:00
|
|
|
! (mask & (1 << 2))) {
|
2012-01-07 12:47:43 +00:00
|
|
|
if (virTypedParameterAssign(¶ms[i],
|
|
|
|
VIR_DOMAIN_SCHEDULER_SHARES,
|
|
|
|
VIR_TYPED_PARAM_INT, 0) < 0)
|
|
|
|
goto cleanup;
|
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:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Shares level has unknown value %d"),
|
|
|
|
(int)sharesInfo->level);
|
2013-09-03 11:20:34 +00:00
|
|
|
esxVI_SharesInfo_Free(&sharesInfo);
|
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
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
|
|
|
esxDomainGetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params, int *nparams)
|
|
|
|
{
|
|
|
|
return esxDomainGetSchedulerParametersFlags(domain, params, nparams, 0);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-05-17 22:33:53 +00:00
|
|
|
esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params, int nparams,
|
|
|
|
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_VirtualMachineConfigSpec *spec = NULL;
|
|
|
|
esxVI_SharesInfo *sharesInfo = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
virCheckFlags(0, -1);
|
2013-05-03 13:34:10 +00:00
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_DOMAIN_SCHEDULER_RESERVATION,
|
|
|
|
VIR_TYPED_PARAM_LLONG,
|
|
|
|
VIR_DOMAIN_SCHEDULER_LIMIT,
|
|
|
|
VIR_TYPED_PARAM_LLONG,
|
|
|
|
VIR_DOMAIN_SCHEDULER_SHARES,
|
|
|
|
VIR_TYPED_PARAM_INT,
|
|
|
|
NULL) < 0)
|
2012-01-07 12:47:43 +00:00
|
|
|
return -1;
|
2011-05-17 22:33:53 +00:00
|
|
|
|
2014-11-13 14:22: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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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) {
|
2012-01-07 12:47:43 +00:00
|
|
|
if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_RESERVATION)) {
|
2014-11-13 14:22:05 +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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("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;
|
2012-10-17 09:23:12 +00:00
|
|
|
} else if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_LIMIT)) {
|
2014-11-13 14:22:05 +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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Could not set limit to %lld MHz, expecting "
|
|
|
|
"positive value or -1 (unlimited)"),
|
|
|
|
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;
|
2012-10-17 09:23:12 +00:00
|
|
|
} else if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_SHARES)) {
|
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;
|
2013-09-03 11:20:34 +00:00
|
|
|
sharesInfo = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
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:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Could not set shares to %d, expecting positive "
|
|
|
|
"value or -1 (low), -2 (normal) or -3 (high)"),
|
|
|
|
params[i].value.i);
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not change scheduler parameters: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2013-09-03 11:20:34 +00:00
|
|
|
esxVI_SharesInfo_Free(&sharesInfo);
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-17 22:33:53 +00:00
|
|
|
static int
|
|
|
|
esxDomainSetSchedulerParameters(virDomainPtr domain,
|
|
|
|
virTypedParameterPtr params, int nparams)
|
|
|
|
{
|
|
|
|
return esxDomainSetSchedulerParametersFlags(domain, params, nparams, 0);
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
/* The subset of migration flags we are able to support. */
|
|
|
|
#define ESX_MIGRATION_FLAGS \
|
|
|
|
(VIR_MIGRATE_PERSIST_DEST | \
|
|
|
|
VIR_MIGRATE_UNDEFINE_SOURCE | \
|
|
|
|
VIR_MIGRATE_LIVE | \
|
|
|
|
VIR_MIGRATE_PAUSED)
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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,
|
2011-07-06 22:14:33 +00:00
|
|
|
unsigned long flags,
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!uri_in) {
|
2010-07-31 21:57:42 +00:00
|
|
|
if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s",
|
|
|
|
priv->vCenter->ipAddress,
|
|
|
|
priv->vCenter->computeResource->resourcePool->value,
|
2013-07-04 10:05:43 +00:00
|
|
|
priv->vCenter->hostSystem->_reference->value) < 0)
|
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,
|
2011-07-06 22:14:33 +00:00
|
|
|
unsigned long flags,
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2012-02-24 18:48:55 +00:00
|
|
|
virURIPtr parsedUri = NULL;
|
2010-07-31 21:57:42 +00:00
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!priv->vCenter) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (dname) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +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 */
|
Centralize error reporting for URI parsing/formatting problems
Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.
* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
src/remote/remote_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
src/xen/xend_internal.c, tests/viruritest.c: Remove error
reporting
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-20 12:16:54 +00:00
|
|
|
if (!(parsedUri = virURIParse(uri)))
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!parsedUri->scheme || STRCASENEQ(parsedUri->scheme, "vpxmigr")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Migration source and destination have to refer to "
|
|
|
|
"the same vCenter"));
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_resourcePool = strtok_r(parsedUri->path, "/", &saveptr);
|
|
|
|
path_hostSystem = strtok_r(NULL, "", &saveptr);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!path_resourcePool || !path_hostSystem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (eventList) {
|
2009-07-23 20:21:08 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Need to report the complete list of events. Limit reporting
|
|
|
|
* to the first event for now.
|
|
|
|
*/
|
2013-10-17 17:04:11 +00:00
|
|
|
if (eventList->fullFormattedMessage) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not migrate domain, validation reported a "
|
|
|
|
"problem: %s"), eventList->fullFormattedMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not migrate domain, migration task finished with "
|
|
|
|
"an error: %s"),
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-03-20 11:59:42 +00:00
|
|
|
virURIFree(parsedUri);
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_Event_Free(&eventList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
esxDomainMigrateFinish(virConnectPtr dconn, const char *dname,
|
|
|
|
const char *cookie ATTRIBUTE_UNUSED,
|
|
|
|
int cookielen ATTRIBUTE_UNUSED,
|
|
|
|
const char *uri ATTRIBUTE_UNUSED,
|
2011-07-06 22:14:33 +00:00
|
|
|
unsigned long flags)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(ESX_MIGRATION_FLAGS, NULL);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
return esxDomainLookupByName(dconn, dname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-23 12:09:44 +00:00
|
|
|
static unsigned long long
|
|
|
|
esxNodeGetFreeMemory(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
unsigned long long result = 0;
|
2015-03-09 15:54:05 +00:00
|
|
|
unsigned long long usageBytes = 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;
|
2015-03-09 15:54:05 +00:00
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_Int *memoryUsage = NULL;
|
|
|
|
esxVI_Long *memorySize = NULL;
|
2009-09-23 12:09:44 +00:00
|
|
|
|
2014-11-13 14:22:05 +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
|
|
|
|
2015-03-09 15:54:05 +00:00
|
|
|
/* Get memory usage of host system */
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"summary.quickStats.overallMemoryUsage\0"
|
|
|
|
"hardware.memorySize\0") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
|
|
|
|
&hostSystem) < 0 ||
|
|
|
|
esxVI_GetInt(hostSystem, "summary.quickStats.overallMemoryUsage",
|
|
|
|
&memoryUsage, esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetLong(hostSystem, "hardware.memorySize", &memorySize,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 15:54:05 +00:00
|
|
|
usageBytes = (unsigned long long) (memoryUsage->value) * 1048576;
|
|
|
|
result = memorySize->value - usageBytes;
|
2009-09-23 12:09:44 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-09-23 12:09:44 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
2015-03-09 15:54:05 +00:00
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_Int_Free(&memoryUsage);
|
|
|
|
esxVI_Long_Free(&memorySize);
|
2009-09-23 12:09:44 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-18 00:03:31 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectIsEncrypted(virConnectPtr conn)
|
2009-11-18 00:03:31 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-11-18 00:03:31 +00:00
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
if (STRCASEEQ(priv->parsedUri->transport, "https")) {
|
2009-11-18 00:03:31 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectIsSecure(virConnectPtr conn)
|
2009-11-18 00:03:31 +00:00
|
|
|
{
|
2010-01-31 14:29:02 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2009-11-18 00:03:31 +00:00
|
|
|
|
2011-04-10 15:18:32 +00:00
|
|
|
if (STRCASEEQ(priv->parsedUri->transport, "https")) {
|
2009-11-18 00:03:31 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-23 06:56:13 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectIsAlive(virConnectPtr conn)
|
2011-09-23 06:56:13 +00:00
|
|
|
{
|
|
|
|
esxPrivate *priv = conn->privateData;
|
|
|
|
|
|
|
|
/* XXX we should be able to do something better than this but this is
|
|
|
|
* simple, safe, and good enough for now. In worst case, the function will
|
|
|
|
* return true even though the connection is not alive.
|
|
|
|
*/
|
|
|
|
if (priv->primary)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-18 00:03:31 +00:00
|
|
|
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;
|
|
|
|
|
2014-11-13 14:22: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;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-11-18 00:03:31 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2012-05-25 02:28:54 +00:00
|
|
|
esxDomainIsPersistent(virDomainPtr domain)
|
2009-11-18 00:03:31 +00:00
|
|
|
{
|
2012-05-25 02:28:54 +00:00
|
|
|
/* ESX has no concept of transient domains, so all of them are
|
|
|
|
* persistent. However, we do want to check for existence. */
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
NULL, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-05-25 02:28:54 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
2009-11-18 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 11:54:20 +00:00
|
|
|
|
|
|
|
|
2010-11-24 07:43:15 +00:00
|
|
|
static int
|
|
|
|
esxDomainIsUpdated(virDomainPtr domain ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2012-05-25 02:28:54 +00:00
|
|
|
/* ESX domains never have a persistent state that differs from
|
|
|
|
* current state. However, we do want to check for existence. */
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
|
|
|
|
NULL, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-05-25 02:28:54 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
2010-11-24 07:43:15 +00:00
|
|
|
}
|
2009-11-18 00:03:31 +00:00
|
|
|
|
2010-12-30 11:54:20 +00:00
|
|
|
|
|
|
|
|
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_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
2013-07-17 18:28:33 +00:00
|
|
|
bool diskOnly = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) != 0;
|
|
|
|
bool quiesce = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) != 0;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2013-07-17 18:28:33 +00:00
|
|
|
/* ESX supports disk-only and quiesced snapshots; libvirt tracks no
|
|
|
|
* snapshot metadata so supporting that flag is trivial. */
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA, NULL);
|
2010-04-16 12:04:31 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2013-03-05 15:17:24 +00:00
|
|
|
def = virDomainSnapshotDefParseString(xmlDesc, priv->caps,
|
2015-04-18 01:22:48 +00:00
|
|
|
priv->xmlopt, 0);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (!def)
|
2010-05-19 20:59:32 +00:00
|
|
|
return NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-08-20 04:03:38 +00:00
|
|
|
if (def->ndisks) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("disk snapshots not supported yet"));
|
2011-08-20 04:03:38 +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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->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,
|
2011-10-03 18:02:25 +00:00
|
|
|
&snapshotTree, NULL,
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (snapshotTree) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2013-07-17 18:28:33 +00:00
|
|
|
diskOnly ? esxVI_Boolean_False : esxVI_Boolean_True,
|
|
|
|
quiesce ? 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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not create snapshot: %s"),
|
|
|
|
taskInfoErrorMessage);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, def->name);
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
virDomainSnapshotDefFree(def);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2011-05-06 19:53:10 +00:00
|
|
|
esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
|
|
|
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);
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&def, 0, sizeof(def));
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-11-13 14:22: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;
|
2013-10-17 17:04:11 +00:00
|
|
|
def.parent = snapshotTreeParent ? snapshotTreeParent->name : NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-11-18 16:44:00 +00:00
|
|
|
xml = virDomainSnapshotDefFormat(uuid_string, &def,
|
|
|
|
virDomainDefFormatConvertXMLFlags(flags),
|
|
|
|
0);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
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;
|
2011-10-03 17:38:21 +00:00
|
|
|
bool recurse;
|
2011-10-08 02:30:14 +00:00
|
|
|
bool leaves;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-10-03 17:38:21 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
2011-10-08 02:30:14 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_METADATA |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1);
|
2011-10-03 17:38:21 +00:00
|
|
|
|
|
|
|
recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
|
2011-10-08 02:30:14 +00:00
|
|
|
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
|
2010-04-16 12:04:31 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2011-08-12 14:51:15 +00:00
|
|
|
/* ESX snapshots do not require libvirt to maintain any metadata. */
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)
|
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-10-08 02:30:14 +00:00
|
|
|
count = esxVI_GetNumberOfSnapshotTrees(rootSnapshotTreeList, recurse,
|
|
|
|
leaves);
|
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;
|
2011-10-03 17:38:21 +00:00
|
|
|
bool recurse;
|
2011-10-08 02:30:14 +00:00
|
|
|
bool leaves;
|
2011-10-03 17:38:21 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
|
2011-10-08 02:30:14 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_METADATA |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-10-03 17:38:21 +00:00
|
|
|
recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0;
|
2011-10-08 02:30:14 +00:00
|
|
|
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
|
2010-04-16 12:04:31 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!names || nameslen < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
2010-04-07 09:23:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (nameslen == 0 || (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA))
|
2010-04-07 09:23:53 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2011-10-03 17:38:21 +00:00
|
|
|
result = esxVI_GetSnapshotTreeNames(rootSnapshotTreeList, names, nameslen,
|
2011-10-08 02:30:14 +00:00
|
|
|
recurse, leaves);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 18:11:17 +00:00
|
|
|
static int
|
|
|
|
esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
|
|
|
int count = -1;
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
bool recurse;
|
2011-10-08 02:30:14 +00:00
|
|
|
bool leaves;
|
2011-10-03 18:11:17 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
2011-10-08 02:30:14 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_METADATA |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1);
|
2011-10-03 18:11:17 +00:00
|
|
|
|
|
|
|
recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0;
|
2011-10-08 02:30:14 +00:00
|
|
|
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
|
2011-10-03 18:11:17 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2011-10-03 18:11:17 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
|
|
|
&rootSnapshotTreeList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotTreeList, snapshot->name,
|
|
|
|
&snapshotTree, NULL,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ESX snapshots do not require libvirt to maintain any metadata. */
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
|
|
|
|
count = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = esxVI_GetNumberOfSnapshotTrees(snapshotTree->childSnapshotList,
|
2011-10-08 02:30:14 +00:00
|
|
|
recurse, leaves);
|
2011-10-03 18:11:17 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-10-03 18:11:17 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|
|
|
char **names, int nameslen,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
bool recurse;
|
2011-10-08 02:30:14 +00:00
|
|
|
bool leaves;
|
2011-10-03 18:11:17 +00:00
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS |
|
2011-10-08 02:30:14 +00:00
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_METADATA |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, -1);
|
2011-10-03 18:11:17 +00:00
|
|
|
|
|
|
|
recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0;
|
2011-10-08 02:30:14 +00:00
|
|
|
leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0;
|
2011-10-03 18:11:17 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!names || nameslen < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument"));
|
2011-10-03 18:11:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (nameslen == 0)
|
2011-10-03 18:11:17 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2011-10-03 18:11:17 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
|
|
|
&rootSnapshotTreeList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotTreeList, snapshot->name,
|
|
|
|
&snapshotTree, NULL,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ESX snapshots do not require libvirt to maintain any metadata. */
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
|
|
|
|
result = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
|
2011-10-08 02:30:14 +00:00
|
|
|
names, nameslen, recurse, leaves);
|
2011-10-03 18:11:17 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-10-03 18:11:17 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
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;
|
|
|
|
virDomainSnapshotPtr snapshot = NULL;
|
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2014-11-13 14:22: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,
|
2011-10-03 18:02:25 +00:00
|
|
|
NULL,
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = virGetDomainSnapshot(domain, name);
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
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
|
|
|
|
2014-11-13 14:22: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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (currentSnapshotTree) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-29 20:11:56 +00:00
|
|
|
static virDomainSnapshotPtr
|
|
|
|
esxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTreeParent = NULL;
|
|
|
|
virDomainSnapshotPtr parent = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2011-09-29 20:11:56 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, &snapshotTreeParent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!snapshotTreeParent) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("snapshot '%s' does not have a parent"),
|
|
|
|
snapshotTree->name);
|
2011-09-29 20:11:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = virGetDomainSnapshot(snapshot->domain, snapshotTreeParent->name);
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-09-29 20:11:56 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-11-13 14:22: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-25 02:28:54 +00:00
|
|
|
static int
|
|
|
|
esxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *currentSnapshotTree = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2012-05-25 02:28:54 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check that snapshot exists. */
|
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, NULL,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupCurrentSnapshotTree(priv->primary, snapshot->domain->uuid,
|
|
|
|
¤tSnapshotTree,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = STREQ(snapshot->name, currentSnapshotTree->name);
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-05-25 02:28:54 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(¤tSnapshotTree);
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, unsigned int flags)
|
|
|
|
{
|
|
|
|
esxPrivate *priv = snapshot->domain->conn->privateData;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2012-05-25 02:28:54 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check that snapshot exists. If so, there is no metadata. */
|
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid,
|
|
|
|
&rootSnapshotList) < 0 ||
|
|
|
|
esxVI_GetSnapshotTreeByName(rootSnapshotList, snapshot->name,
|
|
|
|
&snapshotTree, NULL,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-05-25 02:28:54 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
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_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2010-04-16 12:04:31 +00:00
|
|
|
virCheckFlags(0, -1);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-11-13 14:22: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,
|
2011-10-03 18:02:25 +00:00
|
|
|
&snapshotTree, NULL,
|
2010-04-07 09:23:53 +00:00
|
|
|
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,
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_Boolean_Undefined, &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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not revert to snapshot '%s': %s"), snapshot->name,
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
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_Boolean removeChildren = esxVI_Boolean_False;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-08-12 03:12:05 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
|
|
|
|
VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
|
2010-04-16 12:04:31 +00:00
|
|
|
|
2014-11-13 14:22: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
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)
|
2010-04-07 09:23:53 +00:00
|
|
|
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,
|
2011-10-03 18:02:25 +00:00
|
|
|
&snapshotTree, NULL,
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 03:12:05 +00:00
|
|
|
/* ESX snapshots do not require any libvirt metadata, making this
|
|
|
|
* flag trivial once we know we have a valid snapshot. */
|
|
|
|
if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY) {
|
|
|
|
result = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not delete snapshot '%s': %s"), snapshot->name,
|
|
|
|
taskInfoErrorMessage);
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-06 17:53:39 +00:00
|
|
|
static int
|
2011-05-26 17:39:04 +00:00
|
|
|
esxDomainSetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
|
2010-11-06 17:53:39 +00:00
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-11-06 17:53:39 +00:00
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
2013-05-03 13:34:10 +00:00
|
|
|
if (virTypedParamsValidate(params, nparams,
|
|
|
|
VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
NULL) < 0)
|
2012-01-07 12:47:43 +00:00
|
|
|
return -1;
|
2010-11-06 17:53:39 +00:00
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-11-06 17:53:39 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
|
|
|
(priv->primary, domain->uuid, NULL, &virtualMachine,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer) < 0 ||
|
2010-11-06 17:53:39 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Alloc(&spec) < 0 ||
|
|
|
|
esxVI_ResourceAllocationInfo_Alloc(&spec->memoryAllocation) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nparams; ++i) {
|
2012-01-07 12:47:43 +00:00
|
|
|
if (STREQ(params[i].field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) {
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_Long_Alloc(&spec->memoryAllocation->reservation) < 0)
|
2010-11-06 17:53:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
spec->memoryAllocation->reservation->value =
|
2011-01-28 21:03:24 +00:00
|
|
|
VIR_DIV_UP(params[i].value.ul, 1024); /* Scale from kilobytes to megabytes */
|
2010-11-06 17:53:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ReconfigVM_Task(priv->primary, virtualMachine->obj, spec,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(priv->primary, task, domain->uuid,
|
|
|
|
esxVI_Occurrence_RequiredItem,
|
2011-05-01 19:57:44 +00:00
|
|
|
priv->parsedUri->autoAnswer, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-11-06 17:53:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not change memory parameters: %s"),
|
|
|
|
taskInfoErrorMessage);
|
2010-11-06 17:53:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-11-06 17:53:39 +00:00
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_VirtualMachineConfigSpec_Free(&spec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-11-06 17:53:39 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-05-26 17:39:04 +00:00
|
|
|
esxDomainGetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
|
2010-11-06 17:53:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:05 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-11-06 17:53:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-07 12:47:43 +00:00
|
|
|
/* Scale from megabytes to kilobytes */
|
|
|
|
if (virTypedParameterAssign(params, VIR_DOMAIN_MEMORY_MIN_GUARANTEE,
|
|
|
|
VIR_TYPED_PARAM_ULLONG,
|
|
|
|
reservation->value * 1024) < 0)
|
2010-11-06 17:53:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
*nparams = 1;
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-11-06 17:53:39 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_Long_Free(&reservation);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
#define MATCH(FLAG) (flags & (FLAG))
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
2012-06-05 12:24:40 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
esxPrivate *priv = conn->privateData;
|
2012-09-09 10:31:16 +00:00
|
|
|
bool needIdentity;
|
|
|
|
bool needPowerState;
|
2012-06-05 12:24:40 +00:00
|
|
|
virDomainPtr dom;
|
|
|
|
virDomainPtr *doms = NULL;
|
|
|
|
size_t ndoms = 0;
|
2012-09-09 10:31:16 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
2012-06-05 12:24:40 +00:00
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
2012-09-09 10:31:16 +00:00
|
|
|
esxVI_AutoStartDefaults *autoStartDefaults = NULL;
|
2012-06-05 12:24:40 +00:00
|
|
|
esxVI_VirtualMachinePowerState powerState;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfoList = NULL;
|
|
|
|
esxVI_AutoStartPowerInfo *powerInfo = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
char *name = NULL;
|
|
|
|
int id;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
int count = 0;
|
|
|
|
bool autostart;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
|
|
|
|
|
|
|
/* check for flags that would produce empty output lists:
|
|
|
|
* - persistence: all esx machines are persistent
|
|
|
|
* - managed save: esx doesn't support managed save
|
|
|
|
*/
|
2012-09-09 10:31:16 +00:00
|
|
|
if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) &&
|
2012-06-05 12:24:40 +00:00
|
|
|
!MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
|
|
|
|
!MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) {
|
|
|
|
if (domains &&
|
|
|
|
VIR_ALLOC_N(*domains, 1) < 0)
|
2013-07-04 10:05:43 +00:00
|
|
|
goto cleanup;
|
2012-06-05 12:24:40 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2012-06-05 12:24:40 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* check system default autostart value */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART)) {
|
|
|
|
if (esxVI_LookupAutoStartDefaults(priv->primary,
|
2012-09-09 10:31:16 +00:00
|
|
|
&autoStartDefaults) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autoStartDefaults->enabled == esxVI_Boolean_True) {
|
|
|
|
if (esxVI_LookupAutoStartPowerInfoList(priv->primary,
|
|
|
|
&powerInfoList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
needIdentity = MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT) ||
|
2013-10-17 17:04:11 +00:00
|
|
|
domains;
|
2012-09-09 10:31:16 +00:00
|
|
|
|
|
|
|
if (needIdentity) {
|
|
|
|
/* Request required data for esxVI_GetVirtualMachineIdentity */
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"configStatus\0"
|
|
|
|
"name\0"
|
|
|
|
"config.uuid\0") < 0) {
|
2012-06-05 12:24:40 +00:00
|
|
|
goto cleanup;
|
2012-09-09 10:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
needPowerState = MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
|
|
|
MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE) ||
|
2013-10-17 17:04:11 +00:00
|
|
|
domains;
|
2012-06-05 12:24:40 +00:00
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (needPowerState) {
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"runtime.powerState") < 0) {
|
2012-06-05 12:24:40 +00:00
|
|
|
goto cleanup;
|
2012-09-09 10:31:16 +00:00
|
|
|
}
|
2012-06-05 12:24:40 +00:00
|
|
|
}
|
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (esxVI_LookupVirtualMachineList(priv->primary, propertyNameList,
|
2012-06-05 12:24:40 +00:00
|
|
|
&virtualMachineList) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (domains) {
|
|
|
|
if (VIR_ALLOC_N(doms, 1) < 0)
|
2013-07-04 10:05:43 +00:00
|
|
|
goto cleanup;
|
2012-06-05 12:24:40 +00:00
|
|
|
ndoms = 1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
2012-06-05 12:24:40 +00:00
|
|
|
virtualMachine = virtualMachine->_next) {
|
2012-09-09 10:31:16 +00:00
|
|
|
if (needIdentity) {
|
|
|
|
VIR_FREE(name);
|
2012-06-05 12:24:40 +00:00
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id,
|
|
|
|
&name, uuid) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2012-06-05 12:24:40 +00:00
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (needPowerState) {
|
|
|
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
|
|
|
&powerState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2012-06-05 12:24:40 +00:00
|
|
|
|
|
|
|
/* filter by active state */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
|
|
|
|
!((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) &&
|
|
|
|
powerState != esxVI_VirtualMachinePowerState_PoweredOff) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) &&
|
|
|
|
powerState == esxVI_VirtualMachinePowerState_PoweredOff)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* filter by snapshot existence */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
|
2012-09-09 10:31:16 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
if (esxVI_LookupRootSnapshotTreeList(priv->primary, uuid,
|
|
|
|
&rootSnapshotTreeList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) &&
|
2013-10-17 17:04:11 +00:00
|
|
|
rootSnapshotTreeList) ||
|
2012-06-05 12:24:40 +00:00
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) &&
|
2013-10-17 17:04:11 +00:00
|
|
|
!rootSnapshotTreeList)))
|
2012-06-05 12:24:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter by autostart */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART)) {
|
|
|
|
autostart = false;
|
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (autoStartDefaults->enabled == esxVI_Boolean_True) {
|
2013-10-17 17:04:11 +00:00
|
|
|
for (powerInfo = powerInfoList; powerInfo;
|
2012-09-09 10:31:16 +00:00
|
|
|
powerInfo = powerInfo->_next) {
|
|
|
|
if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) {
|
|
|
|
if (STRCASEEQ(powerInfo->startAction, "powerOn"))
|
|
|
|
autostart = true;
|
2012-06-05 12:24:40 +00:00
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-05 12:24:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) &&
|
|
|
|
autostart) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART) &&
|
|
|
|
!autostart)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter by domain state */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE)) {
|
|
|
|
state = esxVI_VirtualMachinePowerState_ConvertToLibvirt(powerState);
|
2012-09-09 10:31:16 +00:00
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) &&
|
|
|
|
state == VIR_DOMAIN_RUNNING) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) &&
|
|
|
|
state == VIR_DOMAIN_PAUSED) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) &&
|
|
|
|
state == VIR_DOMAIN_SHUTOFF) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) &&
|
|
|
|
(state != VIR_DOMAIN_RUNNING &&
|
|
|
|
state != VIR_DOMAIN_PAUSED &&
|
|
|
|
state != VIR_DOMAIN_SHUTOFF))))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just count the machines */
|
|
|
|
if (!doms) {
|
|
|
|
count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (VIR_RESIZE_N(doms, ndoms, count, 2) < 0)
|
2013-07-04 10:05:43 +00:00
|
|
|
goto cleanup;
|
2012-06-05 12:24:40 +00:00
|
|
|
|
2012-09-09 10:31:16 +00:00
|
|
|
if (!(dom = virGetDomain(conn, name, uuid)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
/* Only running/suspended virtual machines have an ID != -1 */
|
|
|
|
if (powerState != esxVI_VirtualMachinePowerState_PoweredOff)
|
|
|
|
dom->id = id;
|
|
|
|
else
|
|
|
|
dom->id = -1;
|
|
|
|
|
|
|
|
doms[count++] = dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doms)
|
|
|
|
*domains = doms;
|
|
|
|
doms = NULL;
|
|
|
|
ret = count;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-06-05 12:24:40 +00:00
|
|
|
if (doms) {
|
2014-11-13 14:22:05 +00:00
|
|
|
for (id = 0; id < count; id++)
|
2014-11-30 14:57:02 +00:00
|
|
|
virObjectUnref(doms[id]);
|
2012-09-09 10:31:16 +00:00
|
|
|
|
|
|
|
VIR_FREE(doms);
|
2012-06-05 12:24:40 +00:00
|
|
|
}
|
2012-09-09 10:31:16 +00:00
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
VIR_FREE(name);
|
2012-09-09 10:31:16 +00:00
|
|
|
esxVI_AutoStartDefaults_Free(&autoStartDefaults);
|
|
|
|
esxVI_AutoStartPowerInfo_Free(&powerInfoList);
|
2012-06-05 12:24:40 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
2012-09-09 10:31:16 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
2012-06-05 12:24:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#undef MATCH
|
2010-11-06 17:53:39 +00:00
|
|
|
|
2015-01-15 14:02:44 +00:00
|
|
|
static int
|
|
|
|
esxDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxPrivate *priv = domain->conn->privateData;
|
|
|
|
esxVI_ManagedObjectReference *managedObjectReference = NULL;
|
|
|
|
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virUUIDFormat(domain->uuid, uuid_string);
|
|
|
|
|
|
|
|
if (esxVI_FindByUuid(priv->primary, priv->primary->datacenter->_reference,
|
|
|
|
uuid_string, esxVI_Boolean_True,
|
|
|
|
esxVI_Boolean_Undefined,
|
|
|
|
&managedObjectReference) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!managedObjectReference) {
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("Could not find domain with UUID '%s'"),
|
|
|
|
uuid_string);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_ManagedObjectReference_Free(&managedObjectReference);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-11-06 17:53:39 +00:00
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virHypervisorDriver esxHypervisorDriver = {
|
Convert all driver struct intializers to C99 style
Change all the driver struct initializers to use the
C99 style, leaving out unused fields. This will make
it possible to add new APIs without changing every
driver. eg change:
qemudDomainResume, /* domainResume */
qemudDomainShutdown, /* domainShutdown */
NULL, /* domainReboot */
qemudDomainDestroy, /* domainDestroy */
to
.domainResume = qemudDomainResume,
.domainShutdown = qemudDomainShutdown,
.domainDestroy = qemudDomainDestroy,
And get rid of any existing C99 style initializersr which
set NULL, eg change
.listPools = vboxStorageListPools,
.numOfDefinedPools = NULL,
.listDefinedPools = NULL,
.findPoolSources = NULL,
.poolLookupByName = vboxStoragePoolLookupByName,
to
.listPools = vboxStorageListPools,
.poolLookupByName = vboxStoragePoolLookupByName,
2011-05-13 10:16:31 +00:00
|
|
|
.name = "ESX",
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectOpen = esxConnectOpen, /* 0.7.0 */
|
|
|
|
.connectClose = esxConnectClose, /* 0.7.0 */
|
|
|
|
.connectSupportsFeature = esxConnectSupportsFeature, /* 0.7.0 */
|
|
|
|
.connectGetType = esxConnectGetType, /* 0.7.0 */
|
|
|
|
.connectGetVersion = esxConnectGetVersion, /* 0.7.0 */
|
|
|
|
.connectGetHostname = esxConnectGetHostname, /* 0.7.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.nodeGetInfo = esxNodeGetInfo, /* 0.7.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectGetCapabilities = esxConnectGetCapabilities, /* 0.7.1 */
|
|
|
|
.connectListDomains = esxConnectListDomains, /* 0.7.0 */
|
|
|
|
.connectNumOfDomains = esxConnectNumOfDomains, /* 0.7.0 */
|
|
|
|
.connectListAllDomains = esxConnectListAllDomains, /* 0.10.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainLookupByID = esxDomainLookupByID, /* 0.7.0 */
|
|
|
|
.domainLookupByUUID = esxDomainLookupByUUID, /* 0.7.0 */
|
|
|
|
.domainLookupByName = esxDomainLookupByName, /* 0.7.0 */
|
|
|
|
.domainSuspend = esxDomainSuspend, /* 0.7.0 */
|
|
|
|
.domainResume = esxDomainResume, /* 0.7.0 */
|
|
|
|
.domainShutdown = esxDomainShutdown, /* 0.7.0 */
|
2011-10-05 17:31:55 +00:00
|
|
|
.domainShutdownFlags = esxDomainShutdownFlags, /* 0.9.10 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainReboot = esxDomainReboot, /* 0.7.0 */
|
|
|
|
.domainDestroy = esxDomainDestroy, /* 0.7.0 */
|
2011-07-20 16:45:21 +00:00
|
|
|
.domainDestroyFlags = esxDomainDestroyFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetOSType = esxDomainGetOSType, /* 0.7.0 */
|
|
|
|
.domainGetMaxMemory = esxDomainGetMaxMemory, /* 0.7.0 */
|
|
|
|
.domainSetMaxMemory = esxDomainSetMaxMemory, /* 0.7.0 */
|
|
|
|
.domainSetMemory = esxDomainSetMemory, /* 0.7.0 */
|
|
|
|
.domainSetMemoryParameters = esxDomainSetMemoryParameters, /* 0.8.6 */
|
|
|
|
.domainGetMemoryParameters = esxDomainGetMemoryParameters, /* 0.8.6 */
|
|
|
|
.domainGetInfo = esxDomainGetInfo, /* 0.7.0 */
|
|
|
|
.domainGetState = esxDomainGetState, /* 0.9.2 */
|
2014-03-30 18:45:07 +00:00
|
|
|
.domainScreenshot = esxDomainScreenshot, /* 1.2.10 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSetVcpus = esxDomainSetVcpus, /* 0.7.0 */
|
|
|
|
.domainSetVcpusFlags = esxDomainSetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainGetVcpusFlags = esxDomainGetVcpusFlags, /* 0.8.5 */
|
|
|
|
.domainGetMaxVcpus = esxDomainGetMaxVcpus, /* 0.7.0 */
|
|
|
|
.domainGetXMLDesc = esxDomainGetXMLDesc, /* 0.7.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectDomainXMLFromNative = esxConnectDomainXMLFromNative, /* 0.7.0 */
|
|
|
|
.connectDomainXMLToNative = esxConnectDomainXMLToNative, /* 0.7.2 */
|
|
|
|
.connectListDefinedDomains = esxConnectListDefinedDomains, /* 0.7.0 */
|
|
|
|
.connectNumOfDefinedDomains = esxConnectNumOfDefinedDomains, /* 0.7.0 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreate = esxDomainCreate, /* 0.7.0 */
|
|
|
|
.domainCreateWithFlags = esxDomainCreateWithFlags, /* 0.8.2 */
|
|
|
|
.domainDefineXML = esxDomainDefineXML, /* 0.7.2 */
|
2014-11-18 14:19:38 +00:00
|
|
|
.domainDefineXMLFlags = esxDomainDefineXMLFlags, /* 1.2.12 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainUndefine = esxDomainUndefine, /* 0.7.1 */
|
2011-07-20 03:08:21 +00:00
|
|
|
.domainUndefineFlags = esxDomainUndefineFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetAutostart = esxDomainGetAutostart, /* 0.9.0 */
|
|
|
|
.domainSetAutostart = esxDomainSetAutostart, /* 0.9.0 */
|
|
|
|
.domainGetSchedulerType = esxDomainGetSchedulerType, /* 0.7.0 */
|
|
|
|
.domainGetSchedulerParameters = esxDomainGetSchedulerParameters, /* 0.7.0 */
|
2011-05-17 22:33:53 +00:00
|
|
|
.domainGetSchedulerParametersFlags = esxDomainGetSchedulerParametersFlags, /* 0.9.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSetSchedulerParameters = esxDomainSetSchedulerParameters, /* 0.7.0 */
|
2011-05-17 22:33:53 +00:00
|
|
|
.domainSetSchedulerParametersFlags = esxDomainSetSchedulerParametersFlags, /* 0.9.2 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainMigratePrepare = esxDomainMigratePrepare, /* 0.7.0 */
|
|
|
|
.domainMigratePerform = esxDomainMigratePerform, /* 0.7.0 */
|
|
|
|
.domainMigrateFinish = esxDomainMigrateFinish, /* 0.7.0 */
|
|
|
|
.nodeGetFreeMemory = esxNodeGetFreeMemory, /* 0.7.2 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectIsEncrypted = esxConnectIsEncrypted, /* 0.7.3 */
|
|
|
|
.connectIsSecure = esxConnectIsSecure, /* 0.7.3 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainIsActive = esxDomainIsActive, /* 0.7.3 */
|
|
|
|
.domainIsPersistent = esxDomainIsPersistent, /* 0.7.3 */
|
|
|
|
.domainIsUpdated = esxDomainIsUpdated, /* 0.8.6 */
|
|
|
|
.domainSnapshotCreateXML = esxDomainSnapshotCreateXML, /* 0.8.0 */
|
|
|
|
.domainSnapshotGetXMLDesc = esxDomainSnapshotGetXMLDesc, /* 0.8.0 */
|
|
|
|
.domainSnapshotNum = esxDomainSnapshotNum, /* 0.8.0 */
|
|
|
|
.domainSnapshotListNames = esxDomainSnapshotListNames, /* 0.8.0 */
|
2011-10-03 18:11:17 +00:00
|
|
|
.domainSnapshotNumChildren = esxDomainSnapshotNumChildren, /* 0.9.7 */
|
|
|
|
.domainSnapshotListChildrenNames = esxDomainSnapshotListChildrenNames, /* 0.9.7 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSnapshotLookupByName = esxDomainSnapshotLookupByName, /* 0.8.0 */
|
|
|
|
.domainHasCurrentSnapshot = esxDomainHasCurrentSnapshot, /* 0.8.0 */
|
2011-09-29 20:11:56 +00:00
|
|
|
.domainSnapshotGetParent = esxDomainSnapshotGetParent, /* 0.9.7 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSnapshotCurrent = esxDomainSnapshotCurrent, /* 0.8.0 */
|
|
|
|
.domainRevertToSnapshot = esxDomainRevertToSnapshot, /* 0.8.0 */
|
2012-05-25 02:28:54 +00:00
|
|
|
.domainSnapshotIsCurrent = esxDomainSnapshotIsCurrent, /* 0.9.13 */
|
|
|
|
.domainSnapshotHasMetadata = esxDomainSnapshotHasMetadata, /* 0.9.13 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainSnapshotDelete = esxDomainSnapshotDelete, /* 0.8.0 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectIsAlive = esxConnectIsAlive, /* 0.9.8 */
|
2015-01-15 14:02:44 +00:00
|
|
|
.domainHasManagedSaveImage = esxDomainHasManagedSaveImage, /* 1.2.13 */
|
2009-07-23 20:21:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virConnectDriver esxConnectDriver = {
|
|
|
|
.hypervisorDriver = &esxHypervisorDriver,
|
|
|
|
.interfaceDriver = &esxInterfaceDriver,
|
|
|
|
.networkDriver = &esxNetworkDriver,
|
|
|
|
.storageDriver = &esxStorageDriver,
|
|
|
|
};
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
esxRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
return virRegisterConnectDriver(&esxConnectDriver,
|
|
|
|
false);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|