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.
|
2010-02-23 00:06:58 +00:00
|
|
|
* Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-07-23 20:21:08 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "buf.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "uuid.h"
|
|
|
|
#include "esx_vi_methods.h"
|
|
|
|
#include "esx_util.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
2010-04-02 19:34:31 +00:00
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
|
2010-04-13 12:25:52 +00:00
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__None \
|
|
|
|
/* nothing */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__NotNone \
|
|
|
|
if (output == NULL || *output != 0) { \
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \
|
2010-04-13 12:25:52 +00:00
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__RequiredItem \
|
|
|
|
ESX_VI__METHOD__CHECK_OUTPUT__NotNone
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__RequiredList \
|
|
|
|
ESX_VI__METHOD__CHECK_OUTPUT__NotNone
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__OptionalItem \
|
|
|
|
ESX_VI__METHOD__CHECK_OUTPUT__NotNone
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__CHECK_OUTPUT__OptionalList \
|
|
|
|
ESX_VI__METHOD__CHECK_OUTPUT__NotNone
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:17:10 +00:00
|
|
|
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__None(_type, _suffix) \
|
2010-04-13 12:25:52 +00:00
|
|
|
/* nothing */
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:17:10 +00:00
|
|
|
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type, _suffix) \
|
|
|
|
if (esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-04-13 12:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:17:10 +00:00
|
|
|
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type, _suffix) \
|
2010-04-13 12:25:52 +00:00
|
|
|
if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-04-13 12:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:17:10 +00:00
|
|
|
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type, _suffix) \
|
2010-04-13 12:25:52 +00:00
|
|
|
if (response->node != NULL && \
|
2010-08-29 17:17:10 +00:00
|
|
|
esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-04-13 12:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-29 17:17:10 +00:00
|
|
|
#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type, _suffix) \
|
2010-04-13 12:25:52 +00:00
|
|
|
if (response->node != NULL && \
|
|
|
|
esxVI_##_type##_DeserializeList(response->node, output) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-04-13 12:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD(_name, _this_from_service, _parameters, _output_type, \
|
2010-08-29 17:17:10 +00:00
|
|
|
_deserialize_suffix, _occurrence, _validate, \
|
|
|
|
_serialize) \
|
2010-02-23 00:06:58 +00:00
|
|
|
int \
|
|
|
|
esxVI_##_name _parameters \
|
|
|
|
{ \
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1; \
|
2010-04-13 12:25:52 +00:00
|
|
|
const char *methodName = #_name; \
|
2010-02-23 00:06:58 +00:00
|
|
|
virBuffer buffer = VIR_BUFFER_INITIALIZER; \
|
|
|
|
char *request = NULL; \
|
|
|
|
esxVI_Response *response = NULL; \
|
|
|
|
\
|
2010-04-13 12:25:52 +00:00
|
|
|
ESX_VI__METHOD__PARAMETER__THIS__##_this_from_service \
|
|
|
|
\
|
|
|
|
ESX_VI__METHOD__CHECK_OUTPUT__##_occurrence \
|
2010-02-23 00:06:58 +00:00
|
|
|
\
|
|
|
|
_validate \
|
|
|
|
\
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); \
|
|
|
|
virBufferAddLit(&buffer, "<"#_name" xmlns=\"urn:vim25\">"); \
|
|
|
|
\
|
|
|
|
_serialize \
|
|
|
|
\
|
|
|
|
virBufferAddLit(&buffer, "</"#_name">"); \
|
|
|
|
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER); \
|
|
|
|
\
|
|
|
|
if (virBufferError(&buffer)) { \
|
|
|
|
virReportOOMError(); \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-02-23 00:06:58 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
request = virBufferContentAndReset(&buffer); \
|
|
|
|
\
|
2010-04-13 12:25:52 +00:00
|
|
|
if (esxVI_Context_Execute(ctx, methodName, request, &response, \
|
2010-02-23 00:06:58 +00:00
|
|
|
esxVI_Occurrence_##_occurrence) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-02-23 00:06:58 +00:00
|
|
|
} \
|
|
|
|
\
|
2010-08-29 17:17:10 +00:00
|
|
|
ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence \
|
|
|
|
(_output_type, _deserialize_suffix) \
|
2010-02-23 00:06:58 +00:00
|
|
|
\
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0; \
|
|
|
|
\
|
2010-02-23 00:06:58 +00:00
|
|
|
cleanup: \
|
2010-05-19 20:59:32 +00:00
|
|
|
if (result < 0) { \
|
|
|
|
virBufferFreeAndReset(&buffer); \
|
|
|
|
} \
|
|
|
|
\
|
2010-02-23 00:06:58 +00:00
|
|
|
VIR_FREE(request); \
|
|
|
|
esxVI_Response_Free(&response); \
|
|
|
|
\
|
|
|
|
return result; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-13 12:25:52 +00:00
|
|
|
#define ESX_VI__METHOD__PARAMETER__THIS_FROM_SERVICE(_type, _name) \
|
|
|
|
esxVI_##_type *_this = NULL; \
|
|
|
|
\
|
2010-02-23 00:06:58 +00:00
|
|
|
if (ctx->service == NULL) { \
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call")); \
|
2010-02-23 00:06:58 +00:00
|
|
|
return -1; \
|
2010-04-13 12:25:52 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
_this = ctx->service->_name;
|
2010-02-23 00:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-13 12:25:52 +00:00
|
|
|
#define ESX_VI__METHOD__PARAMETER__THIS__/* explicit _this */ \
|
|
|
|
/* nothing */
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-23 00:06:58 +00:00
|
|
|
/*
|
|
|
|
* A required parameter must be != 0 (NULL for pointers, "undefined" == 0 for
|
|
|
|
* enumeration values).
|
|
|
|
*
|
|
|
|
* To be used as part of ESX_VI__METHOD.
|
|
|
|
*/
|
|
|
|
#define ESX_VI__METHOD__PARAMETER__REQUIRE(_name) \
|
|
|
|
if (_name == 0) { \
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"Required parameter '%s' is missing for call to %s", \
|
|
|
|
#_name, methodName); \
|
2010-02-23 00:06:58 +00:00
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__PARAMETER__SERIALIZE(_type, _name) \
|
|
|
|
if (esxVI_##_type##_Serialize(_name, #_name, &buffer) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-02-23 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(_type, _name) \
|
|
|
|
if (esxVI_##_type##_SerializeList(_name, #_name, &buffer) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-02-23 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ESX_VI__METHOD__PARAMETER__SERIALIZE_VALUE(_type, _name) \
|
|
|
|
if (esxVI_##_type##_SerializeValue(_name, #_name, &buffer) < 0) { \
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup; \
|
2010-02-23 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-01 06:05:58 +00:00
|
|
|
#include "esx_vi_methods.generated.macro"
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* 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)
|
|
|
|
{
|
2010-05-19 20:59:32 +00:00
|
|
|
int result = -1;
|
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) {
|
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_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) {
|
2010-05-19 20:59:32 +00:00
|
|
|
goto cleanup;
|
2009-07-23 20:21:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 20:59:32 +00:00
|
|
|
result = 0;
|
|
|
|
|
2009-07-23 20:21:08 +00:00
|
|
|
cleanup:
|
2009-09-04 16:24:25 +00:00
|
|
|
esxVI_Response_Free(&response);
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-23 00:06:58 +00:00
|
|
|
/* esxVI_ValidateMigration */
|
2010-04-13 12:25:52 +00:00
|
|
|
ESX_VI__METHOD(ValidateMigration, /* special _this */,
|
2010-02-23 00:06:58 +00:00
|
|
|
(esxVI_Context *ctx,
|
2010-04-13 12:25:52 +00:00
|
|
|
esxVI_ManagedObjectReference *vm, /* required, list */
|
|
|
|
esxVI_VirtualMachinePowerState state, /* optional */
|
|
|
|
esxVI_String *testType, /* optional, list */
|
|
|
|
esxVI_ManagedObjectReference *pool, /* optional */
|
|
|
|
esxVI_ManagedObjectReference *host, /* optional */
|
|
|
|
esxVI_Event **output), /* optional, list */
|
2010-08-29 17:17:10 +00:00
|
|
|
Event, /* nothing */, OptionalList,
|
2010-02-23 00:06:58 +00:00
|
|
|
{
|
|
|
|
ESX_VI__METHOD__PARAMETER__REQUIRE(vm)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
virBufferAddLit(&buffer, "<_this xmlns=\"urn:vim25\" "
|
|
|
|
"xsi:type=\"ManagedObjectReference\" "
|
|
|
|
"type=\"ServiceInstance\">"
|
|
|
|
"ServiceInstance"
|
|
|
|
"</_this>");
|
|
|
|
ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(ManagedObjectReference, vm)
|
|
|
|
ESX_VI__METHOD__PARAMETER__SERIALIZE(VirtualMachinePowerState, state)
|
|
|
|
ESX_VI__METHOD__PARAMETER__SERIALIZE_LIST(String, testType)
|
|
|
|
ESX_VI__METHOD__PARAMETER__SERIALIZE(ManagedObjectReference, pool)
|
|
|
|
ESX_VI__METHOD__PARAMETER__SERIALIZE(ManagedObjectReference, host)
|
|
|
|
})
|
2009-07-23 20:21:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-13 12:25:52 +00:00
|
|
|
#include "esx_vi_methods.generated.c"
|