libvirt/src/esx/esx_vi_methods.c

1342 lines
39 KiB
C
Raw Normal View History

/*
* esx_vi_methods.c: client for the VMware VI API 2.5 to manage ESX hosts
*
build: consistently use C99 varargs macros Prior to this patch, there was an inconsistent mix between GNU and C99. For consistency, and potential portability to other compilers, stick with the C99 vararg macro syntax. * src/conf/cpu_conf.c (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/conf/domain_conf.c (virDomainReportError): Likewise. * src/conf/domain_event.c (eventReportError): Likewise. * src/conf/interface_conf.c (virInterfaceReportError): Likewise. * src/conf/network_conf.c (virNetworkReportError): Likewise. * src/conf/node_device_conf.h (virNodeDeviceReportError): Likewise. * src/conf/secret_conf.h (virSecretReportError): Likewise. * src/conf/storage_conf.h (virStorageReportError): Likewise. * src/esx/esx_device_monitor.c (ESX_ERROR): Use C99 rather than GNU vararg macro syntax. * src/esx/esx_driver.c (ESX_ERROR): Likewise. * src/esx/esx_interface_driver.c (ESX_ERROR): Likewise. * src/esx/esx_network_driver.c (ESX_ERROR): Likewise. * src/esx/esx_secret_driver.c (ESX_ERROR): Likewise. * src/esx/esx_storage_driver.c (ESX_ERROR): Likewise. * src/esx/esx_util.c (ESX_ERROR): Likewise. * src/esx/esx_vi.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_methods.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_types.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vmx.c (ESX_ERROR): Likewise. * src/util/hostusb.c (usbReportError): Use C99 rather than GNU vararg macro syntax. * src/util/json.c (virJSONError): Likewise. * src/util/macvtap.c (ReportError): Likewise. * src/util/pci.c (pciReportError): Likewise. * src/util/stats_linux.c (virStatsError): Likewise. * src/util/util.c (virUtilError): Likewise. * src/util/xml.c (virXMLError): Likewise. * src/xen/proxy_internal.c (virProxyError): Use C99 rather than GNU vararg macro syntax. * src/xen/sexpr.c (virSexprError): Likewise. * src/xen/xen_driver.c (xenUnifiedError): Likewise. * src/xen/xen_hypervisor.c (virXenError): Likewise. * src/xen/xen_inotify.c (virXenInotifyError): Likewise. * src/xen/xend_internal.c (virXendError): Likewise. * src/xen/xm_internal.c (xenXMError): Likewise. * src/xen/xs_internal.c (virXenStoreError): Likewise. * src/cpu/cpu.h (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/datatypes.c (virLibConnError): Likewise. * src/interface/netcf_driver.c (interfaceReportError): Likewise. * src/libvirt.c (virLibStreamError): Likewise. * src/lxc/lxc_conf.h (lxcError): Likewise. * src/network/bridge_driver.c (networkReportError): Likewise. * src/nodeinfo.c (nodeReportError): Likewise. * src/opennebula/one_conf.h (oneError): Likewise. * src/openvz/openvz_conf.h (openvzError): Likewise. * src/phyp/phyp_driver.c (PHYP_ERROR): Likewise. * src/qemu/qemu_conf.h (qemuReportError): Likewise. * src/remote/remote_driver.c (errorf): Likewise. * src/security/security_driver.h (virSecurityReportError): Likewise. * src/test/test_driver.c (testError): Likewise. * src/uml/uml_conf.h (umlReportError): Likewise. * src/vbox/vbox_driver.c (vboxError): Likewise. * src/vbox/vbox_tmpl.c (vboxError): Likewise.
2010-03-01 23:38:28 +00:00
* Copyright (C) 2010 Red Hat, Inc.
* Copyright (C) 2009 Matthias Bolte <matthias.bolte@googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#include "buf.h"
#include "memory.h"
#include "logging.h"
#include "uuid.h"
#include "virterror_internal.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
#define VIR_FROM_THIS VIR_FROM_ESX
build: consistently use C99 varargs macros Prior to this patch, there was an inconsistent mix between GNU and C99. For consistency, and potential portability to other compilers, stick with the C99 vararg macro syntax. * src/conf/cpu_conf.c (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/conf/domain_conf.c (virDomainReportError): Likewise. * src/conf/domain_event.c (eventReportError): Likewise. * src/conf/interface_conf.c (virInterfaceReportError): Likewise. * src/conf/network_conf.c (virNetworkReportError): Likewise. * src/conf/node_device_conf.h (virNodeDeviceReportError): Likewise. * src/conf/secret_conf.h (virSecretReportError): Likewise. * src/conf/storage_conf.h (virStorageReportError): Likewise. * src/esx/esx_device_monitor.c (ESX_ERROR): Use C99 rather than GNU vararg macro syntax. * src/esx/esx_driver.c (ESX_ERROR): Likewise. * src/esx/esx_interface_driver.c (ESX_ERROR): Likewise. * src/esx/esx_network_driver.c (ESX_ERROR): Likewise. * src/esx/esx_secret_driver.c (ESX_ERROR): Likewise. * src/esx/esx_storage_driver.c (ESX_ERROR): Likewise. * src/esx/esx_util.c (ESX_ERROR): Likewise. * src/esx/esx_vi.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_methods.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_types.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vmx.c (ESX_ERROR): Likewise. * src/util/hostusb.c (usbReportError): Use C99 rather than GNU vararg macro syntax. * src/util/json.c (virJSONError): Likewise. * src/util/macvtap.c (ReportError): Likewise. * src/util/pci.c (pciReportError): Likewise. * src/util/stats_linux.c (virStatsError): Likewise. * src/util/util.c (virUtilError): Likewise. * src/util/xml.c (virXMLError): Likewise. * src/xen/proxy_internal.c (virProxyError): Use C99 rather than GNU vararg macro syntax. * src/xen/sexpr.c (virSexprError): Likewise. * src/xen/xen_driver.c (xenUnifiedError): Likewise. * src/xen/xen_hypervisor.c (virXenError): Likewise. * src/xen/xen_inotify.c (virXenInotifyError): Likewise. * src/xen/xend_internal.c (virXendError): Likewise. * src/xen/xm_internal.c (xenXMError): Likewise. * src/xen/xs_internal.c (virXenStoreError): Likewise. * src/cpu/cpu.h (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/datatypes.c (virLibConnError): Likewise. * src/interface/netcf_driver.c (interfaceReportError): Likewise. * src/libvirt.c (virLibStreamError): Likewise. * src/lxc/lxc_conf.h (lxcError): Likewise. * src/network/bridge_driver.c (networkReportError): Likewise. * src/nodeinfo.c (nodeReportError): Likewise. * src/opennebula/one_conf.h (oneError): Likewise. * src/openvz/openvz_conf.h (openvzError): Likewise. * src/phyp/phyp_driver.c (PHYP_ERROR): Likewise. * src/qemu/qemu_conf.h (qemuReportError): Likewise. * src/remote/remote_driver.c (errorf): Likewise. * src/security/security_driver.h (virSecurityReportError): Likewise. * src/test/test_driver.c (testError): Likewise. * src/uml/uml_conf.h (umlReportError): Likewise. * src/vbox/vbox_driver.c (vboxError): Likewise. * src/vbox/vbox_tmpl.c (vboxError): Likewise.
2010-03-01 23:38:28 +00:00
#define ESX_VI_ERROR(code, ...) \
virReportErrorHelper(NULL, VIR_FROM_ESX, code, __FILE__, __FUNCTION__, \
build: consistently use C99 varargs macros Prior to this patch, there was an inconsistent mix between GNU and C99. For consistency, and potential portability to other compilers, stick with the C99 vararg macro syntax. * src/conf/cpu_conf.c (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/conf/domain_conf.c (virDomainReportError): Likewise. * src/conf/domain_event.c (eventReportError): Likewise. * src/conf/interface_conf.c (virInterfaceReportError): Likewise. * src/conf/network_conf.c (virNetworkReportError): Likewise. * src/conf/node_device_conf.h (virNodeDeviceReportError): Likewise. * src/conf/secret_conf.h (virSecretReportError): Likewise. * src/conf/storage_conf.h (virStorageReportError): Likewise. * src/esx/esx_device_monitor.c (ESX_ERROR): Use C99 rather than GNU vararg macro syntax. * src/esx/esx_driver.c (ESX_ERROR): Likewise. * src/esx/esx_interface_driver.c (ESX_ERROR): Likewise. * src/esx/esx_network_driver.c (ESX_ERROR): Likewise. * src/esx/esx_secret_driver.c (ESX_ERROR): Likewise. * src/esx/esx_storage_driver.c (ESX_ERROR): Likewise. * src/esx/esx_util.c (ESX_ERROR): Likewise. * src/esx/esx_vi.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_methods.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vi_types.c (ESX_VI_ERROR): Likewise. * src/esx/esx_vmx.c (ESX_ERROR): Likewise. * src/util/hostusb.c (usbReportError): Use C99 rather than GNU vararg macro syntax. * src/util/json.c (virJSONError): Likewise. * src/util/macvtap.c (ReportError): Likewise. * src/util/pci.c (pciReportError): Likewise. * src/util/stats_linux.c (virStatsError): Likewise. * src/util/util.c (virUtilError): Likewise. * src/util/xml.c (virXMLError): Likewise. * src/xen/proxy_internal.c (virProxyError): Use C99 rather than GNU vararg macro syntax. * src/xen/sexpr.c (virSexprError): Likewise. * src/xen/xen_driver.c (xenUnifiedError): Likewise. * src/xen/xen_hypervisor.c (virXenError): Likewise. * src/xen/xen_inotify.c (virXenInotifyError): Likewise. * src/xen/xend_internal.c (virXendError): Likewise. * src/xen/xm_internal.c (xenXMError): Likewise. * src/xen/xs_internal.c (virXenStoreError): Likewise. * src/cpu/cpu.h (virCPUReportError): Use C99 rather than GNU vararg macro syntax. * src/datatypes.c (virLibConnError): Likewise. * src/interface/netcf_driver.c (interfaceReportError): Likewise. * src/libvirt.c (virLibStreamError): Likewise. * src/lxc/lxc_conf.h (lxcError): Likewise. * src/network/bridge_driver.c (networkReportError): Likewise. * src/nodeinfo.c (nodeReportError): Likewise. * src/opennebula/one_conf.h (oneError): Likewise. * src/openvz/openvz_conf.h (openvzError): Likewise. * src/phyp/phyp_driver.c (PHYP_ERROR): Likewise. * src/qemu/qemu_conf.h (qemuReportError): Likewise. * src/remote/remote_driver.c (errorf): Likewise. * src/security/security_driver.h (virSecurityReportError): Likewise. * src/test/test_driver.c (testError): Likewise. * src/uml/uml_conf.h (umlReportError): Likewise. * src/vbox/vbox_driver.c (vboxError): Likewise. * src/vbox/vbox_tmpl.c (vboxError): Likewise.
2010-03-01 23:38:28 +00:00
__LINE__, __VA_ARGS__)
#define ESX_VI__SOAP__REQUEST_HEADER \
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
"<soapenv:Envelope " \
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " \
"xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " \
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " \
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" \
"<soapenv:Body>"
#define ESX_VI__SOAP__REQUEST_FOOTER \
"</soapenv:Body>" \
"</soapenv:Envelope>"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Methods
*/
int
esxVI_RetrieveServiceContent(esxVI_Context *ctx,
esxVI_ServiceContent **serviceContent)
{
int result = 0;
const char *request = ESX_VI__SOAP__REQUEST_HEADER
"<RetrieveServiceContent xmlns=\"urn:vim25\">"
"<_this xmlns=\"urn:vim25\" "
"xsi:type=\"ManagedObjectReference\" "
"type=\"ServiceInstance\">"
"ServiceInstance"
"</_this>"
"</RetrieveServiceContent>"
ESX_VI__SOAP__REQUEST_FOOTER;
esxVI_Response *response = NULL;
if (serviceContent == NULL || *serviceContent != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
if (esxVI_Context_Execute(ctx, "RetrieveServiceContent", request,
&response, esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_ServiceContent_Deserialize(response->node, serviceContent) < 0) {
goto failure;
}
cleanup:
esxVI_Response_Free(&response);
return result;
failure:
result = -1;
goto cleanup;
}
int
esxVI_Login(esxVI_Context *ctx, const char *userName, const char *password,
esxVI_UserSession **userSession)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (userSession == NULL || *userSession != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<Login xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(userName, "userName", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(password, "password", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</Login>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "Login", request, &response,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_UserSession_Deserialize(response->node, userSession) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_Logout(esxVI_Context *ctx)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<Logout xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
"_this", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</Logout>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "Logout", request, &response,
esxVI_Occurrence_None) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_SessionIsActive(esxVI_Context *ctx, const char *sessionID,
const char *userName, esxVI_Boolean *active)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (active == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<SessionIsActive xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(sessionID, "sessionID", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(userName, "userName", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</SessionIsActive>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "SessionIsActive", request, &response,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_Boolean_Deserialize(response->node, active) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_RetrieveProperties(esxVI_Context *ctx,
esxVI_PropertyFilterSpec *propertyFilterSpecList,
esxVI_ObjectContent **objectContentList)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (objectContentList == NULL || *objectContentList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<RetrieveProperties xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_PropertyFilterSpec_SerializeList(propertyFilterSpecList,
"specSet", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</RetrieveProperties>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "RetrieveProperties", request, &response,
esxVI_Occurrence_List) < 0 ||
esxVI_ObjectContent_DeserializeList(response->node,
objectContentList) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_PowerOnVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task)
{
return esxVI_StartSimpleVirtualMachineTask(ctx, "PowerOnVM",
virtualMachine, task);
}
int
esxVI_PowerOffVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task)
{
return esxVI_StartSimpleVirtualMachineTask(ctx, "PowerOffVM",
virtualMachine, task);
}
int
esxVI_SuspendVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference **task)
{
return esxVI_StartSimpleVirtualMachineTask(ctx, "SuspendVM",
virtualMachine, task);
}
int
esxVI_MigrateVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_ManagedObjectReference *resourcePool,
esxVI_ManagedObjectReference *hostSystem,
esxVI_ManagedObjectReference **task)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
if (task == NULL || *task != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<MigrateVM_Task xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_VirtualMachineMovePriority_Serialize
(esxVI_VirtualMachineMovePriority_DefaultPriority, "priority",
&buffer, esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</MigrateVM_Task>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_StartVirtualMachineTask(ctx, "MigrateVM", request, task) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_ReconfigVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineConfigSpec *spec,
esxVI_ManagedObjectReference **task)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
if (task == NULL || *task != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<ReconfigVM_Task xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_VirtualMachineConfigSpec_Serialize(spec, "spec", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</ReconfigVM_Task>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_StartVirtualMachineTask(ctx, "ReconfigVM", request, task) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_RegisterVM_Task(esxVI_Context *ctx,
esxVI_ManagedObjectReference *folder,
const char *path, const char *name,
esxVI_Boolean asTemplate,
esxVI_ManagedObjectReference *resourcePool,
esxVI_ManagedObjectReference *hostSystem,
esxVI_ManagedObjectReference **task)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
if (task == NULL || *task != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<RegisterVM_Task xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(folder, "_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(path, "path", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(name, "name", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_Boolean_Serialize(asTemplate, "asTemplate", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
esxVI_Boolean_False) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</RegisterVM_Task>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_StartVirtualMachineTask(ctx, "RegisterVM", request, task) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_CancelTask(esxVI_Context *ctx, esxVI_ManagedObjectReference *task)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<CancelTask xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(task, "_this", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</CancelTask>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "CancelTask", request, &response,
esxVI_Occurrence_None) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1;
goto cleanup;
}
int
esxVI_UnregisterVM(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<UnregisterVM xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</UnregisterVM>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "UnregisterVM", request, &response,
esxVI_Occurrence_None) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_AnswerVM(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine,
const char *questionId, const char *answerChoice)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<AnswerVM xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(questionId, "questionId", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(answerChoice, "answerChoice", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</AnswerVM>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, request, NULL, &response,
esxVI_Boolean_False) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1;
goto cleanup;
}
int
esxVI_CreateFilter(esxVI_Context *ctx,
esxVI_PropertyFilterSpec *propertyFilterSpec,
esxVI_Boolean partialUpdates,
esxVI_ManagedObjectReference **propertyFilter)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (propertyFilter == NULL || *propertyFilter != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<CreateFilter xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_PropertyFilterSpec_Serialize(propertyFilterSpec, "spec", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_Boolean_Serialize(partialUpdates, "partialUpdates", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</CreateFilter>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "CreateFilter", request, &response,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_ManagedObjectReference_Deserialize(response->node, propertyFilter,
"PropertyFilter") < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_DestroyPropertyFilter(esxVI_Context *ctx,
esxVI_ManagedObjectReference *propertyFilter)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<DestroyPropertyFilter xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(propertyFilter, "_this", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</DestroyPropertyFilter>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "DestroyPropertyFilter", request,
&response, esxVI_Occurrence_None) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_WaitForUpdates(esxVI_Context *ctx, const char *version,
esxVI_UpdateSet **updateSet)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (updateSet == NULL || *updateSet != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<WaitForUpdates xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_String_SerializeValue(version, "version", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</WaitForUpdates>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "WaitForUpdates", request,
&response, esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_UpdateSet_Deserialize(response->node, updateSet) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_RebootGuest(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine)
{
return esxVI_SimpleVirtualMachineMethod(ctx, "RebootGuest", virtualMachine);
}
int
esxVI_ShutdownGuest(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachine)
{
return esxVI_SimpleVirtualMachineMethod(ctx, "ShutdownGuest",
virtualMachine);
}
int
esxVI_ValidateMigration(esxVI_Context *ctx,
esxVI_ManagedObjectReference *virtualMachineList,
esxVI_VirtualMachinePowerState powerState,
esxVI_String *testTypeList,
esxVI_ManagedObjectReference *resourcePool,
esxVI_ManagedObjectReference *hostSystem,
esxVI_Event **eventList)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (eventList == NULL || *eventList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<ValidateMigration xmlns=\"urn:vim25\">"
"<_this xmlns=\"urn:vim25\" "
"xsi:type=\"ManagedObjectReference\" "
"type=\"ServiceInstance\">"
"ServiceInstance"
"</_this>");
if (esxVI_ManagedObjectReference_SerializeList(virtualMachineList, "vm",
&buffer,
esxVI_Boolean_True) < 0 ||
esxVI_VirtualMachinePowerState_Serialize(powerState, "state", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_String_SerializeList(testTypeList, "testType", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</ValidateMigration>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "ValidateMigration", request, &response,
esxVI_Occurrence_List) < 0 ||
esxVI_Event_DeserializeList(response->node, eventList) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_FindByIp(esxVI_Context *ctx,
esxVI_ManagedObjectReference *datacenter,
const char *ip, esxVI_Boolean vmSearch,
esxVI_ManagedObjectReference **managedObjectReference)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (managedObjectReference == NULL || *managedObjectReference != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<FindByIp xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->searchIndex,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(datacenter, "datacenter",
&buffer,
esxVI_Boolean_False) < 0 ||
esxVI_String_SerializeValue(ip, "ip", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_Boolean_Serialize(vmSearch, "vmSearch", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</FindByIp>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "FindByIp", request, &response,
esxVI_Occurrence_OptionalItem) < 0 ||
esxVI_ManagedObjectReference_Deserialize
(response->node, managedObjectReference,
vmSearch == esxVI_Boolean_True ? "VirtualMachine"
: "HostSystem") < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_FindByUuid(esxVI_Context *ctx,
esxVI_ManagedObjectReference *datacenter,
const unsigned char *uuid, esxVI_Boolean vmSearch,
esxVI_ManagedObjectReference **managedObjectReference)
{
int result = 0;
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (managedObjectReference == NULL || *managedObjectReference != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virUUIDFormat(uuid, uuid_string);
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<FindByUuid xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->searchIndex,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(datacenter, "datacenter",
&buffer,
esxVI_Boolean_False) < 0 ||
esxVI_String_SerializeValue(uuid_string, "uuid", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_Boolean_Serialize(vmSearch, "vmSearch", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</FindByUuid>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "FindByUuid", request, &response,
esxVI_Occurrence_OptionalItem) < 0) {
goto failure;
}
if (response->node == NULL) {
goto cleanup;
}
if (esxVI_ManagedObjectReference_Deserialize
(response->node, managedObjectReference,
vmSearch == esxVI_Boolean_True ? "VirtualMachine"
: "HostSystem") < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_QueryAvailablePerfMetric(esxVI_Context *ctx,
esxVI_ManagedObjectReference *entity,
esxVI_DateTime *beginTime,
esxVI_DateTime *endTime, esxVI_Int *intervalId,
esxVI_PerfMetricId **perfMetricIdList)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (perfMetricIdList == NULL || *perfMetricIdList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryAvailablePerfMetric xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(entity, "entity", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_DateTime_Serialize(beginTime, "beginTime", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_DateTime_Serialize(endTime, "endTime", &buffer,
esxVI_Boolean_False) < 0 ||
esxVI_Int_Serialize(intervalId, "intervalId", &buffer,
esxVI_Boolean_False) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</QueryAvailablePerfMetric>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "QueryAvailablePerfMetric", request,
&response, esxVI_Occurrence_List) < 0 ||
esxVI_PerfMetricId_DeserializeList(response->node,
perfMetricIdList) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_QueryPerfCounter(esxVI_Context *ctx, esxVI_Int *counterIdList,
esxVI_PerfCounterInfo **perfCounterInfoList)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (perfCounterInfoList == NULL || *perfCounterInfoList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryPerfCounter xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_Int_SerializeList(counterIdList, "counterId", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</QueryPerfCounter>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "QueryPerfCounter", request, &response,
esxVI_Occurrence_List) < 0 ||
esxVI_PerfCounterInfo_DeserializeList(response->node,
perfCounterInfoList) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}
int
esxVI_QueryPerf(esxVI_Context *ctx, esxVI_PerfQuerySpec *querySpecList,
esxVI_PerfEntityMetric **perfEntityMetricList)
{
int result = 0;
virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
return -1;
}
if (perfEntityMetricList == NULL || *perfEntityMetricList != NULL) {
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1;
}
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryPerf xmlns=\"urn:vim25\">");
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
"_this", &buffer,
esxVI_Boolean_True) < 0 ||
esxVI_PerfQuerySpec_SerializeList(querySpecList, "querySpec", &buffer,
esxVI_Boolean_True) < 0) {
goto failure;
}
virBufferAddLit(&buffer, "</QueryPerf>");
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
if (virBufferError(&buffer)) {
virReportOOMError();
goto failure;
}
request = virBufferContentAndReset(&buffer);
if (esxVI_Context_Execute(ctx, "QueryPerf", request, &response,
esxVI_Occurrence_List) < 0 ||
esxVI_PerfEntityMetric_DeserializeList(response->node,
perfEntityMetricList) < 0) {
goto failure;
}
cleanup:
VIR_FREE(request);
esxVI_Response_Free(&response);
return result;
failure:
virBufferFreeAndReset(&buffer);
result = -1;
goto cleanup;
}