2009-07-23 20:21:08 +00:00
|
|
|
/*
|
|
|
|
* esx_vi.c: client for the VMware VI API 2.5 to manage ESX hosts
|
|
|
|
*
|
2012-11-06 09:08:43 +00:00
|
|
|
* Copyright (C) 2010-2012 Red Hat, Inc.
|
2014-03-30 18:37:00 +00:00
|
|
|
* Copyright (C) 2009-2012, 2014 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2014-03-30 18:37:00 +00:00
|
|
|
#include <poll.h>
|
2009-07-23 20:21:08 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/xpathInternals.h>
|
|
|
|
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "vmx.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
#include "esx_vi.h"
|
|
|
|
#include "esx_vi_methods.h"
|
|
|
|
#include "esx_util.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("esx.esx_vi");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
#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
|
|
|
{ \
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ptrptr || *ptrptr) { \
|
2013-09-03 15:22:48 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (VIR_ALLOC(*ptrptr) < 0) \
|
|
|
|
return -1; \
|
|
|
|
return 0; \
|
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) \
|
|
|
|
{ \
|
2011-04-14 17:18:27 +00:00
|
|
|
esxVI_##_type *item ATTRIBUTE_UNUSED; \
|
2009-07-23 20:21:08 +00:00
|
|
|
\
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ptrptr || !(*ptrptr)) { \
|
2009-07-23 20:21:08 +00:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
item = *ptrptr; \
|
|
|
|
\
|
|
|
|
_body \
|
|
|
|
\
|
|
|
|
VIR_FREE(*ptrptr); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2011-02-19 13:34:25 +00:00
|
|
|
* CURL
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
/* esxVI_CURL_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(CURL)
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
/* esxVI_CURL_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(CURL,
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2011-02-19 14:27:16 +00:00
|
|
|
esxVI_SharedCURL *shared = item->shared;
|
2012-07-02 20:52:48 +00:00
|
|
|
esxVI_MultiCURL *multi = item->multi;
|
2011-02-19 14:27:16 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (shared) {
|
2011-02-19 14:27:16 +00:00
|
|
|
esxVI_SharedCURL_Remove(shared, item);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (shared->count == 0)
|
2011-02-19 14:27:16 +00:00
|
|
|
esxVI_SharedCURL_Free(&shared);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (multi) {
|
2012-07-02 20:52:48 +00:00
|
|
|
esxVI_MultiCURL_Remove(multi, item);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (multi->count == 0)
|
2012-07-02 20:52:48 +00:00
|
|
|
esxVI_MultiCURL_Free(&multi);
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (item->handle)
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_cleanup(item->handle);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (item->headers)
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_slist_free_all(item->headers);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
virMutexDestroy(&item->lock);
|
|
|
|
})
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
static size_t
|
2012-07-12 23:58:27 +00:00
|
|
|
esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata)
|
2009-09-23 12:52:36 +00:00
|
|
|
{
|
2012-07-12 23:58:27 +00:00
|
|
|
const char *content = *(const char **)userdata;
|
2009-09-23 12:52:36 +00:00
|
|
|
size_t available = 0;
|
|
|
|
size_t requested = size * nmemb;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!content)
|
2009-09-23 12:52:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
available = strlen(content);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (available == 0)
|
2009-09-23 12:52:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (requested > available)
|
2009-09-23 12:52:36 +00:00
|
|
|
requested = available;
|
|
|
|
|
|
|
|
memcpy(data, content, requested);
|
|
|
|
|
2012-07-12 23:58:27 +00:00
|
|
|
*(const char **)userdata = content + requested;
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
return requested;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2012-07-12 23:58:27 +00:00
|
|
|
esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2012-07-12 23:58:27 +00:00
|
|
|
virBufferPtr buffer = userdata;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (buffer) {
|
2012-07-12 23:58:27 +00:00
|
|
|
/*
|
|
|
|
* Using a virBuffer to store the download data limits the downloadable
|
|
|
|
* size. This is no problem as esxVI_CURL_Download and esxVI_CURL_Perform
|
|
|
|
* are meant to download small things such as VMX files, VMDK metadata
|
|
|
|
* files and SOAP responses.
|
|
|
|
*/
|
2014-11-13 14:22:20 +00:00
|
|
|
if (size * nmemb > INT32_MAX / 2 - virBufferUse(buffer))
|
2012-07-12 23:58:27 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
virBufferAdd(buffer, data, size * nmemb);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
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,
|
2012-07-12 23:58:27 +00:00
|
|
|
char *info, size_t size, void *userdata 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.
|
|
|
|
*/
|
2014-11-13 14:22:20 +00:00
|
|
|
if (VIR_ALLOC_N(buffer, size + 1) < 0)
|
2010-01-02 13:18:44 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virStrncpy(buffer, info, size, size + 1)) {
|
2010-01-02 13:18:44 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case CURLINFO_TEXT:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (size > 0 && buffer[size - 1] == '\n')
|
2010-01-02 13:18:44 +00:00
|
|
|
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:
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("unknown");
|
2009-07-23 20:21:08 +00:00
|
|
|
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
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_CURL_Perform(esxVI_CURL *curl, 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
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
errorCode = curl_easy_perform(curl->handle);
|
2009-10-21 18:25:22 +00:00
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("curl_easy_perform() returned an error: %s (%d) : %s"),
|
|
|
|
curl_easy_strerror(errorCode), errorCode, curl->error);
|
2009-10-21 18:25:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
errorCode = curl_easy_getinfo(curl->handle, CURLINFO_RESPONSE_CODE,
|
2009-10-21 18:25:22 +00:00
|
|
|
&responseCode);
|
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned an "
|
|
|
|
"error: %s (%d) : %s"), curl_easy_strerror(errorCode),
|
|
|
|
errorCode, curl->error);
|
2009-10-21 18:25:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseCode < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 */
|
2011-02-19 13:34:25 +00:00
|
|
|
errorCode = curl_easy_getinfo(curl->handle, CURLINFO_REDIRECT_URL,
|
2009-10-21 18:25:22 +00:00
|
|
|
&redirectUrl);
|
|
|
|
|
|
|
|
if (errorCode != CURLE_OK) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("curl_easy_getinfo(CURLINFO_REDIRECT_URL) returned "
|
|
|
|
"an error: %s (%d) : %s"),
|
|
|
|
curl_easy_strerror(errorCode),
|
|
|
|
errorCode, curl->error);
|
2009-10-21 18:25:22 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("The server redirects from '%s' to '%s'"), url,
|
|
|
|
redirectUrl);
|
2009-10-21 18:25:22 +00:00
|
|
|
}
|
|
|
|
#else
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
2013-10-17 17:04:11 +00:00
|
|
|
if (curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call"));
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
curl->handle = curl_easy_init();
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
curl->headers = curl_slist_append(curl->headers,
|
|
|
|
"Content-Type: text/xml; charset=UTF-8");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
/*
|
2012-02-20 21:34:52 +00:00
|
|
|
* Add an empty expect header to stop CURL from waiting for a response code
|
2009-07-23 20:21:08 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2012-02-20 21:34:52 +00:00
|
|
|
curl->headers = curl_slist_append(curl->headers, "Expect:");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->headers) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_USERAGENT, "libvirt-esx");
|
2012-09-29 20:16:30 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_NOSIGNAL, 1);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_HEADER, 0);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_FOLLOWLOCATION, 0);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYPEER,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->noVerify ? 0 : 1);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYHOST,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->noVerify ? 0 : 2);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_COOKIEFILE, "");
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->headers);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_READFUNCTION,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_CURL_ReadString);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_WRITEFUNCTION,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_CURL_WriteBuffer);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_ERRORBUFFER, curl->error);
|
2009-07-23 20:21:08 +00:00
|
|
|
#if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_DEBUGFUNCTION, esxVI_CURL_Debug);
|
|
|
|
curl_easy_setopt(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) {
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_PROXY,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_hostname);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_PROXYTYPE,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_type);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_PROXYPORT,
|
2010-07-30 20:08:35 +00:00
|
|
|
parsedUri->proxy_port);
|
2010-06-03 21:09:12 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
if (virMutexInit(&curl->lock) < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
int
|
2012-07-12 23:58:27 +00:00
|
|
|
esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
|
|
|
|
unsigned long long offset, unsigned long long *length)
|
2011-02-19 13:34:25 +00:00
|
|
|
{
|
2012-07-12 23:58:27 +00:00
|
|
|
char *range = NULL;
|
2011-02-19 13:34:25 +00:00
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
int responseCode = 0;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!content || *content) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2011-02-19 13:34:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (length && *length > 0) {
|
2012-07-12 23:58:27 +00:00
|
|
|
/*
|
|
|
|
* Using a virBuffer to store the download data limits the downloadable
|
|
|
|
* size. This is no problem as esxVI_CURL_Download is meant to download
|
|
|
|
* small things such as VMX of VMDK metadata files.
|
|
|
|
*/
|
|
|
|
if (*length > INT32_MAX / 2) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Download length it too large"));
|
2012-07-12 23:58:27 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:05:43 +00:00
|
|
|
if (virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1) < 0)
|
2012-07-12 23:58:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else if (offset > 0) {
|
2013-07-04 10:05:43 +00:00
|
|
|
if (virAsprintf(&range, "%llu-", offset) < 0)
|
2012-07-12 23:58:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_URL, url);
|
2012-07-12 23:58:27 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_RANGE, range);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1);
|
|
|
|
|
|
|
|
responseCode = esxVI_CURL_Perform(curl, url);
|
|
|
|
|
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
|
|
|
if (responseCode < 0) {
|
|
|
|
goto cleanup;
|
2012-07-12 23:58:27 +00:00
|
|
|
} else if (responseCode != 200 && responseCode != 206) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for download from '%s'"),
|
|
|
|
responseCode, url);
|
2011-02-19 13:34:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2011-02-19 13:34:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (length)
|
2012-07-12 23:58:27 +00:00
|
|
|
*length = virBufferUse(&buffer);
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
*content = virBufferContentAndReset(&buffer);
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-07-12 23:58:27 +00:00
|
|
|
VIR_FREE(range);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*content)) {
|
2011-02-19 13:34:25 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_CURL_Upload(esxVI_CURL *curl, const char *url, const char *content)
|
|
|
|
{
|
|
|
|
int responseCode = 0;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!content) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2011-02-19 13:34:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_URL, url);
|
2012-07-12 23:58:27 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_RANGE, NULL);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_READDATA, &content);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1);
|
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, strlen(content));
|
|
|
|
|
|
|
|
responseCode = esxVI_CURL_Perform(curl, url);
|
|
|
|
|
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
|
|
|
if (responseCode < 0) {
|
|
|
|
return -1;
|
|
|
|
} else if (responseCode != 200 && responseCode != 201) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for upload to '%s'"),
|
|
|
|
responseCode, url);
|
2011-02-19 13:34:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* SharedCURL
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
esxVI_SharedCURL_Lock(CURL *handle ATTRIBUTE_UNUSED, curl_lock_data data,
|
|
|
|
curl_lock_access access_ ATTRIBUTE_UNUSED, void *userptr)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-02-19 14:27:16 +00:00
|
|
|
esxVI_SharedCURL *shared = userptr;
|
|
|
|
|
|
|
|
switch (data) {
|
|
|
|
case CURL_LOCK_DATA_SHARE:
|
|
|
|
i = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_LOCK_DATA_COOKIE:
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_LOCK_DATA_DNS:
|
|
|
|
i = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VIR_ERROR(_("Trying to lock unknown SharedCURL lock %d"), (int)data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&shared->locks[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
esxVI_SharedCURL_Unlock(CURL *handle ATTRIBUTE_UNUSED, curl_lock_data data,
|
|
|
|
void *userptr)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-02-19 14:27:16 +00:00
|
|
|
esxVI_SharedCURL *shared = userptr;
|
|
|
|
|
|
|
|
switch (data) {
|
|
|
|
case CURL_LOCK_DATA_SHARE:
|
|
|
|
i = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_LOCK_DATA_COOKIE:
|
|
|
|
i = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CURL_LOCK_DATA_DNS:
|
|
|
|
i = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VIR_ERROR(_("Trying to unlock unknown SharedCURL lock %d"), (int)data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexUnlock(&shared->locks[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* esxVI_SharedCURL_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(SharedCURL)
|
|
|
|
|
|
|
|
/* esxVI_SharedCURL_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(SharedCURL,
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-02-19 14:27:16 +00:00
|
|
|
|
|
|
|
if (item->count > 0) {
|
|
|
|
/* Better leak than crash */
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("Trying to free SharedCURL object that is still in use"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (item->handle)
|
2011-02-19 14:27:16 +00:00
|
|
|
curl_share_cleanup(item->handle);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i)
|
2011-02-19 14:27:16 +00:00
|
|
|
virMutexDestroy(&item->locks[i]);
|
|
|
|
})
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-02-19 14:27:16 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot share uninitialized CURL handle"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (curl->shared) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot share CURL handle that is already shared"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!shared->handle) {
|
2011-02-19 14:27:16 +00:00
|
|
|
shared->handle = curl_share_init();
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!shared->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize CURL (share)"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_share_setopt(shared->handle, CURLSHOPT_LOCKFUNC,
|
|
|
|
esxVI_SharedCURL_Lock);
|
|
|
|
curl_share_setopt(shared->handle, CURLSHOPT_UNLOCKFUNC,
|
|
|
|
esxVI_SharedCURL_Unlock);
|
|
|
|
curl_share_setopt(shared->handle, CURLSHOPT_USERDATA, shared);
|
|
|
|
curl_share_setopt(shared->handle, CURLSHOPT_SHARE,
|
|
|
|
CURL_LOCK_DATA_COOKIE);
|
|
|
|
curl_share_setopt(shared->handle, CURLSHOPT_SHARE,
|
|
|
|
CURL_LOCK_DATA_DNS);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(shared->locks); ++i) {
|
|
|
|
if (virMutexInit(&shared->locks[i]) < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize a CURL (share) mutex"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 20:52:48 +00:00
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_SHARE, shared->handle);
|
|
|
|
|
|
|
|
curl->shared = shared;
|
|
|
|
++shared->count;
|
|
|
|
|
2012-07-02 20:52:48 +00:00
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl)
|
|
|
|
{
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot unshare uninitialized CURL handle"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->shared) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot unshare CURL handle that is not shared"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curl->shared != shared) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("CURL (share) mismatch"));
|
2011-02-19 14:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-02 20:52:48 +00:00
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
curl_easy_setopt(curl->handle, CURLOPT_SHARE, NULL);
|
|
|
|
|
|
|
|
curl->shared = NULL;
|
|
|
|
--shared->count;
|
|
|
|
|
2012-07-02 20:52:48 +00:00
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* MultiCURL
|
|
|
|
*/
|
|
|
|
|
2014-03-30 18:37:00 +00:00
|
|
|
#if ESX_EMULATE_CURL_MULTI_WAIT
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxVI_MultiCURL_SocketCallback(CURL *handle ATTRIBUTE_UNUSED,
|
|
|
|
curl_socket_t fd, int action,
|
|
|
|
void *callback_opaque,
|
|
|
|
void *socket_opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
esxVI_MultiCURL *multi = callback_opaque;
|
|
|
|
size_t i;
|
|
|
|
struct pollfd *pollfd = NULL;
|
|
|
|
struct pollfd dummy;
|
|
|
|
|
|
|
|
if (action & CURL_POLL_REMOVE) {
|
|
|
|
for (i = 0; i < multi->npollfds; ++i) {
|
|
|
|
if (multi->pollfds[i].fd == fd) {
|
|
|
|
VIR_DELETE_ELEMENT(multi->pollfds, i, multi->npollfds);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < multi->npollfds; ++i) {
|
|
|
|
if (multi->pollfds[i].fd == fd) {
|
|
|
|
pollfd = &multi->pollfds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pollfd == NULL) {
|
|
|
|
if (VIR_APPEND_ELEMENT(multi->pollfds, multi->npollfds, dummy) < 0)
|
|
|
|
return 0; /* curl_multi_socket() doc says "The callback MUST return 0." */
|
|
|
|
|
|
|
|
pollfd = &multi->pollfds[multi->npollfds - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
pollfd->fd = fd;
|
|
|
|
pollfd->events = 0;
|
|
|
|
|
|
|
|
if (action & CURL_POLL_IN)
|
|
|
|
pollfd->events |= POLLIN;
|
|
|
|
|
|
|
|
if (action & CURL_POLL_OUT)
|
|
|
|
pollfd->events |= POLLOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxVI_MultiCURL_TimerCallback(CURLM *handle ATTRIBUTE_UNUSED,
|
2014-10-08 07:13:40 +00:00
|
|
|
long timeout_ms ATTRIBUTE_UNUSED,
|
|
|
|
void *callback_opaque)
|
2014-03-30 18:37:00 +00:00
|
|
|
{
|
|
|
|
esxVI_MultiCURL *multi = callback_opaque;
|
|
|
|
|
|
|
|
multi->timeoutPending = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-07-02 20:52:48 +00:00
|
|
|
/* esxVI_MultiCURL_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(MultiCURL)
|
|
|
|
|
|
|
|
/* esxVI_MultiCURL_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(MultiCURL,
|
|
|
|
{
|
|
|
|
if (item->count > 0) {
|
|
|
|
/* Better leak than crash */
|
|
|
|
VIR_ERROR(_("Trying to free MultiCURL object that is still in use"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (item->handle)
|
2012-07-02 20:52:48 +00:00
|
|
|
curl_multi_cleanup(item->handle);
|
2014-03-30 18:37:00 +00:00
|
|
|
|
|
|
|
#if ESX_EMULATE_CURL_MULTI_WAIT
|
|
|
|
VIR_FREE(item->pollfds);
|
|
|
|
#endif
|
2012-07-02 20:52:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_Add(esxVI_MultiCURL *multi, esxVI_CURL *curl)
|
|
|
|
{
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot add uninitialized CURL handle to a multi handle"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (curl->multi) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot add CURL handle to a multi handle twice"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!multi->handle) {
|
2012-07-02 20:52:48 +00:00
|
|
|
multi->handle = curl_multi_init();
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!multi->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize CURL (multi)"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-30 18:37:00 +00:00
|
|
|
|
|
|
|
#if ESX_EMULATE_CURL_MULTI_WAIT
|
|
|
|
curl_multi_setopt(multi->handle, CURLMOPT_SOCKETFUNCTION,
|
|
|
|
esxVI_MultiCURL_SocketCallback);
|
|
|
|
curl_multi_setopt(multi->handle, CURLMOPT_SOCKETDATA, multi);
|
|
|
|
curl_multi_setopt(multi->handle, CURLMOPT_TIMERFUNCTION,
|
|
|
|
esxVI_MultiCURL_TimerCallback);
|
|
|
|
curl_multi_setopt(multi->handle, CURLMOPT_TIMERDATA, multi);
|
|
|
|
#endif
|
2012-07-02 20:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
|
|
|
curl_multi_add_handle(multi->handle, curl->handle);
|
|
|
|
|
|
|
|
curl->multi = multi;
|
|
|
|
++multi->count;
|
|
|
|
|
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_Remove(esxVI_MultiCURL *multi, esxVI_CURL *curl)
|
|
|
|
{
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->handle) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot remove uninitialized CURL handle from a "
|
|
|
|
"multi handle"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!curl->multi) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot remove CURL handle from a multi handle when it "
|
|
|
|
"wasn't added before"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curl->multi != multi) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("CURL (multi) mismatch"));
|
2012-07-02 20:52:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virMutexLock(&curl->lock);
|
|
|
|
|
|
|
|
curl_multi_remove_handle(multi->handle, curl->handle);
|
|
|
|
|
|
|
|
curl->multi = NULL;
|
|
|
|
--multi->count;
|
|
|
|
|
|
|
|
virMutexUnlock(&curl->lock);
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-30 18:37:00 +00:00
|
|
|
#if ESX_EMULATE_CURL_MULTI_WAIT
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_Wait(esxVI_MultiCURL *multi, int *runningHandles)
|
|
|
|
{
|
|
|
|
long timeout = -1;
|
|
|
|
CURLMcode errorCode;
|
|
|
|
int rc;
|
|
|
|
size_t i;
|
|
|
|
int action;
|
|
|
|
|
|
|
|
if (multi->timeoutPending) {
|
|
|
|
do {
|
|
|
|
errorCode = curl_multi_socket_action(multi->handle, CURL_SOCKET_TIMEOUT,
|
|
|
|
0, runningHandles);
|
|
|
|
} while (errorCode == CURLM_CALL_MULTI_SOCKET);
|
|
|
|
|
|
|
|
if (errorCode != CURLM_OK) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not trigger socket action: %s (%d)"),
|
|
|
|
curl_multi_strerror(errorCode), errorCode);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
multi->timeoutPending = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multi->npollfds == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
curl_multi_timeout(multi->handle, &timeout);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (timeout < 0)
|
2014-03-30 18:37:00 +00:00
|
|
|
timeout = 1000; /* default to 1 sec timeout */
|
|
|
|
|
|
|
|
do {
|
|
|
|
rc = poll(multi->pollfds, multi->npollfds, timeout);
|
|
|
|
} while (rc < 0 && (errno == EAGAIN || errno == EINTR));
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
virReportSystemError(errno, "%s", _("Could not wait for transfer"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < multi->npollfds && rc > 0; ++i) {
|
|
|
|
if (multi->pollfds[i].revents == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
--rc;
|
|
|
|
action = 0;
|
|
|
|
|
|
|
|
if (multi->pollfds[i].revents & POLLIN)
|
|
|
|
action |= CURL_POLL_IN;
|
|
|
|
|
|
|
|
if (multi->pollfds[i].revents & POLLOUT)
|
|
|
|
action |= CURL_POLL_OUT;
|
|
|
|
|
|
|
|
do {
|
|
|
|
errorCode = curl_multi_socket_action(multi->handle,
|
|
|
|
multi->pollfds[i].fd, action,
|
|
|
|
runningHandles);
|
|
|
|
} while (errorCode == CURLM_CALL_MULTI_SOCKET);
|
|
|
|
|
|
|
|
if (errorCode != CURLM_OK) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not trigger socket action: %s (%d)"),
|
|
|
|
curl_multi_strerror(errorCode), errorCode);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_Wait(esxVI_MultiCURL *multi, int *runningHandles)
|
|
|
|
{
|
|
|
|
long timeout = -1;
|
|
|
|
CURLMcode errorCode;
|
|
|
|
|
|
|
|
curl_multi_timeout(multi->handle, &timeout);
|
|
|
|
|
|
|
|
if (timeout < 0)
|
|
|
|
timeout = 1000; /* default to 1 sec timeout */
|
|
|
|
|
|
|
|
errorCode = curl_multi_wait(multi->handle, NULL, 0, timeout, NULL);
|
|
|
|
|
|
|
|
if (errorCode != CURLM_OK) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not wait for transfer: %s (%d)"),
|
|
|
|
curl_multi_strerror(errorCode), errorCode);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return esxVI_MultiCURL_Perform(multi, runningHandles);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_Perform(esxVI_MultiCURL *multi, int *runningHandles)
|
|
|
|
{
|
|
|
|
CURLMcode errorCode;
|
|
|
|
|
|
|
|
do {
|
|
|
|
errorCode = curl_multi_perform(multi->handle, runningHandles);
|
|
|
|
} while (errorCode == CURLM_CALL_MULTI_PERFORM);
|
|
|
|
|
|
|
|
if (errorCode != CURLM_OK) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not transfer data: %s (%d)"),
|
|
|
|
curl_multi_strerror(errorCode), errorCode);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns -1 on error, 0 if there is no DONE message, 1 if there is a DONE message */
|
|
|
|
int
|
|
|
|
esxVI_MultiCURL_CheckFirstMessage(esxVI_MultiCURL *multi, long *responseCode,
|
|
|
|
CURLcode *errorCode)
|
|
|
|
{
|
|
|
|
int messagesInQueue;
|
|
|
|
CURLMsg* msg = curl_multi_info_read(multi->handle, &messagesInQueue);
|
|
|
|
|
|
|
|
*responseCode = 0;
|
|
|
|
|
|
|
|
if (!msg || msg->msg != CURLMSG_DONE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*errorCode = msg->data.result;
|
|
|
|
|
|
|
|
if (*errorCode != CURLE_OK)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, responseCode);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-02-19 14:27:16 +00:00
|
|
|
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Context
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* esxVI_Context_Alloc */
|
|
|
|
ESX_VI__TEMPLATE__ALLOC(Context)
|
|
|
|
|
|
|
|
/* esxVI_Context_Free */
|
|
|
|
ESX_VI__TEMPLATE__FREE(Context,
|
|
|
|
{
|
2014-11-13 14:22:20 +00:00
|
|
|
if (item->sessionLock)
|
2011-05-01 19:57:43 +00:00
|
|
|
virMutexDestroy(item->sessionLock);
|
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_CURL_Free(&item->curl);
|
|
|
|
VIR_FREE(item->url);
|
|
|
|
VIR_FREE(item->ipAddress);
|
|
|
|
VIR_FREE(item->username);
|
|
|
|
VIR_FREE(item->password);
|
|
|
|
esxVI_ServiceContent_Free(&item->service);
|
|
|
|
esxVI_UserSession_Free(&item->session);
|
2011-05-01 19:57:43 +00:00
|
|
|
VIR_FREE(item->sessionLock);
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_Datacenter_Free(&item->datacenter);
|
2011-11-01 16:12:37 +00:00
|
|
|
VIR_FREE(item->datacenterPath);
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_ComputeResource_Free(&item->computeResource);
|
2011-11-01 16:12:37 +00:00
|
|
|
VIR_FREE(item->computeResourcePath);
|
2011-02-19 13:34:25 +00:00
|
|
|
esxVI_HostSystem_Free(&item->hostSystem);
|
2011-11-01 16:12:37 +00:00
|
|
|
VIR_FREE(item->hostSystemName);
|
2011-02-19 13:34:25 +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);
|
2012-08-05 20:11:50 +00:00
|
|
|
esxVI_SelectionSpec_Free(&item->selectSet_datacenterToNetwork);
|
2011-02-19 13:34:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
|
|
|
|
const char *ipAddress, const char *username,
|
|
|
|
const char *password, esxUtil_ParsedUri *parsedUri)
|
|
|
|
{
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx || !url || !ipAddress || !username ||
|
|
|
|
!password || ctx->url || ctx->service || ctx->curl) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2011-02-19 13:34:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_CURL_Alloc(&ctx->curl) < 0 ||
|
|
|
|
esxVI_CURL_Connect(ctx->curl, parsedUri) < 0 ||
|
2013-05-17 21:19:21 +00:00
|
|
|
VIR_STRDUP(ctx->url, url) < 0 ||
|
|
|
|
VIR_STRDUP(ctx->ipAddress, ipAddress) < 0 ||
|
|
|
|
VIR_STRDUP(ctx->username, username) < 0 ||
|
|
|
|
VIR_STRDUP(ctx->password, password) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 10:05:43 +00:00
|
|
|
if (VIR_ALLOC(ctx->sessionLock) < 0)
|
2011-05-01 19:57:43 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virMutexInit(ctx->sessionLock) < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not initialize session mutex"));
|
2011-05-01 19:57:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +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
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
if (STRNEQ(ctx->service->about->apiType, "HostAgent") &&
|
|
|
|
STRNEQ(ctx->service->about->apiType, "VirtualCenter")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting VI API type 'HostAgent' or 'VirtualCenter' "
|
|
|
|
"but found '%s'"), ctx->service->about->apiType);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virParseVersionString(ctx->service->about->apiVersion,
|
|
|
|
&ctx->apiVersion, true) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse VI API version '%s'"),
|
|
|
|
ctx->service->about->apiVersion);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->apiVersion < 1000000 * 2 + 1000 * 5 /* 2.5 */) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Minimum supported %s version is %s but found version '%s'"),
|
|
|
|
"VI API", "2.5", ctx->service->about->apiVersion);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virParseVersionString(ctx->service->about->version,
|
|
|
|
&ctx->productVersion, true) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse product version '%s'"),
|
|
|
|
ctx->service->about->version);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(ctx->service->about->productLineId, "gsx")) {
|
|
|
|
if (ctx->productVersion < 1000000 * 2 + 1000 * 0 /* 2.0 */) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-10-18 22:11:13 +00:00
|
|
|
_("Minimum supported %s version is %s but found version '%s'"),
|
|
|
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_GSX),
|
|
|
|
"2.0", ctx->service->about->version);
|
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
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
ctx->productLine = esxVI_ProductLine_GSX;
|
|
|
|
} else if (STREQ(ctx->service->about->productLineId, "esx") ||
|
|
|
|
STREQ(ctx->service->about->productLineId, "embeddedEsx")) {
|
|
|
|
if (ctx->productVersion < 1000000 * 3 + 1000 * 5 /* 3.5 */) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Minimum supported %s version is %s but found version '%s'"),
|
|
|
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_ESX),
|
|
|
|
"3.5", ctx->service->about->version);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->productLine = esxVI_ProductLine_ESX;
|
|
|
|
} else if (STREQ(ctx->service->about->productLineId, "vpx")) {
|
|
|
|
if (ctx->productVersion < 1000000 * 2 + 1000 * 5 /* 2.5 */) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-10-18 22:11:13 +00:00
|
|
|
_("Minimum supported %s version is %s but found version '%s'"),
|
|
|
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine_VPX),
|
|
|
|
"2.5", ctx->service->about->version);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2014-10-18 22:11:13 +00:00
|
|
|
|
|
|
|
ctx->productLine = esxVI_ProductLine_VPX;
|
2009-07-23 20:21:08 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2014-10-18 22:11:13 +00:00
|
|
|
_("Expecting product 'gsx' or 'esx' or 'embeddedEsx' "
|
|
|
|
"or 'vpx' but found '%s'"),
|
|
|
|
ctx->service->about->productLineId);
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
if (ctx->productLine == esxVI_ProductLine_ESX) {
|
2010-09-03 23:30:04 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (ctx->productLine == esxVI_ProductLine_VPX)
|
2010-09-05 14:53:10 +00:00
|
|
|
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
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
|
2010-07-31 21:57:42 +00:00
|
|
|
{
|
|
|
|
/* Lookup Datacenter */
|
2011-11-01 16:12:37 +00:00
|
|
|
if (esxVI_LookupDatacenter(ctx, NULL, ctx->service->rootFolder, NULL,
|
|
|
|
&ctx->datacenter,
|
2011-04-10 11:27:56 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
return -1;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-12-20 18:16:05 +00:00
|
|
|
/* Lookup (Cluster)ComputeResource */
|
2011-11-01 16:12:37 +00:00
|
|
|
if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder,
|
|
|
|
NULL, &ctx->computeResource,
|
2011-04-10 11:27:56 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
return -1;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->computeResource->resourcePool) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve resource pool"));
|
2011-04-10 11:27:56 +00:00
|
|
|
return -1;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-07-31 21:57:42 +00:00
|
|
|
/* Lookup HostSystem */
|
2011-11-01 16:12:37 +00:00
|
|
|
if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference,
|
|
|
|
NULL, &ctx->hostSystem,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2011-04-10 11:27:56 +00:00
|
|
|
return -1;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
char *tmp = NULL;
|
|
|
|
char *saveptr = NULL;
|
|
|
|
char *previousItem = NULL;
|
|
|
|
char *item = NULL;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
esxVI_ManagedObjectReference *root = NULL;
|
|
|
|
esxVI_Folder *folder = NULL;
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(tmp, path) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Lookup Datacenter */
|
|
|
|
item = strtok_r(tmp, "/", &saveptr);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!item) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Path '%s' does not specify a datacenter"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
root = ctx->service->rootFolder;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
while (!ctx->datacenter && item) {
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Folder_Free(&folder);
|
|
|
|
|
|
|
|
/* Try to lookup item as a folder */
|
|
|
|
if (esxVI_LookupFolder(ctx, item, root, NULL, &folder,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (folder) {
|
2011-11-01 16:12:37 +00:00
|
|
|
/* It's a folder, use it as new lookup root */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (root != ctx->service->rootFolder)
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_ManagedObjectReference_Free(&root);
|
|
|
|
|
|
|
|
root = folder->_reference;
|
|
|
|
folder->_reference = NULL;
|
|
|
|
} else {
|
|
|
|
/* Try to lookup item as a datacenter */
|
|
|
|
if (esxVI_LookupDatacenter(ctx, item, root, NULL, &ctx->datacenter,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build datacenter path */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (virBufferUse(&buffer) > 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
virBufferAddChar(&buffer, '/');
|
|
|
|
|
|
|
|
virBufferAdd(&buffer, item, -1);
|
|
|
|
|
|
|
|
previousItem = item;
|
|
|
|
item = strtok_r(NULL, "/", &saveptr);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->datacenter) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datacenter specified in '%s'"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ctx->datacenterPath = virBufferContentAndReset(&buffer);
|
|
|
|
|
|
|
|
/* Lookup (Cluster)ComputeResource */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!item) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Path '%s' does not specify a compute resource"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (root != ctx->service->rootFolder)
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_ManagedObjectReference_Free(&root);
|
|
|
|
|
|
|
|
root = ctx->datacenter->hostFolder;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
while (!ctx->computeResource && item) {
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Folder_Free(&folder);
|
|
|
|
|
|
|
|
/* Try to lookup item as a folder */
|
|
|
|
if (esxVI_LookupFolder(ctx, item, root, NULL, &folder,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (folder) {
|
2011-11-01 16:12:37 +00:00
|
|
|
/* It's a folder, use it as new lookup root */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (root != ctx->datacenter->hostFolder)
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_ManagedObjectReference_Free(&root);
|
|
|
|
|
|
|
|
root = folder->_reference;
|
|
|
|
folder->_reference = NULL;
|
2010-07-31 21:57:42 +00:00
|
|
|
} else {
|
2011-11-01 16:12:37 +00:00
|
|
|
/* Try to lookup item as a compute resource */
|
|
|
|
if (esxVI_LookupComputeResource(ctx, item, root, NULL,
|
|
|
|
&ctx->computeResource,
|
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build compute resource path */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (virBufferUse(&buffer) > 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
virBufferAddChar(&buffer, '/');
|
|
|
|
|
|
|
|
virBufferAdd(&buffer, item, -1);
|
|
|
|
|
|
|
|
previousItem = item;
|
|
|
|
item = strtok_r(NULL, "/", &saveptr);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->computeResource) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find compute resource specified in '%s'"),
|
|
|
|
path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->computeResource->resourcePool) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve resource pool"));
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ctx->computeResourcePath = virBufferContentAndReset(&buffer);
|
|
|
|
|
|
|
|
/* Lookup HostSystem */
|
|
|
|
if (STREQ(ctx->computeResource->_reference->type,
|
|
|
|
"ClusterComputeResource")) {
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!item) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Path '%s' does not specify a host system"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
2011-11-01 16:12:37 +00:00
|
|
|
|
|
|
|
/* The path specified a cluster, it has to specify a host system too */
|
|
|
|
previousItem = item;
|
|
|
|
item = strtok_r(NULL, "/", &saveptr);
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (item) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Path '%s' ends with an excess item"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName,
|
2011-04-10 11:27:56 +00:00
|
|
|
ctx->computeResource->_reference, NULL,
|
|
|
|
&ctx->hostSystem,
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->hostSystem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find host system specified in '%s'"), path);
|
2011-11-01 16:12:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (result < 0)
|
2011-11-01 16:12:37 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
|
|
|
|
|
|
|
if (root != ctx->service->rootFolder &&
|
2013-10-17 17:04:11 +00:00
|
|
|
(!ctx->datacenter || root != ctx->datacenter->hostFolder)) {
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_ManagedObjectReference_Free(&root);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
esxVI_Folder_Free(&folder);
|
|
|
|
|
|
|
|
return result;
|
2010-07-31 21:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-11-01 16:12:37 +00:00
|
|
|
esxVI_Context_LookupManagedObjectsByHostSystemIp(esxVI_Context *ctx,
|
|
|
|
const char *hostSystemIpAddress)
|
2010-07-31 21:57:42 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_ManagedObjectReference *managedObjectReference = NULL;
|
|
|
|
|
|
|
|
/* Lookup HostSystem */
|
2011-04-10 11:27:56 +00:00
|
|
|
if (esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
|
2010-07-31 21:57:42 +00:00
|
|
|
&managedObjectReference) < 0 ||
|
2011-04-10 11:27:56 +00:00
|
|
|
esxVI_LookupHostSystem(ctx, NULL, managedObjectReference, NULL,
|
|
|
|
&ctx->hostSystem,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-12-20 18:16:05 +00:00
|
|
|
/* Lookup (Cluster)ComputeResource */
|
2011-04-10 11:27:56 +00:00
|
|
|
if (esxVI_LookupComputeResource(ctx, NULL, ctx->hostSystem->_reference,
|
|
|
|
NULL, &ctx->computeResource,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-07-31 21:57:42 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->computeResource->resourcePool) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve resource pool"));
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup Datacenter */
|
2011-04-10 11:27:56 +00:00
|
|
|
if (esxVI_LookupDatacenter(ctx, NULL, ctx->computeResource->_reference,
|
|
|
|
NULL, &ctx->datacenter,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-07-31 21:57:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-07-31 21:57:42 +00:00
|
|
|
esxVI_ManagedObjectReference_Free(&managedObjectReference);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!request || !response || *response) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +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
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
virMutexLock(&ctx->curl->lock);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(ctx->curl->handle, CURLOPT_URL, ctx->url);
|
2012-07-12 23:58:27 +00:00
|
|
|
curl_easy_setopt(ctx->curl->handle, CURLOPT_RANGE, NULL);
|
2011-02-19 13:34:25 +00:00
|
|
|
curl_easy_setopt(ctx->curl->handle, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0);
|
|
|
|
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
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
(*response)->responseCode = esxVI_CURL_Perform(ctx->curl, ctx->url);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-02-19 13:34:25 +00:00
|
|
|
virMutexUnlock(&ctx->curl->lock);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if ((*response)->responseCode < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2009-09-04 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) {
|
2011-08-18 21:37:14 +00:00
|
|
|
(*response)->document = virXMLParseStringCtxt((*response)->content,
|
2011-09-14 14:17:57 +00:00
|
|
|
_("(esx execute response)"),
|
2011-08-18 21:37:14 +00:00
|
|
|
&xpathContext);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!(*response)->document)
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*response)->node) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault is unknown, XPath evaluation failed"),
|
|
|
|
(*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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault is unknown, deserialization failed"),
|
|
|
|
(*response)->responseCode, methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for call to '%s'. "
|
|
|
|
"Fault: %s - %s"), (*response)->responseCode,
|
|
|
|
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",
|
2013-07-04 10:05:43 +00:00
|
|
|
methodName) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!responseNode) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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:
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*response)->node) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Call to '%s' returned an empty result, "
|
|
|
|
"expecting a non-empty result"), methodName);
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2013-10-17 17:04:11 +00:00
|
|
|
} else if ((*response)->node->next) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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:
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*response)->node) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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:
|
2013-10-17 17:04:11 +00:00
|
|
|
if ((*response)->node &&
|
|
|
|
(*response)->node->next) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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:
|
2013-10-17 17:04:11 +00:00
|
|
|
if ((*response)->node) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("HTTP response code %d for call to '%s'"),
|
|
|
|
(*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;
|
|
|
|
|
2014-03-25 06:48:48 +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 */
|
2011-02-19 13:34:25 +00:00
|
|
|
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
|
|
|
|
2011-08-18 20:54:43 +00:00
|
|
|
xmlFreeDoc(item->document);
|
2011-02-19 13:34:25 +00:00
|
|
|
})
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* 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)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!anyType || !value) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting type '%s' but found '%s'"),
|
|
|
|
esxVI_Type_ToString(enumeration->type),
|
2012-07-21 20:50:24 +00:00
|
|
|
esxVI_AnyType_TypeToString(anyType));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (i = 0; enumeration->values[i].name; ++i) {
|
2009-07-23 20:21:08 +00:00
|
|
|
if (STREQ(anyType->value, enumeration->values[i].name)) {
|
|
|
|
*value = enumeration->values[i].value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown value '%s' for %s"), anyType->value,
|
|
|
|
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
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2009-07-23 20:21:08 +00:00
|
|
|
const char *name = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!element || !output) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (i = 0; enumeration->values[i].name; ++i) {
|
2009-07-23 20:21:08 +00:00
|
|
|
if (value == enumeration->values[i].value) {
|
|
|
|
name = enumeration->values[i].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!name) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
char *name = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!value) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 */
|
|
|
|
|
2014-11-13 14:22:20 +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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (i = 0; enumeration->values[i].name; ++i) {
|
2009-07-23 20:21:08 +00:00
|
|
|
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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown value '%s' for %s"),
|
|
|
|
name, esxVI_Type_ToString(enumeration->type));
|
2010-05-19 20:59:32 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!list || !item) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*list)) {
|
2009-07-23 20:21:08 +00:00
|
|
|
*list = item;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
next = *list;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
while (next->_next)
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!destList || *destList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (src = srcList; src; 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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
failure:
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!list || *list || !castFromAnyTypeFunc || !freeFunc) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!anyType)
|
2009-09-23 12:29:39 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (! STRPREFIX(anyType->other, "ArrayOf")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting type to begin with 'ArrayOf' but found '%s'"),
|
|
|
|
anyType->other);
|
2009-12-15 18:22:31 +00:00
|
|
|
return -1;
|
2009-09-23 12:29:39 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (childNode = anyType->node->children; childNode;
|
2009-09-23 12:29:39 +00:00
|
|
|
childNode = childNode->next) {
|
|
|
|
if (childNode->type != XML_ELEMENT_NODE) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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;
|
|
|
|
|
2014-03-25 06:48:48 +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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!element || !output || !serializeFunc) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!list)
|
2010-02-23 00:06:58 +00:00
|
|
|
return 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (item = list; item; item = item->_next) {
|
2014-11-13 14:22:20 +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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!list || *list || !deserializeFunc || !freeFunc) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!node)
|
2009-07-23 20:21:08 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (; node; node = node->next) {
|
2009-07-23 20:21:08 +00:00
|
|
|
if (node->type != XML_ELEMENT_NODE) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
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-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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!selectSet) {
|
2010-08-26 22:07:23 +00:00
|
|
|
/*
|
|
|
|
* Don't check for *selectSet != NULL here because selectSet is a list
|
|
|
|
* and might contain items already. This function appends to selectSet.
|
|
|
|
*/
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 ||
|
2013-05-17 21:19:21 +00:00
|
|
|
VIR_STRDUP(traversalSpec->name, name) < 0 ||
|
|
|
|
VIR_STRDUP(traversalSpec->type, type) < 0 ||
|
|
|
|
VIR_STRDUP(traversalSpec->path, path) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
traversalSpec->skip = esxVI_Boolean_False;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (selectSetNames) {
|
2009-07-23 20:21:08 +00:00
|
|
|
currentSelectSetName = selectSetNames;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
while (currentSelectSetName && *currentSelectSetName != '\0') {
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0 ||
|
2013-05-17 21:19:21 +00:00
|
|
|
VIR_STRDUP(selectionSpec->name, 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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
failure:
|
2009-07-23 20:21:08 +00:00
|
|
|
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",
|
2011-11-01 16:12:37 +00:00
|
|
|
"Folder", "childEntity", NULL) < 0) {
|
2010-08-21 16:49:18 +00:00
|
|
|
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
|
|
|
|
2012-08-05 20:11:50 +00:00
|
|
|
/* Datacenter -> network (Network) */
|
|
|
|
if (esxVI_BuildSelectSet(&ctx->selectSet_datacenterToNetwork,
|
|
|
|
"datacenterToNetwork",
|
|
|
|
"Datacenter", "network", NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->sessionLock) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no mutex"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-01 19:57:43 +00:00
|
|
|
virMutexLock(ctx->sessionLock);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ctx->session) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no session"));
|
2011-05-01 19:57:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-09-05 14:53:10 +00:00
|
|
|
if (ctx->hasSessionIsActive) {
|
|
|
|
/*
|
|
|
|
* Use SessionIsActive to check if there is an active session for this
|
2011-12-04 00:06:07 +00:00
|
|
|
* connection, and re-login if there isn't.
|
2010-09-05 14:53:10 +00:00
|
|
|
*/
|
|
|
|
if (esxVI_SessionIsActive(ctx, ctx->session->key,
|
|
|
|
ctx->session->userName, &active) < 0) {
|
2011-05-01 19:57:43 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
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) {
|
2011-05-01 19:57:43 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
2010-09-05 14:53:10 +00:00
|
|
|
}
|
|
|
|
} 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,
|
2010-12-30 12:30:44 +00:00
|
|
|
&sessionManager,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-09-05 14:53:10 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = sessionManager->propSet; dynamicProperty;
|
2010-09-05 14:53:10 +00:00
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!currentSession) {
|
2010-09-05 14:53:10 +00:00
|
|
|
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)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
2011-05-01 19:57:43 +00:00
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-05-01 19:57:43 +00:00
|
|
|
result = 0;
|
2010-05-19 20:59:32 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-05-01 19:57:43 +00:00
|
|
|
virMutexUnlock(ctx->sessionLock);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-05-01 19:57:43 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&sessionManager);
|
|
|
|
esxVI_UserSession_Free(¤tSession);
|
|
|
|
|
|
|
|
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,
|
2010-12-30 12:30:44 +00:00
|
|
|
esxVI_ObjectContent **objectContentList,
|
|
|
|
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_ObjectSpec *objectSpec = NULL;
|
2012-05-06 17:33:59 +00:00
|
|
|
bool objectSpec_isAppended = false;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PropertySpec *propertySpec = NULL;
|
2012-05-06 17:33:59 +00:00
|
|
|
bool propertySpec_isAppended = false;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PropertyFilterSpec *propertyFilterSpec = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!objectContentList || *objectContentList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-07-31 21:57:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +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;
|
|
|
|
|
2011-11-01 16:12:37 +00:00
|
|
|
if (STRNEQ(root->type, type) || STREQ(root->type, "Folder")) {
|
2010-08-21 16:49:18 +00:00
|
|
|
if (STREQ(root->type, "Folder")) {
|
2011-11-01 16:12:37 +00:00
|
|
|
if (STREQ(type, "Folder") || STREQ(type, "Datacenter") ||
|
|
|
|
STREQ(type, "ComputeResource") ||
|
2010-12-20 18:16:05 +00:00
|
|
|
STREQ(type, "ClusterComputeResource")) {
|
2010-08-21 16:49:18 +00:00
|
|
|
objectSpec->selectSet = ctx->selectSet_folderToChildEntity;
|
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
2010-08-21 16:49:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-20 18:16:05 +00:00
|
|
|
} else if (STREQ(root->type, "ComputeResource") ||
|
|
|
|
STREQ(root->type, "ClusterComputeResource")) {
|
2010-08-21 16:49:18 +00:00
|
|
|
if (STREQ(type, "HostSystem")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_computeResourceToHost;
|
|
|
|
} else if (STREQ(type, "Datacenter")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_computeResourceToParentToParent;
|
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
2010-08-21 16:49:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else if (STREQ(root->type, "HostSystem")) {
|
2010-12-20 18:16:05 +00:00
|
|
|
if (STREQ(type, "ComputeResource") ||
|
|
|
|
STREQ(type, "ClusterComputeResource")) {
|
2010-08-21 16:49:18 +00:00
|
|
|
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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
2010-08-21 16:49:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-08-05 20:11:50 +00:00
|
|
|
} else if (STREQ(root->type, "Datacenter")) {
|
|
|
|
if (STREQ(type, "Network")) {
|
|
|
|
objectSpec->selectSet = ctx->selectSet_datacenterToNetwork;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup of '%s' from '%s'"),
|
|
|
|
type, root->type);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-08-21 16:49:18 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid lookup from '%s'"), root->type);
|
2010-08-21 16:49:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +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,
|
2012-05-06 17:33:59 +00:00
|
|
|
propertySpec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
propertySpec_isAppended = true;
|
|
|
|
|
|
|
|
if (esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
|
|
|
|
objectSpec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
objectSpec_isAppended = true;
|
|
|
|
|
|
|
|
if (esxVI_RetrieveProperties(ctx, propertyFilterSpec,
|
2010-12-30 12:30:44 +00:00
|
|
|
objectContentList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*objectContentList)) {
|
2010-12-30 12:30:44 +00:00
|
|
|
switch (occurrence) {
|
|
|
|
case esxVI_Occurrence_OptionalItem:
|
|
|
|
case esxVI_Occurrence_OptionalList:
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_Occurrence_RequiredItem:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not lookup '%s' from '%s'"),
|
|
|
|
type, root->type);
|
2010-12-30 12:30:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case esxVI_Occurrence_RequiredList:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not lookup '%s' list from '%s'"),
|
|
|
|
type, root->type);
|
2010-12-30 12:30:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Invalid occurrence value"));
|
2010-12-30 12:30:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 12:30:44 +00:00
|
|
|
result = 0;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
/*
|
|
|
|
* Remove values given by the caller from the data structures to prevent
|
|
|
|
* them from being freed by the call to esxVI_PropertyFilterSpec_Free().
|
2013-01-17 19:17:13 +00:00
|
|
|
* objectSpec cannot be NULL here.
|
2009-07-23 20:21:08 +00:00
|
|
|
*/
|
2013-01-17 19:17:13 +00:00
|
|
|
objectSpec->obj = NULL;
|
|
|
|
objectSpec->selectSet = NULL;
|
2012-05-06 17:33:59 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (propertySpec) {
|
2009-07-23 20:21:08 +00:00
|
|
|
propertySpec->type = NULL;
|
|
|
|
propertySpec->pathSet = NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!objectSpec_isAppended)
|
2012-05-06 17:33:59 +00:00
|
|
|
esxVI_ObjectSpec_Free(&objectSpec);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!propertySpec_isAppended)
|
2012-05-06 17:33:59 +00:00
|
|
|
esxVI_PropertySpec_Free(&propertySpec);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2009-09-04 16:03:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
|
|
|
|
return esxVI_VirtualMachinePowerState_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, powerState);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!questionInfo || *questionInfo) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2009-11-15 21:22:47 +00:00
|
|
|
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,
|
2010-12-30 11:54:20 +00:00
|
|
|
esxVI_Boolean *value, esxVI_Occurrence occurrence)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!value || *value != esxVI_Boolean_Undefined) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2010-05-18 16:11:59 +00:00
|
|
|
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 &&
|
2010-12-30 11:54:20 +00:00
|
|
|
occurrence == esxVI_Occurrence_RequiredItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-30 11:54:20 +00:00
|
|
|
|
|
|
|
|
2010-11-06 17:53:39 +00:00
|
|
|
int
|
|
|
|
esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
|
2010-12-30 11:54:20 +00:00
|
|
|
esxVI_Long **value, esxVI_Occurrence occurrence)
|
2010-11-06 17:53:39 +00:00
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!value || *value) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-11-06 17:53:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2010-11-06 17:53:39 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0)
|
2010-11-06 17:53:39 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
2010-11-06 17:53:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetStringValue(esxVI_ObjectContent *objectContent,
|
|
|
|
const char *propertyName,
|
2010-12-30 11:54:20 +00:00
|
|
|
char **value, esxVI_Occurrence occurrence)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!value || *value) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2010-05-18 16:11:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetManagedObjectReference(esxVI_ObjectContent *objectContent,
|
|
|
|
const char *propertyName,
|
|
|
|
esxVI_ManagedObjectReference **value,
|
2010-12-30 11:54:20 +00:00
|
|
|
esxVI_Occurrence occurrence)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!value || *value) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2010-05-18 16:11:59 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, propertyName)) {
|
|
|
|
if (esxVI_ManagedObjectReference_CastFromAnyType
|
|
|
|
(dynamicProperty->val, value) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*value) && occurrence == esxVI_Occurrence_RequiredItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing '%s' property"), propertyName);
|
2010-05-18 16:11:59 +00:00
|
|
|
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,
|
2011-05-01 19:57:45 +00:00
|
|
|
bool 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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine = virtualMachine->_next) {
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "runtime.powerState")) {
|
|
|
|
if (esxVI_VirtualMachinePowerState_CastFromAnyType
|
2010-01-15 22:05:26 +00:00
|
|
|
(dynamicProperty->val, &powerState_) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 19:57:45 +00:00
|
|
|
if ((!inverse && powerState_ == powerState) ||
|
2012-10-17 09:23:12 +00:00
|
|
|
(inverse && 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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
return success ? count : -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("ObjectContent does not reference a virtual machine"));
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (id) {
|
2009-07-23 20:21:08 +00:00
|
|
|
if (esxUtil_ParseVirtualMachineIDString
|
|
|
|
(virtualMachine->obj->value, id) < 0 || *id <= 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse positive integer from '%s'"),
|
|
|
|
virtualMachine->obj->value);
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (name) {
|
|
|
|
if (*name) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = virtualMachine->propSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty;
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0)
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
if (virVMXUnescapeHexPercent(*name) < 0) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain name contains invalid escape sequence"));
|
2010-10-12 17:37:39 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*name)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not get name of virtual machine"));
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (uuid) {
|
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;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty;
|
2009-09-04 16:03:22 +00:00
|
|
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!uuid_string) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not parse UUID from string '%s'"),
|
|
|
|
uuid_string);
|
2009-09-04 16:03:22 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memset(uuid, 0, VIR_UUID_BUFLEN);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Cannot access UUID, because 'configStatus' property "
|
2009-09-04 16:03:22 +00:00
|
|
|
"indicates a config problem");
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
failure:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (name)
|
2009-07-23 20:21:08 +00:00
|
|
|
VIR_FREE(*name);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-07 09:23:53 +00:00
|
|
|
int
|
|
|
|
esxVI_GetNumberOfSnapshotTrees
|
2011-10-08 02:30:14 +00:00
|
|
|
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, bool recurse,
|
|
|
|
bool leaves)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (snapshotTree = snapshotTreeList; snapshotTree;
|
2010-04-07 09:23:53 +00:00
|
|
|
snapshotTree = snapshotTree->_next) {
|
2011-10-08 02:30:14 +00:00
|
|
|
if (!(leaves && snapshotTree->childSnapshotList))
|
|
|
|
count++;
|
2011-10-03 17:38:21 +00:00
|
|
|
if (recurse)
|
|
|
|
count += esxVI_GetNumberOfSnapshotTrees
|
2011-10-08 02:30:14 +00:00
|
|
|
(snapshotTree->childSnapshotList, true, leaves);
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
|
2011-10-08 02:30:14 +00:00
|
|
|
char **names, int nameslen, bool recurse,
|
|
|
|
bool leaves)
|
2010-04-07 09:23:53 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int result;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-04-07 09:23:53 +00:00
|
|
|
esxVI_VirtualMachineSnapshotTree *snapshotTree;
|
|
|
|
|
|
|
|
for (snapshotTree = snapshotTreeList;
|
2013-10-17 17:04:11 +00:00
|
|
|
snapshotTree && count < nameslen;
|
2010-04-07 09:23:53 +00:00
|
|
|
snapshotTree = snapshotTree->_next) {
|
2011-10-08 02:30:14 +00:00
|
|
|
if (!(leaves && snapshotTree->childSnapshotList)) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(names[count], snapshotTree->name) < 0)
|
2011-10-08 02:30:14 +00:00
|
|
|
goto failure;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-10-08 02:30:14 +00:00
|
|
|
count++;
|
|
|
|
}
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (count >= nameslen)
|
2010-04-07 09:23:53 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-03 17:38:21 +00:00
|
|
|
if (recurse) {
|
|
|
|
result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList,
|
|
|
|
names + count,
|
|
|
|
nameslen - count,
|
2011-10-08 02:30:14 +00:00
|
|
|
true, leaves);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (result < 0)
|
2011-10-03 17:38:21 +00:00
|
|
|
goto failure;
|
2010-04-07 09:23:53 +00:00
|
|
|
|
2011-10-03 17:38:21 +00:00
|
|
|
count += result;
|
|
|
|
}
|
2010-04-07 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
failure:
|
2014-11-13 14:22:20 +00:00
|
|
|
for (i = 0; i < count; ++i)
|
2010-04-07 09:23:53 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!snapshotTree || *snapshotTree ||
|
|
|
|
(snapshotTreeParent && *snapshotTreeParent)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-04-07 09:23:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = snapshotTreeList; candidate;
|
2010-04-07 09:23:53 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STREQ(candidate->name, name)) {
|
|
|
|
*snapshotTree = candidate;
|
2011-10-03 18:02:25 +00:00
|
|
|
if (snapshotTreeParent)
|
|
|
|
*snapshotTreeParent = NULL;
|
2010-04-07 09:23:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_GetSnapshotTreeByName(candidate->childSnapshotList, name,
|
|
|
|
snapshotTree, snapshotTreeParent,
|
|
|
|
occurrence) > 0) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (snapshotTreeParent && !(*snapshotTreeParent))
|
2010-04-07 09:23:53 +00:00
|
|
|
*snapshotTreeParent = candidate;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("Could not find snapshot with name '%s'"), name);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_GetSnapshotTreeBySnapshot
|
|
|
|
(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
|
|
|
|
esxVI_ManagedObjectReference *snapshot,
|
|
|
|
esxVI_VirtualMachineSnapshotTree **snapshotTree)
|
|
|
|
{
|
|
|
|
esxVI_VirtualMachineSnapshotTree *candidate;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!snapshotTree || *snapshotTree) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-04-07 09:23:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = snapshotTreeList; candidate;
|
2010-04-07 09:23:53 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STREQ(candidate->snapshot->value, snapshot->value)) {
|
|
|
|
*snapshotTree = candidate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_GetSnapshotTreeBySnapshot(candidate->childSnapshotList,
|
|
|
|
snapshot, snapshotTree) >= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
|
|
|
_("Could not find domain snapshot with internal name '%s'"),
|
|
|
|
snapshot->value);
|
2010-04-07 09:23:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-30 11:54:20 +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-12-30 12:30:44 +00:00
|
|
|
hostSystem,
|
|
|
|
esxVI_Occurrence_RequiredItem);
|
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,
|
2010-12-30 12:30:44 +00:00
|
|
|
virtualMachineList,
|
|
|
|
esxVI_Occurrence_OptionalList);
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virtualMachine || *virtualMachine) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_Boolean_True, esxVI_Boolean_Undefined,
|
|
|
|
&managedObjectReference) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!managedObjectReference) {
|
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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("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,
|
2010-12-30 12:30:44 +00:00
|
|
|
virtualMachine,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!virtualMachine || *virtualMachine) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = virtualMachineList; candidate;
|
2010-03-02 23:57:57 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (STRNEQ(name, name_candidate))
|
2010-03-02 23:57:57 +00:00
|
|
|
continue;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*virtualMachine)) {
|
2010-03-02 23:57:57 +00:00
|
|
|
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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-03-02 23:57:57 +00:00
|
|
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
bool autoAnswer)
|
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 *completePropertyNameList = NULL;
|
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo = NULL;
|
|
|
|
esxVI_TaskInfo *pendingTaskInfoList = NULL;
|
2011-05-01 19:57:45 +00:00
|
|
|
bool blocked;
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (questionInfo &&
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (pendingTaskInfoList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-11-15 21:22:47 +00:00
|
|
|
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-12-30 12:30:44 +00:00
|
|
|
datastoreList,
|
|
|
|
esxVI_Occurrence_OptionalList);
|
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
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!datastore || *datastore) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = datastoreList; candidate;
|
2010-08-01 17:53:00 +00:00
|
|
|
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)) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0)
|
2010-08-01 17:53:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*datastore) && occurrence != esxVI_Occurrence_OptionalItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find datastore with name '%s'"), name);
|
2010-08-01 17:53:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-01 17:53:00 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!datastore || *datastore) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-08-01 17:53:00 +00:00
|
|
|
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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = datastoreList; candidate;
|
2009-09-23 12:52:36 +00:00
|
|
|
candidate = candidate->_next) {
|
2010-08-01 17:53:00 +00:00
|
|
|
esxVI_DatastoreHostMount_Free(&datastoreHostMountList);
|
2009-09-23 13:08:25 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = candidate->propSet; dynamicProperty;
|
2009-09-23 12:52:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!datastoreHostMountList)
|
2010-08-01 17:53:00 +00:00
|
|
|
continue;
|
2009-09-23 13:08:25 +00:00
|
|
|
|
2010-08-01 17:53:00 +00:00
|
|
|
for (datastoreHostMount = datastoreHostMountList;
|
2013-10-17 17:04:11 +00:00
|
|
|
datastoreHostMount;
|
2010-08-01 17:53:00 +00:00
|
|
|
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)) {
|
2014-11-13 14:22:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*datastore) && occurrence != esxVI_Occurrence_OptionalItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-09-23 12:52:36 +00:00
|
|
|
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,
|
2012-11-10 07:18:07 +00:00
|
|
|
esxVI_DatastoreHostMount **hostMount,
|
|
|
|
esxVI_Occurrence occurrence)
|
2010-08-01 20:11:38 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *objectContent = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_DatastoreHostMount *hostMountList = NULL;
|
|
|
|
esxVI_DatastoreHostMount *candidate = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostMount || *hostMount) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-08-01 20:11:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType(ctx, datastore, "Datastore",
|
2010-12-30 12:30:44 +00:00
|
|
|
propertyNameList, &objectContent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-08-01 20:11:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2010-08-01 20:11:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = hostMountList; candidate;
|
2010-08-01 20:11:38 +00:00
|
|
|
candidate = candidate->_next) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value))
|
2010-08-01 20:11:38 +00:00
|
|
|
continue;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0)
|
2010-08-01 20:11:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*hostMount) && occurrence == esxVI_Occurrence_RequiredItem) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not lookup datastore host mount"));
|
2010-08-01 20:11:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-01 20:11:38 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!taskInfo || *taskInfo) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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,
|
2010-12-30 12:30:44 +00:00
|
|
|
&objectContent,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = objectContent->propSet; dynamicProperty;
|
2009-11-15 21:22:47 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-11-15 21:22:47 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!pendingTaskInfoList || *pendingTaskInfoList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get list of recent tasks */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2009-11-15 21:22:47 +00:00
|
|
|
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 */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (recentTask = recentTaskList; recentTask;
|
2009-11-15 21:22:47 +00:00
|
|
|
recentTask = recentTask->_next) {
|
2014-11-13 14:22:20 +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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (result < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
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,
|
2011-05-01 19:57:45 +00:00
|
|
|
bool autoAnswer, bool *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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (virtualMachine) {
|
2010-07-25 15:45:19 +00:00
|
|
|
if (esxVI_GetVirtualMachineQuestionInfo(virtualMachine,
|
|
|
|
&questionInfo) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (questionInfo &&
|
2010-07-25 15:45:19 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-11-15 21:22:47 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!rootSnapshotTreeList || *rootSnapshotTreeList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-04-07 09:23:53 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2010-04-07 09:23:53 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (result < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!currentSnapshotTree || *currentSnapshotTree) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-04-07 09:23:53 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = virtualMachine->propSet; dynamicProperty;
|
2010-04-07 09:23:53 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!currentSnapshot) {
|
2010-04-07 09:23:53 +00:00
|
|
|
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 {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!rootSnapshotTreeList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-04-07 09:23:53 +00:00
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!fileInfo || *fileInfo) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-08-07 22:24:29 +00:00
|
|
|
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]",
|
2013-07-04 10:05:43 +00:00
|
|
|
datastoreName) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
2010-08-25 09:44:57 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (VIR_STRDUP(fileName, directoryAndFileName) < 0)
|
2010-08-25 09:44:57 +00:00
|
|
|
goto cleanup;
|
2010-08-07 22:24:29 +00:00
|
|
|
} else {
|
|
|
|
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
|
2013-07-04 10:05:43 +00:00
|
|
|
datastoreName, directoryName) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
2010-08-25 09:44:57 +00:00
|
|
|
|
|
|
|
length = strlen(directoryName);
|
|
|
|
|
|
|
|
if (directoryAndFileName[length] != '/' ||
|
|
|
|
directoryAndFileName[length + 1] == '\0') {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Datastore path '%s' doesn't reference a file"),
|
|
|
|
datastorePath);
|
2010-08-25 09:44:57 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0)
|
2010-08-25 09:44:57 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-09-03 11:16:07 +00:00
|
|
|
folderFileQuery = NULL;
|
2010-08-28 19:49:07 +00:00
|
|
|
} 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;
|
2013-09-03 11:16:07 +00:00
|
|
|
vmDiskFileQuery = NULL;
|
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;
|
|
|
|
}
|
2013-09-03 11:16:07 +00:00
|
|
|
isoImageFileQuery = NULL;
|
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;
|
|
|
|
}
|
2013-09-03 11:16:07 +00:00
|
|
|
floppyImageFileQuery = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
false, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not search in datastore '%s': %s"),
|
|
|
|
datastoreName, taskInfoErrorMessage);
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo) < 0 ||
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_CastFromAnyType
|
|
|
|
(taskInfo->result, &searchResults) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interpret search result */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!searchResults->file) {
|
2010-08-07 22:24:29 +00:00
|
|
|
if (occurrence == esxVI_Occurrence_OptionalItem) {
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("No storage volume with key or path '%s'"),
|
|
|
|
datastorePath);
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*fileInfo = searchResults->file;
|
|
|
|
searchResults->file = NULL;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-07 22:24:29 +00:00
|
|
|
/* Don't double free fileName */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (searchSpec && searchSpec->matchPattern)
|
2010-08-07 22:24:29 +00:00
|
|
|
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);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResults);
|
2013-09-03 11:16:07 +00:00
|
|
|
esxVI_FolderFileQuery_Free(&folderFileQuery);
|
|
|
|
esxVI_VmDiskFileQuery_Free(&vmDiskFileQuery);
|
|
|
|
esxVI_IsoImageFileQuery_Free(&isoImageFileQuery);
|
|
|
|
esxVI_FloppyImageFileQuery_Free(&floppyImageFileQuery);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
|
|
|
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;
|
2010-12-06 12:53:36 +00:00
|
|
|
char *taskInfoErrorMessage = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!searchResultsList || *searchResultsList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-08-07 22:24:29 +00:00
|
|
|
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;
|
2013-09-03 11:16:07 +00:00
|
|
|
vmDiskFileQuery = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
|
|
|
if (esxVI_IsoImageFileQuery_Alloc(&isoImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(isoImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-09-03 11:16:07 +00:00
|
|
|
isoImageFileQuery = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
|
|
|
if (esxVI_FloppyImageFileQuery_Alloc(&floppyImageFileQuery) < 0 ||
|
|
|
|
esxVI_FileQuery_AppendToList
|
|
|
|
(&searchSpec->query,
|
|
|
|
esxVI_FileQuery_DynamicCast(floppyImageFileQuery)) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-09-03 11:16:07 +00:00
|
|
|
floppyImageFileQuery = NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
|
|
|
/* Search datastore for files */
|
2013-07-04 10:05:43 +00:00
|
|
|
if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (esxVI_SearchDatastoreSubFolders_Task(ctx, hostDatastoreBrowser,
|
|
|
|
datastorePath, searchSpec,
|
|
|
|
&task) < 0 ||
|
|
|
|
esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
|
2011-05-01 19:57:44 +00:00
|
|
|
false, &taskInfoState,
|
2010-12-06 12:53:36 +00:00
|
|
|
&taskInfoErrorMessage) < 0) {
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskInfoState != esxVI_TaskInfoState_Success) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2013-07-30 08:21:11 +00:00
|
|
|
_("Could not search in datastore '%s': %s"),
|
2012-07-18 14:25:50 +00:00
|
|
|
datastoreName, taskInfoErrorMessage);
|
2010-08-07 22:24:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo) < 0 ||
|
|
|
|
esxVI_HostDatastoreBrowserSearchResults_CastListFromAnyType
|
|
|
|
(taskInfo->result, searchResultsList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&datastore);
|
|
|
|
esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
|
|
|
|
esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
|
|
|
|
VIR_FREE(datastorePath);
|
|
|
|
esxVI_ManagedObjectReference_Free(&task);
|
2010-12-06 12:53:36 +00:00
|
|
|
VIR_FREE(taskInfoErrorMessage);
|
2010-08-07 22:24:29 +00:00
|
|
|
esxVI_TaskInfo_Free(&taskInfo);
|
2013-09-03 11:16:07 +00:00
|
|
|
esxVI_VmDiskFileQuery_Free(&vmDiskFileQuery);
|
|
|
|
esxVI_IsoImageFileQuery_Free(&isoImageFileQuery);
|
|
|
|
esxVI_FloppyImageFileQuery_Free(&floppyImageFileQuery);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!key || *key) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-08-29 17:33:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (esxVI_VmDiskFileInfo_DynamicCast(fileInfo)) {
|
2010-09-03 23:30:04 +00:00
|
|
|
/* 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
|
|
|
|
2013-07-04 10:05:43 +00:00
|
|
|
if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0)
|
2010-09-03 23:30:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxUtil_ReformatUuid(uuid_string, *key) < 0)
|
2010-09-03 23:30:04 +00:00
|
|
|
goto cleanup;
|
2010-08-29 17:33:49 +00:00
|
|
|
}
|
2010-09-03 23:30:04 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*key)) {
|
2010-08-29 17:33:49 +00:00
|
|
|
/* Other files don't have a UUID, fall back to the path as key */
|
2014-11-13 14:22:20 +00:00
|
|
|
if (VIR_STRDUP(*key, datastorePath) < 0)
|
2010-08-29 17:33:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-08-29 17:33:49 +00:00
|
|
|
esxVI_FileInfo_Free(&fileInfo);
|
|
|
|
VIR_FREE(uuid_string);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-30 00:36:31 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupAutoStartDefaults(esxVI_Context *ctx,
|
|
|
|
esxVI_AutoStartDefaults **defaults)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostAutoStartManager = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!defaults || *defaults) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-12-30 00:36:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
|
|
|
|
* for some reason this is much faster than looking up the same info from
|
|
|
|
* the HostSystem config.
|
|
|
|
*/
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.defaults") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType
|
|
|
|
(ctx, ctx->hostSystem->configManager->autoStartManager,
|
|
|
|
"HostAutoStartManager", propertyNameList,
|
2010-12-30 12:30:44 +00:00
|
|
|
&hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostAutoStartManager->propSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty; dynamicProperty = dynamicProperty->_next) {
|
2010-12-30 00:36:31 +00:00
|
|
|
if (STREQ(dynamicProperty->name, "config.defaults")) {
|
|
|
|
if (esxVI_AutoStartDefaults_CastFromAnyType(dynamicProperty->val,
|
|
|
|
defaults) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*defaults)) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not retrieve the AutoStartDefaults object"));
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-12-30 00:36:31 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostAutoStartManager);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx,
|
|
|
|
esxVI_AutoStartPowerInfo **powerInfoList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostAutoStartManager = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!powerInfoList || *powerInfoList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-12-30 00:36:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
|
|
|
|
* for some reason this is much faster than looking up the same info from
|
|
|
|
* the HostSystem config.
|
|
|
|
*/
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.powerInfo") < 0 ||
|
|
|
|
esxVI_LookupObjectContentByType
|
|
|
|
(ctx, ctx->hostSystem->configManager->autoStartManager,
|
|
|
|
"HostAutoStartManager", propertyNameList,
|
2010-12-30 12:30:44 +00:00
|
|
|
&hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
|
2010-12-30 00:36:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dynamicProperty = hostAutoStartManager->propSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty; dynamicProperty = dynamicProperty->_next) {
|
2010-12-30 00:36:31 +00:00
|
|
|
if (STREQ(dynamicProperty->name, "config.powerInfo")) {
|
|
|
|
if (esxVI_AutoStartPowerInfo_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, powerInfoList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-12-30 00:36:31 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostAutoStartManager);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-04 17:48:50 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupPhysicalNicList(esxVI_Context *ctx,
|
|
|
|
esxVI_PhysicalNic **physicalNicList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!physicalNicList || *physicalNicList) {
|
2012-08-04 17:48:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.network.pnic") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-08-04 17:48:50 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.network.pnic")) {
|
|
|
|
if (esxVI_PhysicalNic_CastListFromAnyType(dynamicProperty->val,
|
|
|
|
physicalNicList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-04 17:48:50 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_PhysicalNic **physicalNic,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_PhysicalNic *physicalNicList = NULL;
|
|
|
|
esxVI_PhysicalNic *candidate = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!physicalNic || *physicalNic) {
|
2012-08-04 17:48:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0)
|
2012-08-04 17:48:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Search for a matching physical NIC */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = physicalNicList; candidate;
|
2012-08-04 17:48:50 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STRCASEEQ(candidate->device, name)) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0)
|
2012-08-04 17:48:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Found physical NIC with matching name */
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*physicalNic) && occurrence != esxVI_Occurrence_OptionalItem) {
|
2012-08-04 17:48:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("Could not find physical NIC with name '%s'"), name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-04 17:48:50 +00:00
|
|
|
esxVI_PhysicalNic_Free(&physicalNicList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
|
|
|
|
esxVI_PhysicalNic **physicalNic,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_PhysicalNic *physicalNicList = NULL;
|
|
|
|
esxVI_PhysicalNic *candidate = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!physicalNic || *physicalNic) {
|
2012-08-04 17:48:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0)
|
2012-08-04 17:48:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Search for a matching physical NIC */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = physicalNicList; candidate;
|
2012-08-04 17:48:50 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STRCASEEQ(candidate->mac, mac)) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0)
|
2012-08-04 17:48:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Found physical NIC with matching MAC address */
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*physicalNic) && occurrence != esxVI_Occurrence_OptionalItem) {
|
2012-08-04 17:48:50 +00:00
|
|
|
virReportError(VIR_ERR_NO_INTERFACE,
|
|
|
|
_("Could not find physical NIC with MAC address '%s'"), mac);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-04 17:48:50 +00:00
|
|
|
esxVI_PhysicalNic_Free(&physicalNicList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-05 20:11:50 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupHostVirtualSwitchList(esxVI_Context *ctx,
|
|
|
|
esxVI_HostVirtualSwitch **hostVirtualSwitchList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostVirtualSwitchList || *hostVirtualSwitchList) {
|
2012-08-05 20:11:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.network.vswitch") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-08-05 20:11:50 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.network.vswitch")) {
|
|
|
|
if (esxVI_HostVirtualSwitch_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, hostVirtualSwitchList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-05 20:11:50 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_HostVirtualSwitch **hostVirtualSwitch,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
|
|
|
|
esxVI_HostVirtualSwitch *candidate = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostVirtualSwitch || *hostVirtualSwitch) {
|
2012-08-05 20:11:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0)
|
2012-08-05 20:11:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Search for a matching HostVirtualSwitch */
|
2013-10-17 17:04:11 +00:00
|
|
|
for (candidate = hostVirtualSwitchList; candidate;
|
2012-08-05 20:11:50 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
if (STREQ(candidate->name, name)) {
|
|
|
|
if (esxVI_HostVirtualSwitch_DeepCopy(hostVirtualSwitch,
|
|
|
|
candidate) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Found HostVirtualSwitch with matching name */
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!(*hostVirtualSwitch) &&
|
2012-08-05 20:11:50 +00:00
|
|
|
occurrence != esxVI_Occurrence_OptionalItem) {
|
|
|
|
virReportError(VIR_ERR_NO_NETWORK,
|
|
|
|
_("Could not find HostVirtualSwitch with name '%s'"),
|
|
|
|
name);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-05 20:11:50 +00:00
|
|
|
esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupHostPortGroupList(esxVI_Context *ctx,
|
|
|
|
esxVI_HostPortGroup **hostPortGroupList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostPortGroupList || *hostPortGroupList) {
|
2012-08-05 20:11:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.network.portgroup") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-08-05 20:11:50 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.network.portgroup")) {
|
|
|
|
if (esxVI_HostPortGroup_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, hostPortGroupList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-08-05 20:11:50 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **networkList)
|
|
|
|
{
|
|
|
|
return esxVI_LookupObjectContentByType(ctx, ctx->datacenter->_reference,
|
|
|
|
"Network", propertyNameList,
|
|
|
|
networkList,
|
|
|
|
esxVI_Occurrence_OptionalList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2011-05-01 19:57:45 +00:00
|
|
|
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
|
|
|
|
bool *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;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!blocked) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-07-25 15:45:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-01 19:57:45 +00:00
|
|
|
*blocked = false;
|
2010-07-25 15:45:19 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (questionInfo->choice->choiceInfo) {
|
2009-11-15 21:22:47 +00:00
|
|
|
for (elementDescription = questionInfo->choice->choiceInfo;
|
2013-10-17 17:04:11 +00:00
|
|
|
elementDescription;
|
2009-11-15 21:22:47 +00:00
|
|
|
elementDescription = elementDescription->_next) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buffer, "'%s'", elementDescription->label);
|
2009-11-15 21:22:47 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (elementDescription->_next)
|
2009-11-15 21:22:47 +00:00
|
|
|
virBufferAddLit(&buffer, ", ");
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!answerChoice &&
|
|
|
|
questionInfo->choice->defaultIndex &&
|
2009-11-15 21:22:47 +00:00
|
|
|
questionInfo->choice->defaultIndex->value == answerIndex) {
|
|
|
|
answerChoice = elementDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
++answerIndex;
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&buffer) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-11-15 21:22:47 +00:00
|
|
|
|
|
|
|
possibleAnswers = virBufferContentAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
2011-05-01 19:57:44 +00:00
|
|
|
if (autoAnswer) {
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!possibleAnswers) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', no possible answers"),
|
|
|
|
questionInfo->text);
|
2010-07-25 15:45:19 +00:00
|
|
|
|
2011-05-01 19:57:45 +00:00
|
|
|
*blocked = true;
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2013-10-17 17:04:11 +00:00
|
|
|
} else if (!answerChoice) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', possible answers are %s, but no "
|
|
|
|
"default answer is specified"), questionInfo->text,
|
|
|
|
possibleAnswers);
|
2010-07-25 15:45:19 +00:00
|
|
|
|
2011-05-01 19:57:45 +00:00
|
|
|
*blocked = 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 {
|
2013-10-17 17:04:11 +00:00
|
|
|
if (possibleAnswers) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', possible answers are %s"),
|
|
|
|
questionInfo->text, possibleAnswers);
|
2009-11-15 21:22:47 +00:00
|
|
|
} else {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Pending question blocks virtual machine execution, "
|
|
|
|
"question is '%s', no possible answers"),
|
|
|
|
questionInfo->text);
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 19:57:45 +00:00
|
|
|
*blocked = 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;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2014-11-13 14:22:20 +00:00
|
|
|
if (result < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
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,
|
2011-05-01 19:57:44 +00:00
|
|
|
bool autoAnswer, esxVI_TaskInfoState *finalState,
|
2010-12-06 12:53:36 +00:00
|
|
|
char **errorMessage)
|
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;
|
2012-05-06 17:33:59 +00:00
|
|
|
bool objectSpec_isAppended = false;
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PropertySpec *propertySpec = NULL;
|
2012-05-06 17:33:59 +00:00
|
|
|
bool propertySpec_isAppended = false;
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2011-05-01 19:57:45 +00:00
|
|
|
bool blocked;
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_TaskInfo *taskInfo = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!errorMessage || *errorMessage) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2010-12-06 12:53:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(version, "") < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
return -1;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +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;
|
|
|
|
|
2014-11-13 14:22:20 +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,
|
2012-05-06 17:33:59 +00:00
|
|
|
propertySpec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
propertySpec_isAppended = true;
|
|
|
|
|
|
|
|
if (esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
|
|
|
|
objectSpec) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
objectSpec_isAppended = true;
|
|
|
|
|
|
|
|
if (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);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (virtualMachineUuid) {
|
2009-11-15 21:22:47 +00:00
|
|
|
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
|
|
|
|
*/
|
2014-11-13 14:22:20 +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) {
|
2011-05-01 19:57:45 +00:00
|
|
|
if (esxVI_CancelTask(ctx, task) < 0 && blocked) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("Cancelable task is blocked by an "
|
2011-12-01 23:08:34 +00:00
|
|
|
"unanswered question but cancellation "
|
2010-05-20 06:28:53 +00:00
|
|
|
"failed"));
|
2009-11-15 21:22:47 +00:00
|
|
|
}
|
2011-05-01 19:57:45 +00:00
|
|
|
} else if (blocked) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("Non-cancelable task is blocked by an "
|
2010-05-20 06:28:53 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +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);
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(version, updateSet->version) < 0)
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!updateSet->filterSet)
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (propertyFilterUpdate = updateSet->filterSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
propertyFilterUpdate;
|
2009-07-23 20:21:08 +00:00
|
|
|
propertyFilterUpdate = propertyFilterUpdate->_next) {
|
|
|
|
for (objectUpdate = propertyFilterUpdate->objectSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
objectUpdate; objectUpdate = objectUpdate->_next) {
|
2009-07-23 20:21:08 +00:00
|
|
|
for (propertyChange = objectUpdate->changeSet;
|
2013-10-17 17:04:11 +00:00
|
|
|
propertyChange;
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!propertyValue)
|
2009-07-23 20:21:08 +00:00
|
|
|
continue;
|
|
|
|
|
2014-11-13 14:22:20 +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
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_DestroyPropertyFilter(ctx, propertyFilter) < 0)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("DestroyPropertyFilter failed");
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2014-11-13 14:22:20 +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-12-06 12:53:36 +00:00
|
|
|
if (*finalState != esxVI_TaskInfoState_Success) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo))
|
2010-12-06 12:53:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!taskInfo->error) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0)
|
2010-12-06 12:53:36 +00:00
|
|
|
goto cleanup;
|
2013-10-17 17:04:11 +00:00
|
|
|
} else if (!taskInfo->error->localizedMessage) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0)
|
2010-12-06 12:53:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virAsprintf(errorMessage, "%s - %s",
|
|
|
|
taskInfo->error->fault->_actualType,
|
2013-07-04 10:05:43 +00:00
|
|
|
taskInfo->error->localizedMessage) < 0)
|
2010-12-06 12:53:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2009-07-23 20:21:08 +00:00
|
|
|
/*
|
|
|
|
* Remove values given by the caller from the data structures to prevent
|
|
|
|
* them from being freed by the call to esxVI_PropertyFilterSpec_Free().
|
|
|
|
*/
|
2014-11-13 14:22:20 +00:00
|
|
|
if (objectSpec)
|
2009-07-23 20:21:08 +00:00
|
|
|
objectSpec->obj = NULL;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (propertySpec)
|
2009-07-23 20:21:08 +00:00
|
|
|
propertySpec->type = NULL;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!objectSpec_isAppended)
|
2012-05-06 17:33:59 +00:00
|
|
|
esxVI_ObjectSpec_Free(&objectSpec);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!propertySpec_isAppended)
|
2012-05-06 17:33:59 +00:00
|
|
|
esxVI_PropertySpec_Free(&propertySpec);
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
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" };
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t r, i, o;
|
2010-04-13 22:03:12 +00:00
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(parsedHostCpuIdInfo, 0, sizeof(*parsedHostCpuIdInfo));
|
2010-04-13 22:03:12 +00:00
|
|
|
|
|
|
|
parsedHostCpuIdInfo->level = hostCpuIdInfo->level->value;
|
|
|
|
|
|
|
|
for (r = 0; r < 4; ++r) {
|
|
|
|
if (strlen(input[r]) != expectedLength) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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] != ':') {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(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;
|
|
|
|
}
|
2010-12-21 21:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
const char *
|
|
|
|
esxVI_ProductLineToDisplayName(esxVI_ProductLine productLine)
|
|
|
|
{
|
|
|
|
switch (productLine) {
|
|
|
|
case esxVI_ProductLine_GSX:
|
|
|
|
return "Server/GSX";
|
|
|
|
|
|
|
|
case esxVI_ProductLine_ESX:
|
|
|
|
return "ESX(i)";
|
|
|
|
|
|
|
|
case esxVI_ProductLine_VPX:
|
|
|
|
return "vCenter/VPX";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "<unknown>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
int
|
2014-10-18 22:11:13 +00:00
|
|
|
esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductLine productLine,
|
|
|
|
unsigned long productVersion)
|
2010-12-21 21:39:55 +00:00
|
|
|
{
|
2014-10-18 22:11:13 +00:00
|
|
|
/* product version == 1000000 * major + 1000 * minor + micro */
|
|
|
|
int major = productVersion / 1000000;
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
/*
|
|
|
|
* virtualHW.version compatibility matrix:
|
|
|
|
*
|
2014-07-16 22:25:14 +00:00
|
|
|
* 4 7 8 9 10 API
|
|
|
|
* ESX 3.5 + 2.5
|
|
|
|
* ESX 4.0 + + 4.0
|
|
|
|
* ESX 4.1 + + 4.1
|
|
|
|
* ESX 5.0 + + + 5.0
|
|
|
|
* ESX 5.1 + + + + 5.1
|
|
|
|
* ESX 5.5 + + + + + 5.5
|
|
|
|
* GSX 2.0 + + 2.5
|
2010-12-21 21:39:55 +00:00
|
|
|
*/
|
2014-10-18 22:11:13 +00:00
|
|
|
switch (productLine) {
|
|
|
|
case esxVI_ProductLine_GSX:
|
2010-12-21 21:39:55 +00:00
|
|
|
return 7;
|
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
case esxVI_ProductLine_ESX:
|
|
|
|
switch (major) {
|
|
|
|
case 3:
|
|
|
|
return 4;
|
2010-12-21 21:39:55 +00:00
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
case 4:
|
|
|
|
return 7;
|
2011-10-21 05:56:07 +00:00
|
|
|
|
2014-10-18 22:11:13 +00:00
|
|
|
case 5:
|
|
|
|
default:
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
case esxVI_ProductLine_VPX:
|
|
|
|
switch (major) {
|
|
|
|
case 2:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
return 7;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
default:
|
|
|
|
return 8;
|
|
|
|
}
|
2011-10-21 05:56:07 +00:00
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
default:
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2014-10-18 22:11:13 +00:00
|
|
|
_("Unexpected product line"));
|
2010-12-21 21:39:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 11:27:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-10 07:18:08 +00:00
|
|
|
int
|
|
|
|
esxVI_LookupHostInternetScsiHbaStaticTargetByName
|
|
|
|
(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_HostInternetScsiHbaStaticTarget **target, esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_HostInternetScsiHba *hostInternetScsiHba = NULL;
|
|
|
|
esxVI_HostInternetScsiHbaStaticTarget *candidate = NULL;
|
|
|
|
|
|
|
|
if (esxVI_LookupHostInternetScsiHba(ctx, &hostInternetScsiHba) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to obtain hostInternetScsiHba"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostInternetScsiHba) {
|
2012-11-10 07:18:08 +00:00
|
|
|
/* iSCSI adapter may not be enabled for this host */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (candidate = hostInternetScsiHba->configuredStaticTarget;
|
2013-10-17 17:04:11 +00:00
|
|
|
candidate; candidate = candidate->_next) {
|
2014-11-13 14:22:20 +00:00
|
|
|
if (STREQ(candidate->iScsiName, name))
|
2012-11-10 07:18:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!candidate) {
|
2012-11-10 07:18:08 +00:00
|
|
|
if (occurrence == esxVI_Occurrence_RequiredItem) {
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("Could not find storage pool with name: %s"), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_HostInternetScsiHbaStaticTarget_DeepCopy(target, candidate) < 0)
|
2012-11-10 07:18:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_HostInternetScsiHba_Free(&hostInternetScsiHba);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupHostInternetScsiHba(esxVI_Context *ctx,
|
|
|
|
esxVI_HostInternetScsiHba **hostInternetScsiHba)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_HostHostBusAdapter *hostHostBusAdapterList = NULL;
|
|
|
|
esxVI_HostHostBusAdapter *hostHostBusAdapter = NULL;
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList
|
|
|
|
(&propertyNameList, "config.storageDevice.hostBusAdapter") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-11-10 07:18:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name,
|
|
|
|
"config.storageDevice.hostBusAdapter")) {
|
|
|
|
if (esxVI_HostHostBusAdapter_CastListFromAnyType
|
2013-10-17 17:04:11 +00:00
|
|
|
(dynamicProperty->val, &hostHostBusAdapterList) < 0 ||
|
|
|
|
!hostHostBusAdapterList) {
|
2012-11-10 07:18:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See vSphere API documentation about HostInternetScsiHba for details */
|
|
|
|
for (hostHostBusAdapter = hostHostBusAdapterList;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostHostBusAdapter;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostHostBusAdapter = hostHostBusAdapter->_next) {
|
2014-01-20 11:27:29 +00:00
|
|
|
esxVI_HostInternetScsiHba *candidate =
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_HostInternetScsiHba_DynamicCast(hostHostBusAdapter);
|
|
|
|
|
|
|
|
if (candidate) {
|
|
|
|
if (esxVI_HostInternetScsiHba_DeepCopy(hostInternetScsiHba,
|
|
|
|
candidate) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_HostHostBusAdapter_Free(&hostHostBusAdapterList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupScsiLunList(esxVI_Context *ctx, esxVI_ScsiLun **scsiLunList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty;
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList(&propertyNameList,
|
|
|
|
"config.storageDevice.scsiLun") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-11-10 07:18:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name, "config.storageDevice.scsiLun")) {
|
|
|
|
if (esxVI_ScsiLun_CastListFromAnyType(dynamicProperty->val,
|
|
|
|
scsiLunList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupHostScsiTopologyLunListByTargetName
|
|
|
|
(esxVI_Context *ctx, const char *name,
|
|
|
|
esxVI_HostScsiTopologyLun **hostScsiTopologyLunList)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_HostScsiTopologyInterface *hostScsiInterfaceList = NULL;
|
|
|
|
esxVI_HostScsiTopologyInterface *hostScsiInterface = NULL;
|
|
|
|
esxVI_HostScsiTopologyTarget *hostScsiTopologyTarget = NULL;
|
|
|
|
bool found = false;
|
|
|
|
esxVI_HostInternetScsiTargetTransport *candidate = NULL;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostScsiTopologyLunList || *hostScsiTopologyLunList) {
|
2012-11-10 07:18:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList
|
|
|
|
(&propertyNameList,
|
|
|
|
"config.storageDevice.scsiTopology.adapter") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-11-10 07:18:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name,
|
|
|
|
"config.storageDevice.scsiTopology.adapter")) {
|
|
|
|
esxVI_HostScsiTopologyInterface_Free(&hostScsiInterfaceList);
|
|
|
|
|
|
|
|
if (esxVI_HostScsiTopologyInterface_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, &hostScsiInterfaceList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostScsiInterfaceList == NULL) {
|
|
|
|
/* iSCSI adapter may not be enabled */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See vSphere API documentation about HostScsiTopologyInterface */
|
|
|
|
for (hostScsiInterface = hostScsiInterfaceList;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostScsiInterface && !found;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostScsiInterface = hostScsiInterface->_next) {
|
|
|
|
for (hostScsiTopologyTarget = hostScsiInterface->target;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostScsiTopologyTarget;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostScsiTopologyTarget = hostScsiTopologyTarget->_next) {
|
|
|
|
candidate = esxVI_HostInternetScsiTargetTransport_DynamicCast
|
|
|
|
(hostScsiTopologyTarget->transport);
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (candidate && STREQ(candidate->iScsiName, name)) {
|
2012-11-10 07:18:08 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (!found || !hostScsiTopologyTarget)
|
2012-11-10 07:18:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostScsiTopologyTarget->lun) {
|
2012-11-10 07:18:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Target not found"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_HostScsiTopologyLun_DeepCopyList(hostScsiTopologyLunList,
|
|
|
|
hostScsiTopologyTarget->lun) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_HostScsiTopologyInterface_Free(&hostScsiInterfaceList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx,
|
|
|
|
const char *key,
|
|
|
|
char **poolName)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL;
|
|
|
|
esxVI_ObjectContent *hostSystem = NULL;
|
|
|
|
esxVI_String *propertyNameList = NULL;
|
|
|
|
esxVI_HostScsiTopologyInterface *hostScsiInterfaceList = NULL;
|
|
|
|
esxVI_HostScsiTopologyInterface *hostScsiInterface = NULL;
|
|
|
|
esxVI_HostScsiTopologyTarget *hostScsiTopologyTarget = NULL;
|
|
|
|
esxVI_HostInternetScsiTargetTransport *candidate;
|
|
|
|
esxVI_HostScsiTopologyLun *hostScsiTopologyLun;
|
|
|
|
bool found = false;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!poolName || *poolName) {
|
2012-11-10 07:18:08 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_String_AppendValueToList
|
|
|
|
(&propertyNameList,
|
|
|
|
"config.storageDevice.scsiTopology.adapter") < 0 ||
|
|
|
|
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
|
|
|
|
&hostSystem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
for (dynamicProperty = hostSystem->propSet; dynamicProperty;
|
2012-11-10 07:18:08 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) {
|
|
|
|
if (STREQ(dynamicProperty->name,
|
|
|
|
"config.storageDevice.scsiTopology.adapter")) {
|
|
|
|
esxVI_HostScsiTopologyInterface_Free(&hostScsiInterfaceList);
|
|
|
|
|
|
|
|
if (esxVI_HostScsiTopologyInterface_CastListFromAnyType
|
|
|
|
(dynamicProperty->val, &hostScsiInterfaceList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!hostScsiInterfaceList) {
|
2012-11-10 07:18:08 +00:00
|
|
|
/* iSCSI adapter may not be enabled */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See vSphere API documentation about HostScsiTopologyInterface */
|
|
|
|
for (hostScsiInterface = hostScsiInterfaceList;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostScsiInterface && !found;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostScsiInterface = hostScsiInterface->_next) {
|
|
|
|
for (hostScsiTopologyTarget = hostScsiInterface->target;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostScsiTopologyTarget;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostScsiTopologyTarget = hostScsiTopologyTarget->_next) {
|
|
|
|
candidate = esxVI_HostInternetScsiTargetTransport_DynamicCast
|
2013-05-03 12:41:53 +00:00
|
|
|
(hostScsiTopologyTarget->transport);
|
2012-11-10 07:18:08 +00:00
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (candidate) {
|
2012-11-10 07:18:08 +00:00
|
|
|
/* iterate hostScsiTopologyLun list to find matching key */
|
|
|
|
for (hostScsiTopologyLun = hostScsiTopologyTarget->lun;
|
2013-10-17 17:04:11 +00:00
|
|
|
hostScsiTopologyLun;
|
2012-11-10 07:18:08 +00:00
|
|
|
hostScsiTopologyLun = hostScsiTopologyLun->_next) {
|
2013-05-03 12:41:53 +00:00
|
|
|
if (STREQ(hostScsiTopologyLun->scsiLun, key) &&
|
|
|
|
VIR_STRDUP(*poolName, candidate->iScsiName) < 0)
|
|
|
|
goto cleanup;
|
2012-11-10 07:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* hostScsiTopologyLun iteration done, terminate loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2012-11-10 07:18:08 +00:00
|
|
|
esxVI_ObjectContent_Free(&hostSystem);
|
|
|
|
esxVI_String_Free(&propertyNameList);
|
|
|
|
esxVI_HostScsiTopologyInterface_Free(&hostScsiInterfaceList);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-10 11:27:56 +00:00
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE_IGNORE(_name) \
|
|
|
|
if (STREQ(dynamicProperty->name, #_name)) { \
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__PROPERTY__CAST_FROM_ANY_TYPE(_type, _name) \
|
|
|
|
if (STREQ(dynamicProperty->name, #_name)) { \
|
|
|
|
if (esxVI_##_type##_CastFromAnyType(dynamicProperty->val, \
|
|
|
|
&(*ptrptr)->_name) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__PROPERTY__CAST_LIST_FROM_ANY_TYPE(_type, _name) \
|
|
|
|
if (STREQ(dynamicProperty->name, #_name)) { \
|
|
|
|
if (esxVI_##_type##_CastListFromAnyType(dynamicProperty->val, \
|
|
|
|
&(*ptrptr)->_name) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__PROPERTY__CAST_VALUE_FROM_ANY_TYPE(_type, _name) \
|
|
|
|
if (STREQ(dynamicProperty->name, #_name)) { \
|
|
|
|
if (esxVI_##_type##_CastValueFromAnyType(dynamicProperty->val, \
|
|
|
|
&(*ptrptr)->_name) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__TEMPLATE__LOOKUP(_type, _complete_properties, \
|
2011-09-06 17:05:08 +00:00
|
|
|
_cast_from_anytype) \
|
2011-04-10 11:27:56 +00:00
|
|
|
int \
|
|
|
|
esxVI_Lookup##_type(esxVI_Context *ctx, const char* name /* optional */, \
|
|
|
|
esxVI_ManagedObjectReference *root, \
|
|
|
|
esxVI_String *selectedPropertyNameList /* optional */,\
|
|
|
|
esxVI_##_type **ptrptr, esxVI_Occurrence occurrence) \
|
|
|
|
{ \
|
|
|
|
int result = -1; \
|
|
|
|
const char *completePropertyNameValueList = _complete_properties; \
|
|
|
|
esxVI_String *propertyNameList = NULL; \
|
|
|
|
esxVI_ObjectContent *objectContent = NULL; \
|
|
|
|
esxVI_ObjectContent *objectContentList = NULL; \
|
|
|
|
esxVI_DynamicProperty *dynamicProperty = NULL; \
|
|
|
|
\
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!ptrptr || *ptrptr) { \
|
2012-08-05 11:47:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
|
|
|
_("Invalid argument")); \
|
2011-04-10 11:27:56 +00:00
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
propertyNameList = selectedPropertyNameList; \
|
|
|
|
\
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!propertyNameList && \
|
2011-04-10 11:27:56 +00:00
|
|
|
esxVI_String_AppendValueListToList \
|
|
|
|
(&propertyNameList, completePropertyNameValueList) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (esxVI_LookupManagedObjectHelper(ctx, name, root, #_type, \
|
|
|
|
propertyNameList, &objectContent, \
|
|
|
|
&objectContentList, \
|
|
|
|
occurrence) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!objectContent) { \
|
2011-09-06 17:05:08 +00:00
|
|
|
/* not found, exit early */ \
|
|
|
|
result = 0; \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
2011-04-10 11:27:56 +00:00
|
|
|
if (esxVI_##_type##_Alloc(ptrptr) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (esxVI_ManagedObjectReference_DeepCopy(&(*ptrptr)->_reference, \
|
|
|
|
objectContent->obj) < 0) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
for (dynamicProperty = objectContent->propSet; \
|
2013-10-17 17:04:11 +00:00
|
|
|
dynamicProperty; \
|
2011-04-10 11:27:56 +00:00
|
|
|
dynamicProperty = dynamicProperty->_next) { \
|
|
|
|
_cast_from_anytype \
|
|
|
|
\
|
|
|
|
VIR_WARN("Unexpected '%s' property", dynamicProperty->name); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (esxVI_##_type##_Validate(*ptrptr, selectedPropertyNameList) < 0) {\
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
result = 0; \
|
|
|
|
\
|
|
|
|
cleanup: \
|
|
|
|
if (result < 0) { \
|
|
|
|
esxVI_##_type##_Free(ptrptr); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (propertyNameList != selectedPropertyNameList) { \
|
|
|
|
esxVI_String_Free(&propertyNameList); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
esxVI_ObjectContent_Free(&objectContentList); \
|
|
|
|
\
|
|
|
|
return result; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxVI_LookupManagedObjectHelper(esxVI_Context *ctx,
|
|
|
|
const char *name /* optional */,
|
|
|
|
esxVI_ManagedObjectReference *root,
|
|
|
|
const char *type,
|
|
|
|
esxVI_String *propertyNameList,
|
|
|
|
esxVI_ObjectContent **objectContent,
|
|
|
|
esxVI_ObjectContent **objectContentList,
|
|
|
|
esxVI_Occurrence occurrence)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
esxVI_ObjectContent *candidate = NULL;
|
|
|
|
char *name_candidate;
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!objectContent || *objectContent ||
|
|
|
|
!objectContentList || *objectContentList) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
2011-04-10 11:27:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!esxVI_String_ListContainsValue(propertyNameList, "name")) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing 'name' property in %s lookup"), type);
|
2011-04-10 11:27:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_LookupObjectContentByType(ctx, root, type, propertyNameList,
|
|
|
|
objectContentList,
|
|
|
|
esxVI_Occurrence_OptionalList) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for a matching item */
|
2013-10-17 17:04:11 +00:00
|
|
|
if (name) {
|
|
|
|
for (candidate = *objectContentList; candidate;
|
2011-04-10 11:27:56 +00:00
|
|
|
candidate = candidate->_next) {
|
|
|
|
name_candidate = NULL;
|
|
|
|
|
|
|
|
if (esxVI_GetStringValue(candidate, "name", &name_candidate,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(name_candidate, name)) {
|
|
|
|
/* Found item with matching name */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
candidate = *objectContentList;
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:04:11 +00:00
|
|
|
if (!candidate) {
|
2011-04-10 11:27:56 +00:00
|
|
|
if (occurrence != esxVI_Occurrence_OptionalItem) {
|
2013-10-17 17:04:11 +00:00
|
|
|
if (name) {
|
2013-05-15 21:43:04 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find %s with name '%s'"), type, name);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find %s"), type);
|
|
|
|
}
|
|
|
|
|
2011-04-10 11:27:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2011-04-10 11:27:56 +00:00
|
|
|
if (result < 0) {
|
|
|
|
esxVI_ObjectContent_Free(objectContentList);
|
|
|
|
} else {
|
|
|
|
*objectContent = candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "esx_vi.generated.c"
|