2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* esx_vi.c: client for the VMware VI API 2.5 to manage ESX hosts
|
|
|
|
*
|
2010-03-01 23:38:28 +00:00
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
2010-03-06 16:56:28 +00:00
|
|
|
* Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xpathInternals.h>
|
|
|
|
|
|
|
|
#include "buf.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "uuid.h"
|
2009-09-04 16:08:52 +00:00
|
|
|
#include "xml.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#include "esx_vi.h"
|
|
|
|
#include "esx_vi_methods.h"
|
|
|
|
#include "esx_util.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__SOAP__RESPONSE_XPATH(_type) \
|
|
|
|
((char *)"/soapenv:Envelope/soapenv:Body/" \
|
|
|
|
"vim:"_type"Response/vim:returnval")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__ALLOC(_type) \
|
|
|
|
int \
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_##_type##_Alloc(esxVI_##_type **ptrptr) \
|
2009-07-23 20:21:08 +00:00
|
|
|
{ \
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##_type)); \
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-04-18 17:58:58 +00:00
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
#define ESX_VI__TEMPLATE__FREE(_type, _body) \
|
|
|
|
void \
|
|
|
|
esxVI_##_type##_Free(esxVI_##_type **ptrptr) \
|
|
|
|
{ \
|
|
|
|
esxVI_##_type *item = NULL; \
|
|
|
|
\
|
|
|
|
if (ptrptr == NULL || *ptrptr == NULL) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
item = *ptrptr; \
|
|
|
|
\
|
|
|
|
_body \
|
|
|
|
\
|
|
|
|
VIR_FREE(*ptrptr); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Context
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* esxVI_Context_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(Context);
|
|
|
|
|
|
|
|
/* esxVI_Context_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(Context,
|
|
|
|
{
|
|
|
|
VIR_FREE(item->url);
|
2009-09-23 12:09:44 +00:00
|
|
|
VIR_FREE(item->ipAddress);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (item->curl_handle != NULL) {
|
|
|
|
curl_easy_cleanup(item->curl_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->curl_headers != NULL) {
|
|
|
|
curl_slist_free_all(item->curl_headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexDestroy(&item->curl_lock);
|
|
|
|
|
|
|
|
VIR_FREE(item->username);
|
|
|
|
VIR_FREE(item->password);
|
|
|
|
esxVI_ServiceContent_Free(&item->service);
|
|
|
|
esxVI_UserSession_Free(&item->session);
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_Datacenter_Free(&item->datacenter);
|
|
|
|
esxVI_ComputeResource_Free(&item->computeResource);
|
|
|
|
esxVI_HostSystem_Free(&item->hostSystem);
|
2010-08-21 16:49:18 +00:00
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_folderToChildEntity);
|
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToParent);
|
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToVm);
|
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToDatastore);
|
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToHost);
|
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToParentToParent);
|
2009-07-23 20:21:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
static size_t
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *ptrptr)
|
|
|
|
{
|
|
|
|
const char *content = *(const char **)ptrptr;
|
|
|
|
size_t available = 0;
|
|
|
|
size_t requested = size * nmemb;
|
|
|
|
|
|
|
|
if (content == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
available = strlen(content);
|
|
|
|
|
|
|
|
if (available == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requested > available) {
|
|
|
|
requested = available;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(data, content, requested);
|
|
|
|
|
|
|
|
*(const char **)ptrptr = content + requested;
|
|
|
|
|
|
|
|
return requested;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *buffer)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
if (buffer != NULL) {
|
|
|
|
virBufferAdd((virBufferPtr) buffer, data, size * nmemb);
|
|
|
|
|
|
|
|
return size * nmemb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ESX_VI__CURL__ENABLE_DEBUG_OUTPUT 0
|
|
|
|
|
|
|
|
#if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
|
|
|
|
static int
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type,
|
|
|
|
char *info, size_t size, void *data ATTRIBUTE_UNUSED)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-01-02 13:18:44 +00:00
|
|
|
char *buffer = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The libcurl documentation says:
|
|
|
|
*
|
|
|
|
* The data pointed to by the char * passed to this function WILL NOT
|
|
|
|
* be zero terminated, but will be exactly of the size as told by the
|
|
|
|
* size_t argument.
|
|
|
|
*
|
|
|
|
* To handle this properly in order to pass the info string to VIR_DEBUG
|
|
|
|
* a zero terminated copy of the info string has to be allocated.
|
|
|
|
*/
|
|
|
|
if (VIR_ALLOC_N(buffer, size + 1) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrncpy(buffer, info, size, size + 1) == NULL) {
|
|
|
|
VIR_FREE(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case CURLINFO_TEXT:
|
2010-01-02 13:18:44 +00:00
|
|
|
if (size > 0 && buffer[size - 1] == '\n') {
|
|
|
|
buffer[size - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("CURLINFO_TEXT [[[[%s]]]]", buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CURLINFO_HEADER_IN:
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_DEBUG("CURLINFO_HEADER_IN [[[[%s]]]]", buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CURLINFO_HEADER_OUT:
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_DEBUG("CURLINFO_HEADER_OUT [[[[%s]]]]", buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CURLINFO_DATA_IN:
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_DEBUG("CURLINFO_DATA_IN [[[[%s]]]]", buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CURLINFO_DATA_OUT:
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_DEBUG("CURLINFO_DATA_OUT [[[[%s]]]]", buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VIR_DEBUG0("unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
static int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_CURL_Perform(esxVI_Context *ctx, const char *url)
|
2009-10-21 18:25:22 +00:00
|
|
|
{
|
|
|
|
CURLcode errorCode;
|
|
|
|
long responseCode = 0;
|
|
|
|
#if LIBCURL_VERSION_NUM >= 0x071202 /* 7.18.2 */
|
|
|
|
const char *redirectUrl = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
errorCode = curl_easy_perform(ctx->curl_handle);
|
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("curl_easy_perform() returned an error: %s (%d) : %s"),
|
2010-01-26 01:05:45 +00:00
|
|
|
curl_easy_strerror(errorCode), errorCode, ctx->curl_error);
|
2009-10-21 18:25:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
|
|
|
|
&responseCode);
|
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned an "
|
|
|
|
"error: %s (%d) : %s"), curl_easy_strerror(errorCode),
|
2010-01-26 01:05:45 +00:00
|
|
|
errorCode, ctx->curl_error);
|
2009-10-21 18:25:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseCode < 0) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned a "
|
|
|
|
"negative response code"));
|
2009-10-21 18:25:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseCode == 301) {
|
|
|
|
#if LIBCURL_VERSION_NUM >= 0x071202 /* 7.18.2 */
|
|
|
|
errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_REDIRECT_URL,
|
|
|
|
&redirectUrl);
|
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("curl_easy_getinfo(CURLINFO_REDIRECT_URL) returned "
|
|
|
|
"an error: %s (%d) : %s"),
|
|
|
|
curl_easy_strerror(errorCode),
|
2010-01-26 01:05:45 +00:00
|
|
|
errorCode, ctx->curl_error);
|
2009-10-21 18:25:22 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("The server redirects from '%s' to '%s'"), url,
|
2009-10-21 18:25:22 +00:00
|
|
|
redirectUrl);
|
|
|
|
}
|
|
|
|
#else
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("The server redirects from '%s'"), url);
|
2009-10-21 18:25:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseCode;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
2009-09-23 12:09:44 +00:00
|
|
|
const char *ipAddress, const char *username,
|
2010-07-30 20:08:35 +00:00
|
|
|
const char *password, esxUtil_ParsedUri *parsedUri)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2009-09-23 12:09:44 +00:00
|
|
|
if (ctx == NULL || url == NULL || ipAddress == NULL || username == NULL ||
|
|
|
|
password == NULL || ctx->url != NULL || ctx->service != NULL ||
|
|
|
|
ctx->curl_handle != NULL || ctx->curl_headers != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
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_DeepCopyValue(&ctx->url, url) < 0 ||
|
|
|
|
esxVI_String_DeepCopyValue(&ctx->ipAddress, ipAddress) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->curl_handle = curl_easy_init();
|
|
|
|
|
|
|
|
if (ctx->curl_handle == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize CURL"));
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->curl_headers = curl_slist_append(ctx->curl_headers, "Content-Type: "
|
|
|
|
"text/xml; charset=UTF-8");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a dummy expect header to stop CURL from waiting for a response code
|
|
|
|
* 100 (Continue) from the server before continuing the POST operation.
|
|
|
|
* Waiting for this response would slowdown each communication with the
|
|
|
|
* server by approx. 2 sec, because the server doesn't send the expected
|
|
|
|
* 100 (Continue) response and the wait times out resulting in wasting
|
|
|
|
* approx. 2 sec per POST operation.
|
|
|
|
*/
|
|
|
|
ctx->curl_headers = curl_slist_append(ctx->curl_headers,
|
|
|
|
"Expect: nothing");
|
|
|
|
|
|
|
|
if (ctx->curl_headers == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not build CURL header list"));
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_USERAGENT, "libvirt-esx");
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_HEADER, 0);
|
2009-10-21 18:25:22 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_FOLLOWLOCATION, 0);
|
2010-06-03 21:09:12 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_SSL_VERIFYPEER,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->noVerify ? 0 : 1);
|
2010-06-03 21:09:12 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_SSL_VERIFYHOST,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->noVerify ? 0 : 2);
|
2009-07-23 20:21:08 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_COOKIEFILE, "");
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_HTTPHEADER, ctx->curl_headers);
|
2009-09-23 12:52:36 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_READFUNCTION,
|
|
|
|
esxVI_CURL_ReadString);
|
2009-07-23 20:21:08 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEFUNCTION,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_CURL_WriteBuffer);
|
2010-01-26 01:05:45 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_ERRORBUFFER,
|
|
|
|
ctx->curl_error);
|
2009-07-23 20:21:08 +00:00
|
|
|
#if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
|
2010-01-02 13:18:44 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_DEBUGFUNCTION, esxVI_CURL_Debug);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_VERBOSE, 1);
|
2009-07-23 20:21:08 +00:00
|
|
|
#endif
|
|
|
|
|
2010-07-30 20:08:35 +00:00
|
|
|
if (parsedUri->proxy) {
|
2010-06-03 21:09:12 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_PROXY,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_hostname);
|
2010-06-03 21:09:12 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_PROXYTYPE,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_type);
|
2010-06-03 21:09:12 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_PROXYPORT,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_port);
|
2010-06-03 21:09:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
if (virMutexInit(&ctx->curl_lock) < 0) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize CURL mutex"));
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->username = strdup(username);
|
|
|
|
ctx->password = strdup(password);
|
|
|
|
|
|
|
|
if (ctx->username == NULL || ctx->password == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 12:27:09 +00:00
|
|
|
if (STREQ(ctx->service->about->apiType, "HostAgent") ||
|
|
|
|
STREQ(ctx->service->about->apiType, "VirtualCenter")) {
|
|
|
|
if (STRPREFIX(ctx->service->about->apiVersion, "2.5")) {
|
2009-08-05 08:23:59 +00:00
|
|
|
ctx->apiVersion = esxVI_APIVersion_25;
|
2009-07-27 12:27:09 +00:00
|
|
|
} else if (STRPREFIX(ctx->service->about->apiVersion, "4.0")) {
|
2009-08-05 08:23:59 +00:00
|
|
|
ctx->apiVersion = esxVI_APIVersion_40;
|
2010-07-21 23:19:04 +00:00
|
|
|
} else if (STRPREFIX(ctx->service->about->apiVersion, "4.1")) {
|
|
|
|
ctx->apiVersion = esxVI_APIVersion_41;
|
|
|
|
} else if (STRPREFIX(ctx->service->about->apiVersion, "4.")) {
|
|
|
|
ctx->apiVersion = esxVI_APIVersion_4x;
|
|
|
|
|
|
|
|
VIR_WARN("Found untested VI API major/minor version '%s'",
|
|
|
|
ctx->service->about->apiVersion);
|
2009-07-27 12:27:09 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-07-21 23:19:04 +00:00
|
|
|
_("Expecting VI API major/minor version '2.5' or '4.x' "
|
2010-04-02 19:34:31 +00:00
|
|
|
"but found '%s'"), ctx->service->about->apiVersion);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2009-07-27 12:27:09 +00:00
|
|
|
|
2009-08-05 08:23:59 +00:00
|
|
|
if (STREQ(ctx->service->about->productLineId, "gsx")) {
|
|
|
|
if (STRPREFIX(ctx->service->about->version, "2.0")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_GSX20;
|
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting GSX major/minor version '2.0' but "
|
|
|
|
"found '%s'"), ctx->service->about->version);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-08-05 08:23:59 +00:00
|
|
|
}
|
|
|
|
} else if (STREQ(ctx->service->about->productLineId, "esx") ||
|
|
|
|
STREQ(ctx->service->about->productLineId, "embeddedEsx")) {
|
|
|
|
if (STRPREFIX(ctx->service->about->version, "3.5")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_ESX35;
|
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.0")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_ESX40;
|
2010-07-21 23:19:04 +00:00
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.1")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_ESX41;
|
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_ESX4x;
|
|
|
|
|
|
|
|
VIR_WARN("Found untested ESX major/minor version '%s'",
|
|
|
|
ctx->service->about->version);
|
2009-08-05 08:23:59 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting ESX major/minor version '3.5' or "
|
2010-07-21 23:19:04 +00:00
|
|
|
"'4.x' but found '%s'"),
|
2009-08-05 08:23:59 +00:00
|
|
|
ctx->service->about->version);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-08-05 08:23:59 +00:00
|
|
|
}
|
|
|
|
} else if (STREQ(ctx->service->about->productLineId, "vpx")) {
|
|
|
|
if (STRPREFIX(ctx->service->about->version, "2.5")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_VPX25;
|
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.0")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_VPX40;
|
2010-07-21 23:19:04 +00:00
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.1")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_VPX41;
|
|
|
|
} else if (STRPREFIX(ctx->service->about->version, "4.")) {
|
|
|
|
ctx->productVersion = esxVI_ProductVersion_VPX4x;
|
|
|
|
|
|
|
|
VIR_WARN("Found untested VPX major/minor version '%s'",
|
|
|
|
ctx->service->about->version);
|
2009-08-05 08:23:59 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-07-21 23:19:04 +00:00
|
|
|
_("Expecting VPX major/minor version '2.5' or '4.x' "
|
2010-04-02 19:34:31 +00:00
|
|
|
"but found '%s'"), ctx->service->about->version);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-08-05 08:23:59 +00:00
|
|
|
}
|
2009-07-27 12:27:09 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting product 'gsx' or 'esx' or 'embeddedEsx' "
|
|
|
|
"or 'vpx' but found '%s'"),
|
2009-08-05 08:23:59 +00:00
|
|
|
ctx->service->about->productLineId);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting VI API type 'HostAgent' or 'VirtualCenter' "
|
|
|
|
"but found '%s'"), ctx->service->about->apiType);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-03 23:30:04 +00:00
|
|
|
if (ctx->productVersion & esxVI_ProductVersion_ESX) {
|
|
|
|
/*
|
|
|
|
* FIXME: Actually this should be detected by really calling
|
|
|
|
* QueryVirtualDiskUuid and checking if a NotImplemented fault is
|
|
|
|
* returned. But currently we don't deserialized the details of a
|
|
|
|
* possbile fault and therefore we don't know if the fault was a
|
|
|
|
* NotImplemented fault or not.
|
|
|
|
*/
|
|
|
|
ctx->hasQueryVirtualDiskUuid = true;
|
|
|
|
}
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (ctx->productVersion & esxVI_ProductVersion_VPX) {
|
|
|
|
ctx->hasSessionIsActive = true;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0 ||
|
2010-08-21 16:49:18 +00:00
|
|
|
esxVI_BuildSelectSetCollection(ctx) < 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_Context_LookupObjectsByPath(esxVI_Context *ctx,
|
|
|
|
esxUtil_ParsedUri *parsedUri)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
char *name = NULL;
|
|
|
|
esxVI_ObjectContent *datacenterList = NULL;
|
|
|
|
esxVI_ObjectContent *datacenter = NULL;
|
|
|
|
esxVI_ObjectContent *computeResourceList = NULL;
|
|
|
|
esxVI_ObjectContent *computeResource = NULL;
|
|
|
|
char *hostSystemName = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystemList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
|
|
|
|
/* Lookup Datacenter */
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0"
|
|
|
|
"vmFolder\0"
|
|
|
|
"hostFolder\0") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, ctx->service->rootFolder,
|
2009-10-18 19:31:46 +00:00
|
|
|
"Datacenter", propertyNameList,
|
|
|
|
&datacenterList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (datacenterList == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
2010-07-31 21:57:42 +00:00
|
|
|
_("Could not retrieve datacenter list"));
|
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 (parsedUri->path_datacenter != NULL) {
|
|
|
|
for (datacenter = datacenterList; datacenter != NULL;
|
|
|
|
datacenter = datacenter->_next) {
|
|
|
|
name = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_GetStringValue(datacenter, "name", &name,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
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 (STREQ(name, parsedUri->path_datacenter)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (datacenter == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datacenter '%s'"),
|
|
|
|
parsedUri->path_datacenter);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
datacenter = datacenterList;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_Datacenter_CastFromObjectContent(datacenter,
|
|
|
|
&ctx->datacenter) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup ComputeResource */
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0"
|
|
|
|
"host\0"
|
|
|
|
"resourcePool\0") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, ctx->datacenter->hostFolder,
|
|
|
|
"ComputeResource", propertyNameList,
|
|
|
|
&computeResourceList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (computeResourceList == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve compute resource list"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsedUri->path_computeResource != NULL) {
|
|
|
|
for (computeResource = computeResourceList; computeResource != NULL;
|
|
|
|
computeResource = computeResource->_next) {
|
|
|
|
name = NULL;
|
|
|
|
|
|
|
|
if (esxVI_GetStringValue(computeResource, "name", &name,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
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 (STREQ(name, parsedUri->path_computeResource)) {
|
|
|
|
break;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2010-07-31 21:57:42 +00:00
|
|
|
|
|
|
|
if (computeResource == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find compute resource '%s'"),
|
|
|
|
parsedUri->path_computeResource);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
computeResource = computeResourceList;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
|
|
|
|
&ctx->computeResource) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->computeResource->resourcePool == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve resource pool"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup HostSystem */
|
|
|
|
if (parsedUri->path_hostSystem == NULL &&
|
|
|
|
STREQ(ctx->computeResource->_reference->type,
|
|
|
|
"ClusterComputeResource")) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("Path has to specify the host system"));
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, ctx->computeResource->_reference,
|
|
|
|
"HostSystem", propertyNameList,
|
|
|
|
&hostSystemList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystemList == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
2010-07-31 21:57:42 +00:00
|
|
|
_("Could not retrieve host system list"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsedUri->path_hostSystem != NULL ||
|
|
|
|
(parsedUri->path_computeResource != NULL &&
|
|
|
|
parsedUri->path_hostSystem == NULL)) {
|
|
|
|
if (parsedUri->path_hostSystem != NULL) {
|
|
|
|
hostSystemName = parsedUri->path_hostSystem;
|
|
|
|
} else {
|
|
|
|
hostSystemName = parsedUri->path_computeResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (hostSystem = hostSystemList; hostSystem != NULL;
|
|
|
|
hostSystem = hostSystem->_next) {
|
|
|
|
name = NULL;
|
|
|
|
|
|
|
|
if (esxVI_GetStringValue(hostSystem, "name", &name,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(name, hostSystemName)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find host system '%s'"), hostSystemName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hostSystem = hostSystemList;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
|
|
|
|
&ctx->hostSystem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datacenterList);
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_ObjectContent_Free(&computeResourceList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystemList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_Context_LookupObjectsByHostSystemIp(esxVI_Context *ctx,
|
|
|
|
const char *hostSystemIpAddress)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ManagedObjectReference *managedObjectReference = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_ObjectContent *computeResource = NULL;
|
|
|
|
esxVI_ObjectContent *datacenter = NULL;
|
|
|
|
|
|
|
|
/* Lookup HostSystem */
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0") < 0 ||
|
|
|
|
esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
|
|
|
|
&managedObjectReference) < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, managedObjectReference,
|
|
|
|
"HostSystem", propertyNameList,
|
2010-08-21 16:49:18 +00:00
|
|
|
&hostSystem) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostSystem == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve host system"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
|
|
|
|
&ctx->hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup ComputeResource */
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0"
|
|
|
|
"host\0"
|
|
|
|
"resourcePool\0") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, hostSystem->obj,
|
|
|
|
"ComputeResource", propertyNameList,
|
|
|
|
&computeResource) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (computeResource == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve compute resource of host system"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
|
|
|
|
&ctx->computeResource) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup Datacenter */
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"name\0"
|
|
|
|
"vmFolder\0"
|
|
|
|
"hostFolder\0") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, computeResource->obj,
|
|
|
|
"Datacenter", propertyNameList,
|
|
|
|
&datacenter) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (datacenter == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve datacenter of compute resource"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_Datacenter_CastFromObjectContent(datacenter,
|
|
|
|
&ctx->datacenter) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&managedObjectReference);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_ObjectContent_Free(&computeResource);
|
|
|
|
esxVI_ObjectContent_Free(&datacenter);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Context_DownloadFile(esxVI_Context *ctx, const char *url, char **content)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-10-21 18:25:22 +00:00
|
|
|
int responseCode = 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (content == NULL || *content != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&ctx->curl_lock);
|
|
|
|
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEDATA, &buffer);
|
2009-09-23 12:52:36 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_UPLOAD, 0);
|
2009-07-23 20:21:08 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_HTTPGET, 1);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
responseCode = esxVI_CURL_Perform(ctx, url);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
virMutexUnlock(&ctx->curl_lock);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
if (responseCode < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-10-21 18:25:22 +00:00
|
|
|
} else if (responseCode != 200) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for download from '%s'"),
|
2009-10-21 18:25:22 +00:00
|
|
|
responseCode, url);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*content = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
cleanup:
|
|
|
|
if (*content == NULL) {
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Context_UploadFile(esxVI_Context *ctx, const char *url,
|
|
|
|
const char *content)
|
2009-09-23 12:52:36 +00:00
|
|
|
{
|
2009-10-21 18:25:22 +00:00
|
|
|
int responseCode = 0;
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
if (content == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-09-23 12:52:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&ctx->curl_lock);
|
|
|
|
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, url);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_READDATA, &content);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_UPLOAD, 1);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_INFILESIZE, strlen(content));
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
responseCode = esxVI_CURL_Perform(ctx, url);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
virMutexUnlock(&ctx->curl_lock);
|
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
if (responseCode < 0) {
|
|
|
|
return -1;
|
|
|
|
} else if (responseCode != 200 && responseCode != 201) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for upload to '%s'"),
|
2009-10-21 18:25:22 +00:00
|
|
|
responseCode, url);
|
2009-09-23 12:52:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
|
|
|
|
const char *request, esxVI_Response **response,
|
|
|
|
esxVI_Occurrence occurrence)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
esxVI_Fault *fault = NULL;
|
2009-11-22 20:32:23 +00:00
|
|
|
char *xpathExpression = NULL;
|
|
|
|
xmlXPathContextPtr xpathContext = NULL;
|
|
|
|
xmlNodePtr responseNode = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
if (request == NULL || response == NULL || *response != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
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_Response_Alloc(response) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&ctx->curl_lock);
|
|
|
|
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEDATA, &buffer);
|
2009-09-23 12:52:36 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_UPLOAD, 0);
|
2009-09-04 16:24:25 +00:00
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS, request);
|
|
|
|
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE, strlen(request));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
(*response)->responseCode = esxVI_CURL_Perform(ctx, ctx->url);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
virMutexUnlock(&ctx->curl_lock);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-10-21 18:25:22 +00:00
|
|
|
if ((*response)->responseCode < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
(*response)->content = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
if ((*response)->responseCode == 500 || (*response)->responseCode == 200) {
|
2009-09-04 16:24:25 +00:00
|
|
|
(*response)->document = xmlReadDoc(BAD_CAST (*response)->content, "",
|
|
|
|
NULL, XML_PARSE_NONET);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
if ((*response)->document == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Response for call to '%s' could not be parsed"),
|
2009-11-22 20:32:23 +00:00
|
|
|
methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
if (xmlDocGetRootElement((*response)->document) == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Response for call to '%s' is an empty XML document"),
|
2009-11-22 20:32:23 +00:00
|
|
|
methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
xpathContext = xmlXPathNewContext((*response)->document);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
if (xpathContext == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not create XPath context"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv",
|
2009-07-23 20:21:08 +00:00
|
|
|
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/");
|
2009-11-22 20:32:23 +00:00
|
|
|
xmlXPathRegisterNs(xpathContext, BAD_CAST "vim", BAD_CAST "urn:vim25");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
if ((*response)->responseCode == 500) {
|
|
|
|
(*response)->node =
|
2010-02-04 21:52:34 +00:00
|
|
|
virXPathNode("/soapenv:Envelope/soapenv:Body/soapenv:Fault",
|
2009-11-22 20:32:23 +00:00
|
|
|
xpathContext);
|
2009-09-04 16:08:52 +00:00
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
if ((*response)->node == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault is unknown, XPath evaluation failed"),
|
2009-11-22 20:32:23 +00:00
|
|
|
(*response)->responseCode, methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:08:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Fault_Deserialize((*response)->node, &fault) < 0) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault is unknown, deserialization failed"),
|
2009-11-22 20:32:23 +00:00
|
|
|
(*response)->responseCode, methodName);
|
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
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault: %s - %s"), (*response)->responseCode,
|
2009-11-22 20:32:23 +00:00
|
|
|
methodName, fault->faultcode, fault->faultstring);
|
2010-01-05 01:44:33 +00:00
|
|
|
|
|
|
|
/* FIXME: Dump raw response until detail part gets deserialized */
|
|
|
|
VIR_DEBUG("HTTP response code %d for call to '%s' [[[[%s]]]]",
|
|
|
|
(*response)->responseCode, methodName,
|
|
|
|
(*response)->content);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-22 20:32:23 +00:00
|
|
|
} else {
|
|
|
|
if (virAsprintf(&xpathExpression,
|
|
|
|
"/soapenv:Envelope/soapenv:Body/vim:%sResponse",
|
|
|
|
methodName) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-22 20:32:23 +00:00
|
|
|
}
|
2009-09-04 16:08:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
responseNode = virXPathNode(xpathExpression, xpathContext);
|
2009-09-04 16:08:52 +00:00
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
if (responseNode == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("XPath evaluation of response for call to '%s' "
|
|
|
|
"failed"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:08:52 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
xpathContext->node = responseNode;
|
2010-02-04 21:52:34 +00:00
|
|
|
(*response)->node = virXPathNode("./vim:returnval", xpathContext);
|
2009-09-04 16:08:52 +00:00
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
switch (occurrence) {
|
|
|
|
case esxVI_Occurrence_RequiredItem:
|
2010-03-06 16:56:28 +00:00
|
|
|
if ((*response)->node == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Call to '%s' returned an empty result, "
|
|
|
|
"expecting a non-empty result"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-06 16:56:28 +00:00
|
|
|
} else if ((*response)->node->next != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Call to '%s' returned a list, expecting "
|
|
|
|
"exactly one item"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-06 16:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_Occurrence_RequiredList:
|
2009-11-22 20:32:23 +00:00
|
|
|
if ((*response)->node == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Call to '%s' returned an empty result, "
|
|
|
|
"expecting a non-empty result"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-22 20:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_Occurrence_OptionalItem:
|
|
|
|
if ((*response)->node != NULL &&
|
|
|
|
(*response)->node->next != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Call to '%s' returned a list, expecting "
|
|
|
|
"exactly one item"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-22 20:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-03-06 16:56:28 +00:00
|
|
|
case esxVI_Occurrence_OptionalList:
|
2009-11-22 20:32:23 +00:00
|
|
|
/* Any amount of items is valid */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_Occurrence_None:
|
|
|
|
if ((*response)->node != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Call to '%s' returned something, expecting "
|
|
|
|
"an empty result"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-22 20:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Invalid argument (occurrence)"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-04 16:08:52 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2009-11-22 20:32:23 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("HTTP response code %d for call to '%s'"),
|
2009-11-22 20:32:23 +00:00
|
|
|
(*response)->responseCode, methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
esxVI_Response_Free(response);
|
|
|
|
esxVI_Fault_Free(&fault);
|
|
|
|
}
|
|
|
|
|
2009-11-22 20:32:23 +00:00
|
|
|
VIR_FREE(xpathExpression);
|
|
|
|
xmlXPathFreeContext(xpathContext);
|
|
|
|
|
|
|
|
return result;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2009-09-04 16:24:25 +00:00
|
|
|
* Response
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
/* esxVI_Response_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(Response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
/* esxVI_Response_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(Response,
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(item->content);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (item->document != NULL) {
|
|
|
|
xmlFreeDoc(item->document);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Enumeration
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_AnyType *anyType, int *value)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (anyType == NULL || value == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = 0; /* undefined */
|
|
|
|
|
2010-03-06 16:56:28 +00:00
|
|
|
if (anyType->type != enumeration->type) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting type '%s' but found '%s'"),
|
2010-03-06 16:56:28 +00:00
|
|
|
esxVI_Type_ToString(enumeration->type),
|
|
|
|
esxVI_Type_ToString(anyType->type));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; enumeration->values[i].name != NULL; ++i) {
|
|
|
|
if (STREQ(anyType->value, enumeration->values[i].name)) {
|
|
|
|
*value = enumeration->values[i].value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Unknown value '%s' for %s"), anyType->value,
|
2010-03-06 16:56:28 +00:00
|
|
|
esxVI_Type_ToString(enumeration->type));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Enumeration_Serialize(const esxVI_Enumeration *enumeration,
|
2010-02-23 00:06:58 +00:00
|
|
|
int value, const char *element, virBufferPtr output)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
if (element == NULL || output == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == 0) { /* undefined */
|
2010-02-23 00:06:58 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; enumeration->values[i].name != NULL; ++i) {
|
|
|
|
if (value == enumeration->values[i].value) {
|
|
|
|
name = enumeration->values[i].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-03-06 16:56:28 +00:00
|
|
|
ESV_VI__XML_TAG__OPEN(output, element,
|
|
|
|
esxVI_Type_ToString(enumeration->type));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
virBufferAdd(output, name, -1);
|
|
|
|
|
|
|
|
ESV_VI__XML_TAG__CLOSE(output, element);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
|
2009-07-23 20:21:08 +00:00
|
|
|
xmlNodePtr node, int *value)
|
|
|
|
{
|
|
|
|
int i;
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
char *name = NULL;
|
|
|
|
|
|
|
|
if (value == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*value = 0; /* undefined */
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_DeserializeValue(node, &name) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; enumeration->values[i].name != NULL; ++i) {
|
|
|
|
if (STREQ(name, enumeration->values[i].name)) {
|
|
|
|
*value = enumeration->values[i].value;
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
break;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"),
|
|
|
|
name, esxVI_Type_ToString(enumeration->type));
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
VIR_FREE(name);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* List
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_List_Append(esxVI_List **list, esxVI_List *item)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
esxVI_List *next = NULL;
|
|
|
|
|
|
|
|
if (list == NULL || item == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*list == NULL) {
|
|
|
|
*list = item;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
next = *list;
|
|
|
|
|
|
|
|
while (next->_next != NULL) {
|
|
|
|
next = next->_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
next->_next = item;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_List_DeepCopy(esxVI_List **destList, esxVI_List *srcList,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_List_DeepCopyFunc deepCopyFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc)
|
|
|
|
{
|
|
|
|
esxVI_List *dest = NULL;
|
|
|
|
esxVI_List *src = NULL;
|
|
|
|
|
|
|
|
if (destList == NULL || *destList != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (src = srcList; src != NULL; src = src->_next) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (deepCopyFunc(&dest, src) < 0 ||
|
|
|
|
esxVI_List_Append(destList, dest) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
freeFunc(&dest);
|
|
|
|
freeFunc(destList);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list,
|
2009-09-23 12:29:39 +00:00
|
|
|
esxVI_List_CastFromAnyTypeFunc castFromAnyTypeFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-09-23 12:29:39 +00:00
|
|
|
xmlNodePtr childNode = NULL;
|
|
|
|
esxVI_AnyType *childAnyType = NULL;
|
|
|
|
esxVI_List *item = NULL;
|
|
|
|
|
|
|
|
if (list == NULL || *list != NULL ||
|
|
|
|
castFromAnyTypeFunc == NULL || freeFunc == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-12-15 18:22:31 +00:00
|
|
|
return -1;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (anyType == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! STRPREFIX(anyType->other, "ArrayOf")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Expecting type to begin with 'ArrayOf' but found '%s'"),
|
2009-09-23 12:29:39 +00:00
|
|
|
anyType->other);
|
2009-12-15 18:22:31 +00:00
|
|
|
return -1;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 16:56:28 +00:00
|
|
|
for (childNode = anyType->node->children; childNode != NULL;
|
2009-09-23 12:29:39 +00:00
|
|
|
childNode = childNode->next) {
|
|
|
|
if (childNode->type != XML_ELEMENT_NODE) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Wrong XML element type %d"), childNode->type);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_AnyType_Free(&childAnyType);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_Deserialize(childNode, &childAnyType) < 0 ||
|
|
|
|
castFromAnyTypeFunc(childAnyType, &item) < 0 ||
|
|
|
|
esxVI_List_Append(list, item) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
item = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
freeFunc(&item);
|
|
|
|
freeFunc(list);
|
|
|
|
}
|
|
|
|
|
2009-09-23 12:29:39 +00:00
|
|
|
esxVI_AnyType_Free(&childAnyType);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_List_Serialize(esxVI_List *list, const char *element,
|
2010-02-23 00:06:58 +00:00
|
|
|
virBufferPtr output,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_List_SerializeFunc serializeFunc)
|
|
|
|
{
|
|
|
|
esxVI_List *item = NULL;
|
|
|
|
|
|
|
|
if (element == NULL || output == NULL || serializeFunc == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list == NULL) {
|
2010-02-23 00:06:58 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (item = list; item != NULL; item = item->_next) {
|
2010-02-23 00:06:58 +00:00
|
|
|
if (serializeFunc(item, element, output) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_List_DeserializeFunc deserializeFunc,
|
|
|
|
esxVI_List_FreeFunc freeFunc)
|
|
|
|
{
|
|
|
|
esxVI_List *item = NULL;
|
|
|
|
|
|
|
|
if (list == NULL || *list != NULL ||
|
|
|
|
deserializeFunc == NULL || freeFunc == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; node != NULL; node = node->next) {
|
|
|
|
if (node->type != XML_ELEMENT_NODE) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Wrong XML element type %d"), node->type);
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (deserializeFunc(node, &item) < 0 ||
|
|
|
|
esxVI_List_Append(list, item) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-10-22 07:47:51 +00:00
|
|
|
item = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
2009-10-22 07:47:51 +00:00
|
|
|
freeFunc(&item);
|
2009-07-23 20:21:08 +00:00
|
|
|
freeFunc(list);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Utility and Convenience Functions
|
2009-10-18 19:31:46 +00:00
|
|
|
*
|
|
|
|
* Function naming scheme:
|
|
|
|
* - 'lookup' functions query the ESX or vCenter for information
|
|
|
|
* - 'get' functions get information from a local object
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Alloc(void **ptrptr, size_t size)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
if (ptrptr == NULL || *ptrptr != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAllocN(ptrptr, size, 1) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-08-21 16:49:18 +00:00
|
|
|
esxVI_BuildSelectSet(esxVI_SelectionSpec **selectSet,
|
|
|
|
const char *name, const char *type,
|
|
|
|
const char *path, const char *selectSetNames)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
esxVI_TraversalSpec *traversalSpec = NULL;
|
|
|
|
esxVI_SelectionSpec *selectionSpec = NULL;
|
|
|
|
const char *currentSelectSetName = NULL;
|
|
|
|
|
2010-08-26 22:07:23 +00:00
|
|
|
if (selectSet == NULL) {
|
|
|
|
/*
|
|
|
|
* Don't check for *selectSet != NULL here because selectSet is a list
|
|
|
|
* and might contain items already. This function appends to selectSet.
|
|
|
|
*/
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_TraversalSpec_Alloc(&traversalSpec) < 0 ||
|
2010-03-06 16:56:28 +00:00
|
|
|
esxVI_String_DeepCopyValue(&traversalSpec->name, name) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_DeepCopyValue(&traversalSpec->type, type) < 0 ||
|
|
|
|
esxVI_String_DeepCopyValue(&traversalSpec->path, path) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
traversalSpec->skip = esxVI_Boolean_False;
|
|
|
|
|
|
|
|
if (selectSetNames != NULL) {
|
|
|
|
currentSelectSetName = selectSetNames;
|
|
|
|
|
|
|
|
while (currentSelectSetName != NULL && *currentSelectSetName != '\0') {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0 ||
|
|
|
|
esxVI_String_DeepCopyValue(&selectionSpec->name,
|
2009-07-23 20:21:08 +00:00
|
|
|
currentSelectSetName) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
selectionSpec) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2010-03-02 22:15:00 +00:00
|
|
|
selectionSpec = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
currentSelectSetName += strlen(currentSelectSetName) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_SelectionSpec_AppendToList(selectSet,
|
2010-03-06 16:56:28 +00:00
|
|
|
esxVI_SelectionSpec_DynamicCast
|
|
|
|
(traversalSpec)) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
esxVI_TraversalSpec_Free(&traversalSpec);
|
2010-03-02 22:15:00 +00:00
|
|
|
esxVI_SelectionSpec_Free(&selectionSpec);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-08-21 16:49:18 +00:00
|
|
|
esxVI_BuildSelectSetCollection(esxVI_Context *ctx)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-07-31 21:57:42 +00:00
|
|
|
/* Folder -> childEntity (ManagedEntity) */
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_folderToChildEntity,
|
|
|
|
"folderToChildEntity",
|
|
|
|
"Folder", "childEntity",
|
|
|
|
"folderToChildEntity\0") < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* ComputeResource -> host (HostSystem) */
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_computeResourceToHost,
|
|
|
|
"computeResourceToHost",
|
|
|
|
"ComputeResource", "host", NULL) < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
/* ComputeResource -> datastore (Datastore) *//*
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_computeResourceToDatastore,
|
|
|
|
"computeResourceToDatastore",
|
|
|
|
"ComputeResource", "datastore", NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/* ResourcePool -> resourcePool (ResourcePool) *//*
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_resourcePoolToVm,
|
|
|
|
"resourcePoolToResourcePool",
|
|
|
|
"ResourcePool", "resourcePool",
|
|
|
|
"resourcePoolToResourcePool\0"
|
|
|
|
"resourcePoolToVm\0") < 0) {
|
|
|
|
return -1;
|
|
|
|
}*/
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
/* ResourcePool -> vm (VirtualMachine) *//*
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_resourcePoolToVm,
|
|
|
|
"resourcePoolToVm",
|
|
|
|
"ResourcePool", "vm", NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}*/
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* HostSystem -> parent (ComputeResource) */
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_hostSystemToParent,
|
|
|
|
"hostSystemToParent",
|
|
|
|
"HostSystem", "parent", NULL) < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* HostSystem -> vm (VirtualMachine) */
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_hostSystemToVm,
|
|
|
|
"hostSystemToVm",
|
|
|
|
"HostSystem", "vm", NULL) < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* HostSystem -> datastore (Datastore) */
|
2010-08-21 16:49:18 +00:00
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_hostSystemToDatastore,
|
|
|
|
"hostSystemToDatastore",
|
|
|
|
"HostSystem", "datastore", NULL) < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
/* Folder -> parent (Folder, Datacenter) */
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_computeResourceToParentToParent,
|
|
|
|
"managedEntityToParent",
|
|
|
|
"ManagedEntity", "parent", NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
/* ComputeResource -> parent (Folder) */
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_computeResourceToParentToParent,
|
|
|
|
"computeResourceToParent",
|
|
|
|
"ComputeResource", "parent",
|
|
|
|
"managedEntityToParent\0") < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_EnsureSession(esxVI_Context *ctx)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-09-05 14:53:10 +00:00
|
|
|
esxVI_Boolean active = esxVI_Boolean_Undefined;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *sessionManager = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_UserSession *currentSession = NULL;
|
|
|
|
|
|
|
|
if (ctx->session == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (ctx->hasSessionIsActive) {
|
|
|
|
/*
|
|
|
|
* Use SessionIsActive to check if there is an active session for this
|
|
|
|
* connection an re-login in there isn't.
|
|
|
|
*/
|
|
|
|
if (esxVI_SessionIsActive(ctx, ctx->session->key,
|
|
|
|
ctx->session->userName, &active) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-30 10:16:01 +00:00
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (active != esxVI_Boolean_True) {
|
|
|
|
esxVI_UserSession_Free(&ctx->session);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
|
|
|
|
&ctx->session) < 0) {
|
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2010-09-05 14:53:10 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Query the session manager for the current session of this connection
|
|
|
|
* and re-login if there is no current session for this connection.
|
|
|
|
*/
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"currentSession") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
|
|
|
|
"SessionManager", propertyNameList,
|
|
|
|
&sessionManager) < 0) {
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
for (dynamicProperty = sessionManager->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "currentSession")) {
|
|
|
|
if (esxVI_UserSession_CastFromAnyType(dynamicProperty->val,
|
|
|
|
¤tSession) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (currentSession == NULL) {
|
|
|
|
esxVI_UserSession_Free(&ctx->session);
|
|
|
|
|
|
|
|
if (esxVI_Login(ctx, ctx->username, ctx->password, NULL,
|
|
|
|
&ctx->session) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STRNEQ(ctx->session->key, currentSession->key)) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Key of the current session differs from the key at "
|
|
|
|
"last login"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
result = 0;
|
2010-05-19 20:59:32 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
2010-09-05 14:53:10 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&sessionManager);
|
|
|
|
esxVI_UserSession_Free(¤tSession);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupObjectContentByType(esxVI_Context *ctx,
|
2009-10-18 19:31:46 +00:00
|
|
|
esxVI_ManagedObjectReference *root,
|
|
|
|
const char *type,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **objectContentList)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectSpec *objectSpec = NULL;
|
|
|
|
esxVI_PropertySpec *propertySpec = NULL;
|
|
|
|
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (objectContentList == NULL || *objectContentList != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
objectSpec->obj = root;
|
|
|
|
objectSpec->skip = esxVI_Boolean_False;
|
|
|
|
|
2010-08-21 16:49:18 +00:00
|
|
|
if (STRNEQ(root->type, type)) {
|
|
|
|
if (STREQ(root->type, "Folder")) {
|
|
|
|
if (STREQ(type, "Datacenter") || STREQ(type, "ComputeResource")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_folderToChildEntity;
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STREQ(root->type, "ComputeResource")) {
|
|
|
|
if (STREQ(type, "HostSystem")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_computeResourceToHost;
|
|
|
|
} else if (STREQ(type, "Datacenter")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_computeResourceToParentToParent;
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STREQ(root->type, "HostSystem")) {
|
|
|
|
if (STREQ(type, "ComputeResource")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_hostSystemToParent;
|
|
|
|
} else if (STREQ(type, "VirtualMachine")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_hostSystemToVm;
|
|
|
|
} else if (STREQ(type, "Datastore")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_hostSystemToDatastore;
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup from '%s'"), root->type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
propertySpec->type = (char *)type;
|
|
|
|
propertySpec->pathSet = propertyNameList;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_PropertyFilterSpec_Alloc(&propertyFilterSpec) < 0 ||
|
|
|
|
esxVI_PropertySpec_AppendToList(&propertyFilterSpec->propSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
propertySpec) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
objectSpec) < 0) {
|
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
|
|
|
result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
|
2009-07-23 20:21:08 +00:00
|
|
|
objectContentList);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/*
|
|
|
|
* Remove values given by the caller from the data structures to prevent
|
|
|
|
* them from being freed by the call to esxVI_PropertyFilterSpec_Free().
|
|
|
|
*/
|
|
|
|
if (objectSpec != NULL) {
|
|
|
|
objectSpec->obj = NULL;
|
|
|
|
objectSpec->selectSet = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertySpec != NULL) {
|
|
|
|
propertySpec->type = NULL;
|
|
|
|
propertySpec->pathSet = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:03:22 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetManagedEntityStatus(esxVI_ObjectContent *objectContent,
|
2009-09-04 16:03:22 +00:00
|
|
|
const char *propertyName,
|
|
|
|
esxVI_ManagedEntityStatus *managedEntityStatus)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
return esxVI_ManagedEntityStatus_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, managedEntityStatus);
|
2009-09-04 16:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Missing '%s' property while looking for "
|
|
|
|
"ManagedEntityStatus"), propertyName);
|
2009-09-04 16:03:22 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachinePowerState(esxVI_ObjectContent *virtualMachine,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_VirtualMachinePowerState *powerState)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
|
|
|
|
return esxVI_VirtualMachinePowerState_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, powerState);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing 'runtime.powerState' property"));
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int
|
|
|
|
esxVI_GetVirtualMachineQuestionInfo
|
2010-01-15 22:05:26 +00:00
|
|
|
(esxVI_ObjectContent *virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_VirtualMachineQuestionInfo **questionInfo)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (questionInfo == NULL || *questionInfo != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.question")) {
|
|
|
|
if (esxVI_VirtualMachineQuestionInfo_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, questionInfo) < 0) {
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
int
|
|
|
|
esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName,
|
|
|
|
esxVI_Boolean *value, esxVI_Occurrence occurence)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (value == NULL || *value != esxVI_Boolean_Undefined) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
|
|
|
esxVI_Type_Boolean) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = dynamicProperty->val->boolean;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*value == esxVI_Boolean_Undefined &&
|
|
|
|
occurence == esxVI_Occurrence_RequiredItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-06 17:53:39 +00:00
|
|
|
int
|
|
|
|
esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
|
|
|
|
esxVI_Long **value, esxVI_Occurrence occurence)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (value == NULL || *value != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*value == NULL && occurence == esxVI_Occurrence_RequiredItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetStringValue(esxVI_ObjectContent *objectContent,
|
|
|
|
const char *propertyName,
|
|
|
|
char **value, esxVI_Occurrence occurence)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (value == NULL || *value != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
|
|
|
esxVI_Type_String) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = dynamicProperty->val->string;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*value == NULL && occurence == esxVI_Occurrence_RequiredItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetManagedObjectReference(esxVI_ObjectContent *objectContent,
|
|
|
|
const char *propertyName,
|
|
|
|
esxVI_ManagedObjectReference **value,
|
|
|
|
esxVI_Occurrence occurence)
|
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (value == NULL || *value != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
if (esxVI_ManagedObjectReference_CastFromAnyType
|
|
|
|
(dynamicProperty->val, value) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*value == NULL && occurence == esxVI_Occurrence_RequiredItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupNumberOfDomainsByPowerState(esxVI_Context *ctx,
|
2009-10-18 19:31:46 +00:00
|
|
|
esxVI_VirtualMachinePowerState powerState,
|
|
|
|
esxVI_Boolean inverse)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
bool success = false;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_VirtualMachinePowerState powerState_;
|
2010-05-19 20:59:32 +00:00
|
|
|
int count = 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
|
|
|
"runtime.powerState") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(ctx, propertyNameList,
|
|
|
|
&virtualMachineList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine != NULL;
|
|
|
|
virtualMachine = virtualMachine->_next) {
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
|
|
|
dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
|
|
|
|
if (esxVI_VirtualMachinePowerState_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, &powerState_) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((inverse != esxVI_Boolean_True &&
|
|
|
|
powerState_ == powerState) ||
|
|
|
|
(inverse == esxVI_Boolean_True &&
|
|
|
|
powerState_ != powerState)) {
|
2010-05-19 20:59:32 +00:00
|
|
|
count++;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
success = true;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return success ? count : -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
|
2009-07-23 20:21:08 +00:00
|
|
|
int *id, char **name, unsigned char *uuid)
|
|
|
|
{
|
|
|
|
const char *uuid_string = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
2009-09-04 16:03:22 +00:00
|
|
|
esxVI_ManagedEntityStatus configStatus = esxVI_ManagedEntityStatus_Undefined;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (STRNEQ(virtualMachine->obj->type, "VirtualMachine")) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("ObjectContent does not reference a virtual machine"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id != NULL) {
|
|
|
|
if (esxUtil_ParseVirtualMachineIDString
|
|
|
|
(virtualMachine->obj->value, id) < 0 || *id <= 0) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not parse positive integer from '%s'"),
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine->obj->value);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != NULL) {
|
|
|
|
if (*name != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
|
|
|
dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "name")) {
|
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) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = strdup(dynamicProperty->val->string);
|
|
|
|
|
|
|
|
if (*name == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2010-10-12 17:37:39 +00:00
|
|
|
if (esxUtil_UnescapeHexPercent(*name) < 0) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain name contains invalid escape sequence"));
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*name == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not get name of virtual machine"));
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uuid != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_GetManagedEntityStatus(virtualMachine, "configStatus",
|
2009-09-04 16:03:22 +00:00
|
|
|
&configStatus) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configStatus == esxVI_ManagedEntityStatus_Green) {
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
|
|
|
dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.uuid")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnyType_ExpectType(dynamicProperty->val,
|
2009-09-04 16:03:22 +00:00
|
|
|
esxVI_Type_String) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
uuid_string = dynamicProperty->val->string;
|
|
|
|
break;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2009-09-04 16:03:22 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:03:22 +00:00
|
|
|
if (uuid_string == NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not get UUID of virtual machine"));
|
2009-09-04 16:03:22 +00:00
|
|
|
goto failure;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:03:22 +00:00
|
|
|
if (virUUIDParse(uuid_string, uuid) < 0) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not parse UUID from string '%s'"),
|
2009-09-04 16:03:22 +00:00
|
|
|
uuid_string);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 16:03:22 +00:00
|
|
|
VIR_WARN0("Cannot access UUID, because 'configStatus' property "
|
|
|
|
"indicates a config problem");
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
if (name != NULL) {
|
|
|
|
VIR_FREE(*name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
int
|
|
|
|
esxVI_GetNumberOfSnapshotTrees
|
|
|
|
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree;
|
|
|
|
|
|
|
|
for (snapshotTree = snapshotTreeList; snapshotTree != NULL;
|
|
|
|
snapshotTree = snapshotTree->_next) {
|
|
|
|
count += 1 + esxVI_GetNumberOfSnapshotTrees
|
|
|
|
(snapshotTree->childSnapshotList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
|
|
|
|
char **names, int nameslen)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int result;
|
|
|
|
int i;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree;
|
|
|
|
|
|
|
|
for (snapshotTree = snapshotTreeList;
|
|
|
|
snapshotTree != NULL && count < nameslen;
|
|
|
|
snapshotTree = snapshotTree->_next) {
|
|
|
|
names[count] = strdup(snapshotTree->name);
|
|
|
|
|
|
|
|
if (names[count] == NULL) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (count >= nameslen) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
|
|
|
|
names + count, nameslen - count);
|
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
VIR_FREE(names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetSnapshotTreeByName
|
|
|
|
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, const char *name,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **snapshotTree,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **snapshotTreeParent,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
esxVI_VirtualMachineSnapshotTree *candidate;
|
|
|
|
|
|
|
|
if (snapshotTree == NULL || *snapshotTree != NULL ||
|
|
|
|
snapshotTreeParent == NULL || *snapshotTreeParent != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (candidate = snapshotTreeList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STREQ(candidate->name, name)) {
|
|
|
|
*snapshotTree = candidate;
|
|
|
|
*snapshotTreeParent = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_GetSnapshotTreeByName(candidate->childSnapshotList, name,
|
|
|
|
snapshotTree, snapshotTreeParent,
|
|
|
|
occurrence) > 0) {
|
|
|
|
if (*snapshotTreeParent == NULL) {
|
|
|
|
*snapshotTreeParent = candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("Could not find snapshot with name '%s'"), name);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetSnapshotTreeBySnapshot
|
|
|
|
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
|
|
|
|
esxVI_ManagedObjectReference *snapshot,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **snapshotTree)
|
|
|
|
{
|
|
|
|
esxVI_VirtualMachineSnapshotTree *candidate;
|
|
|
|
|
|
|
|
if (snapshotTree == NULL || *snapshotTree != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (candidate = snapshotTreeList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STREQ(candidate->snapshot->value, snapshot->value)) {
|
|
|
|
*snapshotTree = candidate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_GetSnapshotTreeBySnapshot(candidate->childSnapshotList,
|
|
|
|
snapshot, snapshotTree) >= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("Could not find domain snapshot with internal name '%s'"),
|
|
|
|
snapshot->value);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
int esxVI_LookupHostSystemProperties(esxVI_Context *ctx,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **hostSystem)
|
2009-09-23 12:09:44 +00:00
|
|
|
{
|
2010-07-31 21:57:42 +00:00
|
|
|
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
|
|
|
|
"HostSystem", propertyNameList,
|
2010-08-21 16:49:18 +00:00
|
|
|
hostSystem);
|
2009-09-23 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(esxVI_Context *ctx,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **virtualMachineList)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-07-31 21:57:42 +00:00
|
|
|
/* FIXME: Switch from ctx->hostSystem to ctx->computeResource->resourcePool
|
|
|
|
* for cluster support */
|
|
|
|
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
|
|
|
|
"VirtualMachine", propertyNameList,
|
|
|
|
virtualMachineList);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String *propertyNameList,
|
2009-09-23 12:40:41 +00:00
|
|
|
esxVI_ObjectContent **virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence occurrence)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *managedObjectReference = NULL;
|
2009-09-23 12:40:41 +00:00
|
|
|
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (virtualMachine == NULL || *virtualMachine != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-23 00:06:58 +00:00
|
|
|
virUUIDFormat(uuid, uuid_string);
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
if (esxVI_FindByUuid(ctx, ctx->datacenter->_reference, uuid_string,
|
|
|
|
esxVI_Boolean_True, &managedObjectReference) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-23 12:40:41 +00:00
|
|
|
if (managedObjectReference == NULL) {
|
2009-11-22 20:18:45 +00:00
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
2010-08-08 19:32:29 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
2009-09-23 12:40:41 +00:00
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not find domain with UUID '%s'"),
|
|
|
|
uuid_string);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_LookupObjectContentByType(ctx, managedObjectReference,
|
2009-10-18 19:31:46 +00:00
|
|
|
"VirtualMachine", propertyNameList,
|
|
|
|
virtualMachine) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ManagedObjectReference_Free(&managedObjectReference);
|
|
|
|
|
|
|
|
return result;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **virtualMachine,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-03-02 23:57:57 +00:00
|
|
|
esxVI_String *completePropertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
|
|
|
esxVI_ObjectContent *candidate = NULL;
|
|
|
|
char *name_candidate = NULL;
|
|
|
|
|
|
|
|
if (virtualMachine == NULL || *virtualMachine != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-03-02 23:57:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_DeepCopyList(&completePropertyNameList,
|
|
|
|
propertyNameList) < 0 ||
|
|
|
|
esxVI_String_AppendValueToList(&completePropertyNameList, "name") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupVirtualMachineList(ctx, completePropertyNameList,
|
|
|
|
&virtualMachineList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (candidate = virtualMachineList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
|
|
|
VIR_FREE(name_candidate);
|
|
|
|
|
|
|
|
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
|
|
|
|
NULL) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ(name, name_candidate)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*virtualMachine == NULL) {
|
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
2010-08-08 19:32:29 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Could not find domain with name '%s'"), name);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-03-02 23:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2010-03-02 23:57:57 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&completePropertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
|
|
|
VIR_FREE(name_candidate);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
|
2010-01-15 22:05:26 +00:00
|
|
|
(esxVI_Context *ctx, const unsigned char *uuid,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_String *propertyNameList, esxVI_ObjectContent **virtualMachine,
|
|
|
|
esxVI_Boolean autoAnswer)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_String *completePropertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
|
|
|
|
esxVI_TaskInfo *pendingTaskInfoList = NULL;
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Boolean blocked = esxVI_Boolean_Undefined;
|
2009-11-15 21:22:47 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_DeepCopyList(&completePropertyNameList,
|
2009-11-15 21:22:47 +00:00
|
|
|
propertyNameList) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_AppendValueListToList(&completePropertyNameList,
|
2009-11-15 21:22:47 +00:00
|
|
|
"runtime.question\0"
|
|
|
|
"recentTask\0") < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(ctx, uuid, completePropertyNameList,
|
2009-11-15 21:22:47 +00:00
|
|
|
virtualMachine,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_GetVirtualMachineQuestionInfo(*virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
&questionInfo) < 0 ||
|
|
|
|
esxVI_LookupPendingTaskInfoListByVirtualMachine
|
2010-01-15 22:05:26 +00:00
|
|
|
(ctx, *virtualMachine, &pendingTaskInfoList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (questionInfo != NULL &&
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_HandleVirtualMachineQuestion(ctx, (*virtualMachine)->obj,
|
2010-07-25 15:45:19 +00:00
|
|
|
questionInfo, autoAnswer,
|
|
|
|
&blocked) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pendingTaskInfoList != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("Other tasks are pending for this domain"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&completePropertyNameList);
|
|
|
|
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
|
|
|
|
esxVI_TaskInfo_Free(&pendingTaskInfoList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupDatastoreList(esxVI_Context *ctx, esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **datastoreList)
|
|
|
|
{
|
|
|
|
/* FIXME: Switch from ctx->hostSystem to ctx->computeResource for cluster
|
|
|
|
* support */
|
|
|
|
return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
|
|
|
|
"Datastore", propertyNameList,
|
2010-08-21 16:49:18 +00:00
|
|
|
datastoreList);
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_String *propertyNameList,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_ObjectContent **datastore,
|
2009-11-22 20:18:45 +00:00
|
|
|
esxVI_Occurrence occurrence)
|
2009-09-23 12:52:36 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_String *completePropertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *datastoreList = NULL;
|
|
|
|
esxVI_ObjectContent *candidate = NULL;
|
2010-08-01 17:53:00 +00:00
|
|
|
char *name_candidate;
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
if (datastore == NULL || *datastore != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-09-23 12:52:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get all datastores */
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_DeepCopyList(&completePropertyNameList,
|
2009-09-23 12:52:36 +00:00
|
|
|
propertyNameList) < 0 ||
|
2010-08-01 17:53:00 +00:00
|
|
|
esxVI_String_AppendValueToList(&completePropertyNameList,
|
|
|
|
"summary.name") < 0 ||
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_LookupDatastoreList(ctx, completePropertyNameList,
|
|
|
|
&datastoreList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
/* Search for a matching datastore */
|
|
|
|
for (candidate = datastoreList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
|
|
|
name_candidate = NULL;
|
|
|
|
|
|
|
|
if (esxVI_GetStringValue(candidate, "summary.name", &name_candidate,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
2010-08-01 17:53:00 +00:00
|
|
|
|
|
|
|
if (STREQ(name_candidate, name)) {
|
|
|
|
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-08-08 19:32:29 +00:00
|
|
|
/* Found datastore with matching name */
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
2010-08-01 17:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*datastore == NULL && occurrence != esxVI_Occurrence_OptionalItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datastore with name '%s'"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&completePropertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastoreList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx,
|
|
|
|
const char *absolutePath,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **datastore,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *completePropertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *datastoreList = NULL;
|
|
|
|
esxVI_ObjectContent *candidate = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_DatastoreHostMount *datastoreHostMountList = NULL;
|
|
|
|
esxVI_DatastoreHostMount *datastoreHostMount = NULL;
|
|
|
|
|
|
|
|
if (datastore == NULL || *datastore != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get all datastores */
|
|
|
|
if (esxVI_String_DeepCopyList(&completePropertyNameList,
|
|
|
|
propertyNameList) < 0 ||
|
|
|
|
esxVI_String_AppendValueToList(&completePropertyNameList, "host") < 0 ||
|
|
|
|
esxVI_LookupDatastoreList(ctx, completePropertyNameList,
|
|
|
|
&datastoreList) < 0) {
|
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for a matching datastore */
|
|
|
|
for (candidate = datastoreList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
2010-08-01 17:53:00 +00:00
|
|
|
esxVI_DatastoreHostMount_Free(&datastoreHostMountList);
|
2009-09-23 13:08:25 +00:00
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
for (dynamicProperty = candidate->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
2010-08-01 17:53:00 +00:00
|
|
|
if (STREQ(dynamicProperty->name, "host")) {
|
|
|
|
if (esxVI_DatastoreHostMount_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, &datastoreHostMountList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 13:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
if (datastoreHostMountList == NULL) {
|
|
|
|
continue;
|
2009-09-23 13:08:25 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
for (datastoreHostMount = datastoreHostMountList;
|
|
|
|
datastoreHostMount != NULL;
|
|
|
|
datastoreHostMount = datastoreHostMount->_next) {
|
|
|
|
if (STRNEQ(ctx->hostSystem->_reference->value,
|
|
|
|
datastoreHostMount->key->value)) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-23 13:08:25 +00:00
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
if (STRPREFIX(absolutePath, datastoreHostMount->mountInfo->path)) {
|
|
|
|
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
/* Found datastore with matching mount path */
|
2010-08-08 19:32:29 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
if (*datastore == NULL && occurrence != esxVI_Occurrence_OptionalItem) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datastore containing absolute path '%s'"),
|
|
|
|
absolutePath);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-09-23 12:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-09-23 12:52:36 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&completePropertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastoreList);
|
2010-08-01 17:53:00 +00:00
|
|
|
esxVI_DatastoreHostMount_Free(&datastoreHostMountList);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
return result;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-01 20:11:38 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupDatastoreHostMount(esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *datastore,
|
|
|
|
esxVI_DatastoreHostMount **hostMount)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *objectContent = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_DatastoreHostMount *hostMountList = NULL;
|
|
|
|
esxVI_DatastoreHostMount *candidate = NULL;
|
|
|
|
|
|
|
|
if (hostMount == NULL || *hostMount != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, datastore, "Datastore",
|
2010-08-21 16:49:18 +00:00
|
|
|
propertyNameList, &objectContent) < 0) {
|
2010-08-01 20:11:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "host")) {
|
|
|
|
if (esxVI_DatastoreHostMount_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, &hostMountList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (candidate = hostMountList; candidate != NULL;
|
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*hostMount == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not lookup datastore host mount"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&objectContent);
|
|
|
|
esxVI_DatastoreHostMount_Free(&hostMountList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupTaskInfoByTask(esxVI_Context *ctx,
|
|
|
|
esxVI_ManagedObjectReference *task,
|
|
|
|
esxVI_TaskInfo **taskInfo)
|
2009-11-15 21:22:47 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *objectContent = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
|
|
|
if (taskInfo == NULL || *taskInfo != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList, "info") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList,
|
2009-11-15 21:22:47 +00:00
|
|
|
&objectContent) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "info")) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_TaskInfo_CastFromAnyType(dynamicProperty->val,
|
2009-11-15 21:22:47 +00:00
|
|
|
taskInfo) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&objectContent);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupPendingTaskInfoListByVirtualMachine
|
2010-01-15 22:05:26 +00:00
|
|
|
(esxVI_Context *ctx, esxVI_ObjectContent *virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_TaskInfo **pendingTaskInfoList)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ManagedObjectReference *recentTaskList = NULL;
|
|
|
|
esxVI_ManagedObjectReference *recentTask = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
|
|
|
|
|
|
|
if (pendingTaskInfoList == NULL || *pendingTaskInfoList != NULL) {
|
2010-04-02 19:34:31 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get list of recent tasks */
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "recentTask")) {
|
|
|
|
if (esxVI_ManagedObjectReference_CastListFromAnyType
|
2010-03-06 16:56:28 +00:00
|
|
|
(dynamicProperty->val, &recentTaskList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup task info for each task */
|
|
|
|
for (recentTask = recentTaskList; recentTask != NULL;
|
|
|
|
recentTask = recentTask->_next) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfo->state == esxVI_TaskInfoState_Queued ||
|
|
|
|
taskInfo->state == esxVI_TaskInfoState_Running) {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_TaskInfo_AppendToList(pendingTaskInfoList,
|
2009-11-15 21:22:47 +00:00
|
|
|
taskInfo) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
taskInfo = NULL;
|
|
|
|
} else {
|
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
esxVI_TaskInfo_Free(pendingTaskInfoList);
|
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ManagedObjectReference_Free(&recentTaskList);
|
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupAndHandleVirtualMachineQuestion(esxVI_Context *ctx,
|
2009-11-15 21:22:47 +00:00
|
|
|
const unsigned char *uuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence occurrence,
|
|
|
|
esxVI_Boolean autoAnswer,
|
|
|
|
esxVI_Boolean *blocked)
|
2009-11-15 21:22:47 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
2009-11-15 21:22:47 +00:00
|
|
|
"runtime.question") < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_LookupVirtualMachineByUuid(ctx, uuid, propertyNameList,
|
2010-07-25 15:45:19 +00:00
|
|
|
&virtualMachine, occurrence) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-07-25 15:45:19 +00:00
|
|
|
if (virtualMachine != NULL) {
|
|
|
|
if (esxVI_GetVirtualMachineQuestionInfo(virtualMachine,
|
|
|
|
&questionInfo) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (questionInfo != NULL &&
|
|
|
|
esxVI_HandleVirtualMachineQuestion(ctx, virtualMachine->obj,
|
|
|
|
questionInfo, autoAnswer,
|
|
|
|
blocked) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_VirtualMachineQuestionInfo_Free(&questionInfo);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupRootSnapshotTreeList
|
|
|
|
(esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **rootSnapshotTreeList)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
|
|
|
if (rootSnapshotTreeList == NULL || *rootSnapshotTreeList != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"snapshot.rootSnapshotList") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
|
|
|
|
propertyNameList, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
|
|
|
|
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, rootSnapshotTreeList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList);
|
|
|
|
}
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupCurrentSnapshotTree
|
|
|
|
(esxVI_Context *ctx, const unsigned char *virtualMachineUuid,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **currentSnapshotTree,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *virtualMachine = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_ManagedObjectReference *currentSnapshot = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
|
|
|
|
|
|
|
if (currentSnapshotTree == NULL || *currentSnapshotTree != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueListToList(&propertyNameList,
|
|
|
|
"snapshot.currentSnapshot\0"
|
|
|
|
"snapshot.rootSnapshotList\0") < 0 ||
|
|
|
|
esxVI_LookupVirtualMachineByUuid(ctx, virtualMachineUuid,
|
|
|
|
propertyNameList, &virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
|
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "snapshot.currentSnapshot")) {
|
|
|
|
if (esxVI_ManagedObjectReference_CastFromAnyType
|
|
|
|
(dynamicProperty->val, ¤tSnapshot) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
} else if (STREQ(dynamicProperty->name, "snapshot.rootSnapshotList")) {
|
|
|
|
if (esxVI_VirtualMachineSnapshotTree_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, &rootSnapshotTreeList) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentSnapshot == NULL) {
|
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
2010-08-08 19:32:29 +00:00
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_DOMAIN_SNAPSHOT, "%s",
|
|
|
|
_("Domain has no current snapshot"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootSnapshotTreeList == NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not lookup root snapshot list"));
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_GetSnapshotTreeBySnapshot(rootSnapshotTreeList, currentSnapshot,
|
|
|
|
&snapshotTree) < 0 ||
|
|
|
|
esxVI_VirtualMachineSnapshotTree_DeepCopy(currentSnapshotTree,
|
|
|
|
snapshotTree) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachine);
|
|
|
|
esxVI_ManagedObjectReference_Free(¤tSnapshot);
|
|
|
|
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotTreeList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
|
|
|
|
const char *datastorePath,
|
2010-08-28 19:49:07 +00:00
|
|
|
bool lookupFolder,
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_FileInfo **fileInfo,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char *datastoreName = NULL;
|
|
|
|
char *directoryName = NULL;
|
2010-08-25 09:44:57 +00:00
|
|
|
char *directoryAndFileName = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
char *fileName = NULL;
|
2010-08-25 09:44:57 +00:00
|
|
|
size_t length;
|
2010-08-07 22:24:29 +00:00
|
|
|
char *datastorePathWithoutFileName = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *datastore = NULL;
|
|
|
|
esxVI_ManagedObjectReference *hostDatastoreBrowser = NULL;
|
|
|
|
esxVI_HostDatastoreBrowserSearchSpec *searchSpec = NULL;
|
2010-08-28 19:49:07 +00:00
|
|
|
esxVI_FolderFileQuery *folderFileQuery = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_VmDiskFileQuery *vmDiskFileQuery = NULL;
|
|
|
|
esxVI_IsoImageFileQuery *isoImageFileQuery = NULL;
|
|
|
|
esxVI_FloppyImageFileQuery *floppyImageFileQuery = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
|
|
|
|
|
|
|
if (fileInfo == NULL || *fileInfo != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxUtil_ParseDatastorePath(datastorePath, &datastoreName,
|
2010-08-25 09:44:57 +00:00
|
|
|
&directoryName, &directoryAndFileName) < 0) {
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:57 +00:00
|
|
|
if (STREQ(directoryName, directoryAndFileName)) {
|
|
|
|
/*
|
|
|
|
* The <path> part of the datatore path didn't contain a '/', assume
|
|
|
|
* that the <path> part is actually the file name.
|
|
|
|
*/
|
2010-08-07 22:24:29 +00:00
|
|
|
if (virAsprintf(&datastorePathWithoutFileName, "[%s]",
|
|
|
|
datastoreName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-25 09:44:57 +00:00
|
|
|
|
|
|
|
if (esxVI_String_DeepCopyValue(&fileName, directoryAndFileName) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 22:24:29 +00:00
|
|
|
} else {
|
|
|
|
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
|
|
|
|
datastoreName, directoryName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-25 09:44:57 +00:00
|
|
|
|
|
|
|
length = strlen(directoryName);
|
|
|
|
|
|
|
|
if (directoryAndFileName[length] != '/' ||
|
|
|
|
directoryAndFileName[length + 1] == '\0') {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Datastore path '%s' doesn't reference a file"),
|
|
|
|
datastorePath);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_DeepCopyValue(&fileName,
|
|
|
|
directoryAndFileName + length + 1) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup HostDatastoreBrowser */
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList, "browser") < 0 ||
|
|
|
|
esxVI_LookupDatastoreByName(ctx, datastoreName, propertyNameList,
|
|
|
|
&datastore,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetManagedObjectReference(datastore, "browser",
|
|
|
|
&hostDatastoreBrowser,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build HostDatastoreBrowserSearchSpec */
|
|
|
|
if (esxVI_HostDatastoreBrowserSearchSpec_Alloc(&searchSpec) < 0 ||
|
|
|
|
esxVI_FileQueryFlags_Alloc(&searchSpec->details) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
searchSpec->details->fileType = esxVI_Boolean_True;
|
|
|
|
searchSpec->details->fileSize = esxVI_Boolean_True;
|
|
|
|
searchSpec->details->modification = esxVI_Boolean_False;
|
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
if (lookupFolder) {
|
|
|
|
if (esxVI_FolderFileQuery_Alloc(&folderFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(folderFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (esxVI_VmDiskFileQuery_Alloc(&vmDiskFileQuery) < 0 ||
|
|
|
|
esxVI_VmDiskFileQueryFlags_Alloc(&vmDiskFileQuery->details) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(vmDiskFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
vmDiskFileQuery->details->diskType = esxVI_Boolean_False;
|
|
|
|
vmDiskFileQuery->details->capacityKb = esxVI_Boolean_True;
|
|
|
|
vmDiskFileQuery->details->hardwareVersion = esxVI_Boolean_False;
|
|
|
|
vmDiskFileQuery->details->controllerType = esxVI_Boolean_True;
|
|
|
|
vmDiskFileQuery->details->diskExtents = esxVI_Boolean_False;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
if (esxVI_IsoImageFileQuery_Alloc(&isoImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(isoImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
if (esxVI_FloppyImageFileQuery_Alloc(&floppyImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(floppyImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
searchSpec->matchPattern->value = fileName;
|
|
|
|
|
|
|
|
/* Search datastore for file */
|
|
|
|
if (esxVI_SearchDatastore_Task(ctx, hostDatastoreBrowser,
|
|
|
|
datastorePathWithoutFileName, searchSpec,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
|
|
|
|
esxVI_Boolean_False, &taskInfoState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not serach in datastore '%s'"), datastoreName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo) < 0 ||
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_CastFromAnyType
|
|
|
|
(taskInfo->result, &searchResults) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interpret search result */
|
|
|
|
if (searchResults->file == NULL) {
|
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("No storage volume with key or path '%s'"),
|
|
|
|
datastorePath);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*fileInfo = searchResults->file;
|
|
|
|
searchResults->file = NULL;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
/* Don't double free fileName */
|
|
|
|
if (searchSpec != NULL && searchSpec->matchPattern != NULL) {
|
|
|
|
searchSpec->matchPattern->value = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(datastoreName);
|
|
|
|
VIR_FREE(directoryName);
|
2010-08-25 09:44:57 +00:00
|
|
|
VIR_FREE(directoryAndFileName);
|
2010-08-07 22:24:29 +00:00
|
|
|
VIR_FREE(fileName);
|
|
|
|
VIR_FREE(datastorePathWithoutFileName);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastore);
|
|
|
|
esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
|
|
|
|
esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResults);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupDatastoreContentByDatastoreName
|
|
|
|
(esxVI_Context *ctx, const char *datastoreName,
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults **searchResultsList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *datastore = NULL;
|
|
|
|
esxVI_ManagedObjectReference *hostDatastoreBrowser = NULL;
|
|
|
|
esxVI_HostDatastoreBrowserSearchSpec *searchSpec = NULL;
|
|
|
|
esxVI_VmDiskFileQuery *vmDiskFileQuery = NULL;
|
|
|
|
esxVI_IsoImageFileQuery *isoImageFileQuery = NULL;
|
|
|
|
esxVI_FloppyImageFileQuery *floppyImageFileQuery = NULL;
|
|
|
|
char *datastorePath = NULL;
|
|
|
|
esxVI_ManagedObjectReference *task = NULL;
|
|
|
|
esxVI_TaskInfoState taskInfoState;
|
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
|
|
|
|
|
|
|
if (searchResultsList == NULL || *searchResultsList != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup Datastore and HostDatastoreBrowser */
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList, "browser") < 0 ||
|
|
|
|
esxVI_LookupDatastoreByName(ctx, datastoreName, propertyNameList,
|
|
|
|
&datastore,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_GetManagedObjectReference(datastore, "browser",
|
|
|
|
&hostDatastoreBrowser,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build HostDatastoreBrowserSearchSpec */
|
|
|
|
if (esxVI_HostDatastoreBrowserSearchSpec_Alloc(&searchSpec) < 0 ||
|
|
|
|
esxVI_FileQueryFlags_Alloc(&searchSpec->details) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
searchSpec->details->fileType = esxVI_Boolean_True;
|
|
|
|
searchSpec->details->fileSize = esxVI_Boolean_True;
|
|
|
|
searchSpec->details->modification = esxVI_Boolean_False;
|
|
|
|
|
|
|
|
if (esxVI_VmDiskFileQuery_Alloc(&vmDiskFileQuery) < 0 ||
|
|
|
|
esxVI_VmDiskFileQueryFlags_Alloc(&vmDiskFileQuery->details) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(vmDiskFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmDiskFileQuery->details->diskType = esxVI_Boolean_False;
|
|
|
|
vmDiskFileQuery->details->capacityKb = esxVI_Boolean_True;
|
|
|
|
vmDiskFileQuery->details->hardwareVersion = esxVI_Boolean_False;
|
|
|
|
vmDiskFileQuery->details->controllerType = esxVI_Boolean_True;
|
|
|
|
vmDiskFileQuery->details->diskExtents = esxVI_Boolean_False;
|
|
|
|
|
|
|
|
if (esxVI_IsoImageFileQuery_Alloc(&isoImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(isoImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_FloppyImageFileQuery_Alloc(&floppyImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(floppyImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search datastore for files */
|
|
|
|
if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_SearchDatastoreSubFolders_Task(ctx, hostDatastoreBrowser,
|
|
|
|
datastorePath, searchSpec,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
|
|
|
|
esxVI_Boolean_False, &taskInfoState) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not serach in datastore '%s'"), datastoreName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo) < 0 ||
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_CastListFromAnyType
|
|
|
|
(taskInfo->result, searchResultsList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastore);
|
|
|
|
esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
|
|
|
|
esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
|
|
|
|
VIR_FREE(datastorePath);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:33:49 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
|
|
|
|
const char *datastorePath,
|
|
|
|
char **key)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_FileInfo *fileInfo = NULL;
|
|
|
|
char *uuid_string = NULL;
|
|
|
|
|
|
|
|
if (key == NULL || *key != NULL) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-03 23:30:04 +00:00
|
|
|
if (ctx->hasQueryVirtualDiskUuid) {
|
|
|
|
if (esxVI_LookupFileInfoByDatastorePath
|
|
|
|
(ctx, datastorePath, false, &fileInfo,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-08-29 17:33:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-09-03 23:30:04 +00:00
|
|
|
if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo) != NULL) {
|
|
|
|
/* VirtualDisks have a UUID, use it as key */
|
|
|
|
if (esxVI_QueryVirtualDiskUuid(ctx, datastorePath,
|
|
|
|
ctx->datacenter->_reference,
|
|
|
|
&uuid_string) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-29 17:33:49 +00:00
|
|
|
|
2010-09-03 23:30:04 +00:00
|
|
|
if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxUtil_ReformatUuid(uuid_string, *key) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-29 17:33:49 +00:00
|
|
|
}
|
2010-09-03 23:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*key == NULL) {
|
2010-08-29 17:33:49 +00:00
|
|
|
/* Other files don't have a UUID, fall back to the path as key */
|
|
|
|
if (esxVI_String_DeepCopyValue(key, datastorePath) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
esxVI_FileInfo_Free(&fileInfo);
|
|
|
|
VIR_FREE(uuid_string);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int
|
|
|
|
esxVI_HandleVirtualMachineQuestion
|
2010-01-15 22:05:26 +00:00
|
|
|
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Boolean autoAnswer, esxVI_Boolean *blocked)
|
2009-11-15 21:22:47 +00:00
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_ElementDescription *elementDescription = NULL;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
esxVI_ElementDescription *answerChoice = NULL;
|
|
|
|
int answerIndex = 0;
|
|
|
|
char *possibleAnswers = NULL;
|
|
|
|
|
2010-07-25 15:45:19 +00:00
|
|
|
if (blocked == NULL || *blocked != esxVI_Boolean_Undefined) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*blocked = esxVI_Boolean_False;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (questionInfo->choice->choiceInfo != NULL) {
|
|
|
|
for (elementDescription = questionInfo->choice->choiceInfo;
|
|
|
|
elementDescription != NULL;
|
|
|
|
elementDescription = elementDescription->_next) {
|
|
|
|
virBufferVSprintf(&buffer, "'%s'", elementDescription->label);
|
|
|
|
|
|
|
|
if (elementDescription->_next != NULL) {
|
|
|
|
virBufferAddLit(&buffer, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answerChoice == NULL &&
|
|
|
|
questionInfo->choice->defaultIndex != NULL &&
|
|
|
|
questionInfo->choice->defaultIndex->value == answerIndex) {
|
|
|
|
answerChoice = elementDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
++answerIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
possibleAnswers = virBufferContentAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autoAnswer == esxVI_Boolean_True) {
|
|
|
|
if (possibleAnswers == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', no possible answers"),
|
2009-11-15 21:22:47 +00:00
|
|
|
questionInfo->text);
|
2010-07-25 15:45:19 +00:00
|
|
|
|
|
|
|
*blocked = esxVI_Boolean_True;
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
} else if (answerChoice == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', possible answers are %s, but no "
|
|
|
|
"default answer is specified"), questionInfo->text,
|
2009-11-15 21:22:47 +00:00
|
|
|
possibleAnswers);
|
2010-07-25 15:45:19 +00:00
|
|
|
|
|
|
|
*blocked = esxVI_Boolean_True;
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_INFO("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', possible answers are %s, responding "
|
|
|
|
"with default answer '%s'", questionInfo->text,
|
|
|
|
possibleAnswers, answerChoice->label);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_AnswerVM(ctx, virtualMachine, questionInfo->id,
|
2009-11-15 21:22:47 +00:00
|
|
|
answerChoice->key) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (possibleAnswers != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', possible answers are %s"),
|
2009-11-15 21:22:47 +00:00
|
|
|
questionInfo->text, possibleAnswers);
|
|
|
|
} else {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
2010-04-02 19:34:31 +00:00
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', no possible answers"),
|
2009-11-15 21:22:47 +00:00
|
|
|
questionInfo->text);
|
|
|
|
}
|
|
|
|
|
2010-07-25 15:45:19 +00:00
|
|
|
*blocked = esxVI_Boolean_True;
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
cleanup:
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) {
|
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
VIR_FREE(possibleAnswers);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *task,
|
2009-11-15 21:22:47 +00:00
|
|
|
const unsigned char *virtualMachineUuid,
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Occurrence virtualMachineOccurrence,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_Boolean autoAnswer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_TaskInfoState *finalState)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ObjectSpec *objectSpec = NULL;
|
|
|
|
esxVI_PropertySpec *propertySpec = NULL;
|
|
|
|
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
|
|
|
|
esxVI_ManagedObjectReference *propertyFilter = NULL;
|
|
|
|
char *version = NULL;
|
|
|
|
esxVI_UpdateSet *updateSet = NULL;
|
|
|
|
esxVI_PropertyFilterUpdate *propertyFilterUpdate = NULL;
|
|
|
|
esxVI_ObjectUpdate *objectUpdate = NULL;
|
|
|
|
esxVI_PropertyChange *propertyChange = NULL;
|
|
|
|
esxVI_AnyType *propertyValue = NULL;
|
|
|
|
esxVI_TaskInfoState state = esxVI_TaskInfoState_Undefined;
|
2010-07-25 15:45:19 +00:00
|
|
|
esxVI_Boolean blocked = esxVI_Boolean_Undefined;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
version = strdup("");
|
|
|
|
|
|
|
|
if (version == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
objectSpec->obj = task;
|
|
|
|
objectSpec->skip = esxVI_Boolean_False;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
propertySpec->type = task->type;
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_String_AppendValueToList(&propertySpec->pathSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
"info.state") < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PropertyFilterSpec_Alloc(&propertyFilterSpec) < 0 ||
|
|
|
|
esxVI_PropertySpec_AppendToList(&propertyFilterSpec->propSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
propertySpec) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
|
2009-07-23 20:21:08 +00:00
|
|
|
objectSpec) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_CreateFilter(ctx, propertyFilterSpec, esxVI_Boolean_True,
|
2009-07-23 20:21:08 +00:00
|
|
|
&propertyFilter) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (state != esxVI_TaskInfoState_Success &&
|
|
|
|
state != esxVI_TaskInfoState_Error) {
|
|
|
|
esxVI_UpdateSet_Free(&updateSet);
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
if (virtualMachineUuid != NULL) {
|
|
|
|
if (esxVI_LookupAndHandleVirtualMachineQuestion
|
2010-07-25 15:45:19 +00:00
|
|
|
(ctx, virtualMachineUuid, virtualMachineOccurrence,
|
|
|
|
autoAnswer, &blocked) < 0) {
|
2009-11-15 21:22:47 +00:00
|
|
|
/*
|
|
|
|
* FIXME: Disable error reporting here, so possible errors from
|
|
|
|
* esxVI_LookupTaskInfoByTask() and esxVI_CancelTask()
|
|
|
|
* don't overwrite the actual error
|
|
|
|
*/
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfo->cancelable == esxVI_Boolean_True) {
|
2010-07-25 15:45:19 +00:00
|
|
|
if (esxVI_CancelTask(ctx, task) < 0 &&
|
|
|
|
blocked == esxVI_Boolean_True) {
|
2010-05-20 06:28:53 +00:00
|
|
|
VIR_ERROR0(_("Cancelable task is blocked by an "
|
|
|
|
"unanswered question but cancelation "
|
|
|
|
"failed"));
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
2010-07-25 15:45:19 +00:00
|
|
|
} else if (blocked == esxVI_Boolean_True) {
|
2010-05-20 06:28:53 +00:00
|
|
|
VIR_ERROR0(_("Non-cancelable task is blocked by an "
|
|
|
|
"unanswered question"));
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Enable error reporting here again */
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(version);
|
|
|
|
version = strdup(updateSet->version);
|
|
|
|
|
|
|
|
if (version == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updateSet->filterSet == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (propertyFilterUpdate = updateSet->filterSet;
|
|
|
|
propertyFilterUpdate != NULL;
|
|
|
|
propertyFilterUpdate = propertyFilterUpdate->_next) {
|
|
|
|
for (objectUpdate = propertyFilterUpdate->objectSet;
|
|
|
|
objectUpdate != NULL; objectUpdate = objectUpdate->_next) {
|
|
|
|
for (propertyChange = objectUpdate->changeSet;
|
|
|
|
propertyChange != NULL;
|
|
|
|
propertyChange = propertyChange->_next) {
|
|
|
|
if (STREQ(propertyChange->name, "info.state")) {
|
|
|
|
if (propertyChange->op == esxVI_PropertyChangeOp_Add ||
|
|
|
|
propertyChange->op == esxVI_PropertyChangeOp_Assign) {
|
|
|
|
propertyValue = propertyChange->val;
|
|
|
|
} else {
|
|
|
|
propertyValue = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertyValue == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) {
|
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_DestroyPropertyFilter(ctx, propertyFilter) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_DEBUG0("DestroyPropertyFilter failed");
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
|
|
|
/*
|
|
|
|
* Remove values given by the caller from the data structures to prevent
|
|
|
|
* them from being freed by the call to esxVI_PropertyFilterSpec_Free().
|
|
|
|
*/
|
|
|
|
if (objectSpec != NULL) {
|
|
|
|
objectSpec->obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertySpec != NULL) {
|
|
|
|
propertySpec->type = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esxVI_PropertyFilterSpec_Free(&propertyFilterSpec);
|
|
|
|
esxVI_ManagedObjectReference_Free(&propertyFilter);
|
|
|
|
VIR_FREE(version);
|
|
|
|
esxVI_UpdateSet_Free(&updateSet);
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2010-04-13 22:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_ParseHostCpuIdInfo(esxVI_ParsedHostCpuIdInfo *parsedHostCpuIdInfo,
|
|
|
|
esxVI_HostCpuIdInfo *hostCpuIdInfo)
|
|
|
|
{
|
|
|
|
int expectedLength = 39; /* = strlen("----:----:----:----:----:----:----:----"); */
|
|
|
|
char *input[4] = { hostCpuIdInfo->eax, hostCpuIdInfo->ebx,
|
|
|
|
hostCpuIdInfo->ecx, hostCpuIdInfo->edx };
|
|
|
|
char *output[4] = { parsedHostCpuIdInfo->eax, parsedHostCpuIdInfo->ebx,
|
|
|
|
parsedHostCpuIdInfo->ecx, parsedHostCpuIdInfo->edx };
|
|
|
|
const char *name[4] = { "eax", "ebx", "ecx", "edx" };
|
|
|
|
int r, i, o;
|
|
|
|
|
|
|
|
memset(parsedHostCpuIdInfo, 0, sizeof (*parsedHostCpuIdInfo));
|
|
|
|
|
|
|
|
parsedHostCpuIdInfo->level = hostCpuIdInfo->level->value;
|
|
|
|
|
|
|
|
for (r = 0; r < 4; ++r) {
|
|
|
|
if (strlen(input[r]) != expectedLength) {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HostCpuIdInfo register '%s' has an unexpected length"),
|
|
|
|
name[r]);
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-13 22:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip the ':' and invert the "bit" order from 31..0 to 0..31 */
|
|
|
|
for (i = 0, o = 31; i < expectedLength; i += 5, o -= 4) {
|
|
|
|
output[r][o] = input[r][i];
|
|
|
|
output[r][o - 1] = input[r][i + 1];
|
|
|
|
output[r][o - 2] = input[r][i + 2];
|
|
|
|
output[r][o - 3] = input[r][i + 3];
|
|
|
|
|
|
|
|
if (i + 4 < expectedLength && input[r][i + 4] != ':') {
|
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HostCpuIdInfo register '%s' has an unexpected format"),
|
|
|
|
name[r]);
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2010-04-13 22:03:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|