2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* esx_vi_methods.c: client for the VMware VI API 2.5 to manage ESX hosts
|
|
|
|
*
|
2010-03-01 23:38:28 +00:00
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
2009-07-23 20:21:08 +00:00
|
|
|
* 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
|
|
|
|
|
2010-03-01 23:38:28 +00:00
|
|
|
#define ESX_VI_ERROR(code, ...) \
|
2010-01-15 22:05:26 +00:00
|
|
|
virReportErrorHelper(NULL, VIR_FROM_ESX, code, __FILE__, __FUNCTION__, \
|
2010-03-01 23:38:28 +00:00
|
|
|
__LINE__, __VA_ARGS__)
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
#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
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_RetrieveServiceContent(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ServiceContent **serviceContent)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2009-09-04 16:24:25 +00:00
|
|
|
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;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (serviceContent == NULL || *serviceContent != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "RetrieveServiceContent", request,
|
2009-11-22 20:32:23 +00:00
|
|
|
&response, esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ServiceContent_Deserialize(response->node, serviceContent) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Login(esxVI_Context *ctx, const char *userName, const char *password,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_UserSession **userSession)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userSession == NULL || *userSession != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<Login xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(userName, "userName", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(password, "password", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</Login>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "Login", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_UserSession_Deserialize(response->node, userSession) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Logout(esxVI_Context *ctx)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<Logout xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</Logout>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "Logout", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_None) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_SessionIsActive(esxVI_Context *ctx, const char *sessionID,
|
|
|
|
const char *userName, esxVI_Boolean *active)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<SessionIsActive xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->sessionManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(sessionID, "sessionID", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(userName, "userName", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</SessionIsActive>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "SessionIsActive", request, &response,
|
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
|
|
|
esxVI_Boolean_Deserialize(response->node, active) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_RetrieveProperties(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PropertyFilterSpec *propertyFilterSpecList,
|
|
|
|
esxVI_ObjectContent **objectContentList)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectContentList == NULL || *objectContentList != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<RetrieveProperties xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PropertyFilterSpec_SerializeList(propertyFilterSpecList,
|
2009-07-23 20:21:08 +00:00
|
|
|
"specSet", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</RetrieveProperties>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "RetrieveProperties", request, &response,
|
|
|
|
esxVI_Occurrence_List) < 0 ||
|
|
|
|
esxVI_ObjectContent_DeserializeList(response->node,
|
2009-09-04 16:08:52 +00:00
|
|
|
objectContentList) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PowerOnVM_Task(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *virtualMachine,
|
|
|
|
esxVI_ManagedObjectReference **task)
|
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_StartSimpleVirtualMachineTask(ctx, "PowerOnVM",
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PowerOffVM_Task(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *virtualMachine,
|
|
|
|
esxVI_ManagedObjectReference **task)
|
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_StartSimpleVirtualMachineTask(ctx, "PowerOffVM",
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_SuspendVM_Task(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *virtualMachine,
|
|
|
|
esxVI_ManagedObjectReference **task)
|
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_StartSimpleVirtualMachineTask(ctx, "SuspendVM",
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine, task);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_MigrateVM_Task(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
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) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<MigrateVM_Task xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
|
|
|
esxVI_VirtualMachineMovePriority_Serialize
|
2010-01-15 22:05:26 +00:00
|
|
|
(esxVI_VirtualMachineMovePriority_DefaultPriority, "priority",
|
|
|
|
&buffer, esxVI_Boolean_True) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</MigrateVM_Task>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_StartVirtualMachineTask(ctx, "MigrateVM", request, task) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(request);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ReconfigVM_Task(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
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) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<ReconfigVM_Task xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachineConfigSpec_Serialize(spec, "spec", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</ReconfigVM_Task>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_StartVirtualMachineTask(ctx, "ReconfigVM", request, task) < 0) {
|
2009-09-23 12:52:36 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(request);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-09-23 12:52:36 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_RegisterVM_Task(esxVI_Context *ctx,
|
2009-09-23 12:52:36 +00:00
|
|
|
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) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-09-23 12:52:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<RegisterVM_Task xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(folder, "_this", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(path, "path", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(name, "name", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Boolean_Serialize(asTemplate, "asTemplate", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
|
2009-09-23 12:52:36 +00:00
|
|
|
esxVI_Boolean_False) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</RegisterVM_Task>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-09-23 12:52:36 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_StartVirtualMachineTask(ctx, "RegisterVM", request, task) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(request);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_CancelTask(esxVI_Context *ctx, esxVI_ManagedObjectReference *task)
|
2009-11-15 21:22:47 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-11-15 21:22:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<CancelTask xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(task, "_this", &buffer,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</CancelTask>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-15 21:22:47 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "CancelTask", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_None) < 0) {
|
2009-11-15 21:22:47 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
if (request == NULL) {
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 16:30:10 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_UnregisterVM(esxVI_Context *ctx,
|
2009-09-04 16:30:10 +00:00
|
|
|
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\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
|
2009-09-04 16:30:10 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</UnregisterVM>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-09-04 16:30:10 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "UnregisterVM", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_None) < 0) {
|
2009-09-04 16:30:10 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-09-04 16:30:10 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-15 21:22:47 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_AnswerVM(esxVI_Context *ctx,
|
2009-11-15 21:22:47 +00:00
|
|
|
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\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(virtualMachine, "_this", &buffer,
|
2009-11-15 21:22:47 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(questionId, "questionId", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
|
|
|
esxVI_String_SerializeValue(answerChoice, "answerChoice", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0) {
|
2009-11-15 21:22:47 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</AnswerVM>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-15 21:22:47 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
request = virBufferContentAndReset(&buffer);
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, request, NULL, &response,
|
2009-11-15 21:22:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_CreateFilter(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PropertyFilterSpec *propertyFilterSpec,
|
|
|
|
esxVI_Boolean partialUpdates,
|
|
|
|
esxVI_ManagedObjectReference **propertyFilter)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertyFilter == NULL || *propertyFilter != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<CreateFilter xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PropertyFilterSpec_Serialize(propertyFilterSpec, "spec", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
|
|
|
esxVI_Boolean_Serialize(partialUpdates, "partialUpdates", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</CreateFilter>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "CreateFilter", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Deserialize(response->node, propertyFilter,
|
2009-09-04 16:24:25 +00:00
|
|
|
"PropertyFilter") < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_DestroyPropertyFilter(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *propertyFilter)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<DestroyPropertyFilter xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(propertyFilter, "_this", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</DestroyPropertyFilter>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "DestroyPropertyFilter", request,
|
2009-11-22 20:32:23 +00:00
|
|
|
&response, esxVI_Occurrence_None) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_WaitForUpdates(esxVI_Context *ctx, const char *version,
|
|
|
|
esxVI_UpdateSet **updateSet)
|
2009-07-23 20:21:08 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateSet == NULL || *updateSet != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<WaitForUpdates xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->propertyCollector,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(version, "version", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</WaitForUpdates>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "WaitForUpdates", request,
|
2009-11-22 20:32:23 +00:00
|
|
|
&response, esxVI_Occurrence_RequiredItem) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_UpdateSet_Deserialize(response->node, updateSet) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_RebootGuest(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *virtualMachine)
|
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_SimpleVirtualMachineMethod(ctx, "RebootGuest", virtualMachine);
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ShutdownGuest(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *virtualMachine)
|
|
|
|
{
|
2010-01-15 22:05:26 +00:00
|
|
|
return esxVI_SimpleVirtualMachineMethod(ctx, "ShutdownGuest",
|
2009-07-23 20:21:08 +00:00
|
|
|
virtualMachine);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ValidateMigration(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventList == NULL || *eventList != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
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>");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_SerializeList(virtualMachineList, "vm",
|
|
|
|
&buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_VirtualMachinePowerState_Serialize(powerState, "state", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeList(testTypeList, "testType", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(resourcePool, "pool", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(hostSystem, "host", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</ValidateMigration>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "ValidateMigration", request, &response,
|
|
|
|
esxVI_Occurrence_List) < 0 ||
|
|
|
|
esxVI_Event_DeserializeList(response->node, eventList) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_FindByIp(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *datacenter,
|
|
|
|
const char *ip, esxVI_Boolean vmSearch,
|
|
|
|
esxVI_ManagedObjectReference **managedObjectReference)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (managedObjectReference == NULL || *managedObjectReference != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<FindByIp xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->searchIndex,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(datacenter, "datacenter",
|
|
|
|
&buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(ip, "ip", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Boolean_Serialize(vmSearch, "vmSearch", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</FindByIp>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "FindByIp", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_OptionalItem) < 0 ||
|
2009-09-04 16:08:52 +00:00
|
|
|
esxVI_ManagedObjectReference_Deserialize
|
2010-01-15 22:05:26 +00:00
|
|
|
(response->node, managedObjectReference,
|
2009-07-23 20:21:08 +00:00
|
|
|
vmSearch == esxVI_Boolean_True ? "VirtualMachine"
|
|
|
|
: "HostSystem") < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_FindByUuid(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
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;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (managedObjectReference == NULL || *managedObjectReference != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virUUIDFormat(uuid, uuid_string);
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<FindByUuid xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->searchIndex,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(datacenter, "datacenter",
|
|
|
|
&buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_String_SerializeValue(uuid_string, "uuid", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Boolean_Serialize(vmSearch, "vmSearch", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</FindByUuid>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "FindByUuid", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_OptionalItem) < 0) {
|
2009-09-23 12:40:41 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response->node == NULL) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (esxVI_ManagedObjectReference_Deserialize
|
2010-01-15 22:05:26 +00:00
|
|
|
(response->node, managedObjectReference,
|
2009-07-23 20:21:08 +00:00
|
|
|
vmSearch == esxVI_Boolean_True ? "VirtualMachine"
|
|
|
|
: "HostSystem") < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_QueryAvailablePerfMetric(esxVI_Context *ctx,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_ManagedObjectReference *entity,
|
|
|
|
esxVI_DateTime *beginTime,
|
|
|
|
esxVI_DateTime *endTime, esxVI_Int *intervalId,
|
|
|
|
esxVI_PerfMetricId **perfMetricIdList)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (perfMetricIdList == NULL || *perfMetricIdList != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<QueryAvailablePerfMetric xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_ManagedObjectReference_Serialize(entity, "entity", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_DateTime_Serialize(beginTime, "beginTime", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_DateTime_Serialize(endTime, "endTime", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Int_Serialize(intervalId, "intervalId", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_False) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</QueryAvailablePerfMetric>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "QueryAvailablePerfMetric", request,
|
2009-11-22 20:32:23 +00:00
|
|
|
&response, esxVI_Occurrence_List) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PerfMetricId_DeserializeList(response->node,
|
2009-09-04 16:08:52 +00:00
|
|
|
perfMetricIdList) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_QueryPerfCounter(esxVI_Context *ctx, esxVI_Int *counterIdList,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PerfCounterInfo **perfCounterInfoList)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (perfCounterInfoList == NULL || *perfCounterInfoList != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<QueryPerfCounter xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_Int_SerializeList(counterIdList, "counterId", &buffer,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_Boolean_True) < 0) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</QueryPerfCounter>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "QueryPerfCounter", request, &response,
|
|
|
|
esxVI_Occurrence_List) < 0 ||
|
|
|
|
esxVI_PerfCounterInfo_DeserializeList(response->node,
|
2009-09-04 16:08:52 +00:00
|
|
|
perfCounterInfoList) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_QueryPerf(esxVI_Context *ctx, esxVI_PerfQuerySpec *querySpecList,
|
2009-07-23 20:21:08 +00:00
|
|
|
esxVI_PerfEntityMetric **perfEntityMetricList)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
2009-09-04 16:24:25 +00:00
|
|
|
char *request = NULL;
|
|
|
|
esxVI_Response *response = NULL;
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
if (ctx->service == NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid call");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (perfEntityMetricList == NULL || *perfEntityMetricList != NULL) {
|
2010-01-15 22:05:26 +00:00
|
|
|
ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "Invalid argument");
|
2009-07-23 20:21:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
|
|
|
|
virBufferAddLit(&buffer, "<QueryPerf xmlns=\"urn:vim25\">");
|
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_ManagedObjectReference_Serialize(ctx->service->perfManager,
|
2009-07-23 20:21:08 +00:00
|
|
|
"_this", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PerfQuerySpec_SerializeList(querySpecList, "querySpec", &buffer,
|
|
|
|
esxVI_Boolean_True) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buffer, "</QueryPerf>");
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
|
|
|
|
|
|
|
|
if (virBufferError(&buffer)) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:24:25 +00:00
|
|
|
request = virBufferContentAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-01-15 22:05:26 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, "QueryPerf", request, &response,
|
2009-11-22 20:32:23 +00:00
|
|
|
esxVI_Occurrence_List) < 0 ||
|
2010-01-15 22:05:26 +00:00
|
|
|
esxVI_PerfEntityMetric_DeserializeList(response->node,
|
2009-09-04 16:08:52 +00:00
|
|
|
perfEntityMetricList) < 0) {
|
2009-07-23 20:21:08 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
VIR_FREE(request);
|
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
failure:
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buffer);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
result = -1;
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
}
|