1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-08-24 09:49:59 +03:00

ESX simplify SOAP request and response handling

* src/esx/esx_vi.[ch]: convert esxVI_RemoteRequest_Execute() to a
  simpler esxVI_Context_Execute() version, remove esxVI_RemoteRequest
  and convert esxVI_RemoteResponse to esxVI_Response
* src/esx/esx_vi_methods.c: update and simplify callers to use
  esxVI_Context_Execute() instead of esxVI_RemoteRequest_Execute()
This commit is contained in:
Matthias Bolte
2009-09-04 18:24:25 +02:00
committed by Daniel Veillard
parent 03d28d7355
commit 46e76e8b2b
3 changed files with 266 additions and 427 deletions

View File

@ -461,39 +461,21 @@ esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx, const char *url,
goto failure; goto failure;
} }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteRequest
*/
/* esxVI_RemoteRequest_Alloc */
ESX_VI__TEMPLATE__ALLOC(RemoteRequest);
/* esxVI_RemoteRequest_Free */
ESX_VI__TEMPLATE__FREE(RemoteRequest,
{
VIR_FREE(item->request);
VIR_FREE(item->xpathExpression);
});
int int
esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx, esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
esxVI_RemoteRequest *remoteRequest, const char *request, const char *xpathExpression,
esxVI_RemoteResponse **remoteResponse, esxVI_Response **response, esxVI_Boolean expectList)
esxVI_Boolean expectList)
{ {
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL; esxVI_Fault *fault = NULL;
CURLcode errorCode; CURLcode errorCode;
if (remoteRequest == NULL || remoteRequest->request == NULL || if (request == NULL || response == NULL || *response != NULL) {
remoteResponse == NULL || *remoteResponse != NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
goto failure; goto failure;
} }
if (esxVI_RemoteResponse_Alloc(conn, remoteResponse) < 0) { if (esxVI_Response_Alloc(conn, response) < 0) {
goto failure; goto failure;
} }
@ -501,10 +483,8 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url); curl_easy_setopt(ctx->curl_handle, CURLOPT_URL, ctx->url);
curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(ctx->curl_handle, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS, curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDS, request);
remoteRequest->request); curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE, strlen(request));
curl_easy_setopt(ctx->curl_handle, CURLOPT_POSTFIELDSIZE,
strlen(remoteRequest->request));
errorCode = curl_easy_perform(ctx->curl_handle); errorCode = curl_easy_perform(ctx->curl_handle);
@ -516,7 +496,7 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
} }
errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE, errorCode = curl_easy_getinfo(ctx->curl_handle, CURLINFO_RESPONSE_CODE,
&(*remoteResponse)->responseCode); &(*response)->responseCode);
if (errorCode != CURLE_OK) { if (errorCode != CURLE_OK) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
@ -532,66 +512,62 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
(*remoteResponse)->response = virBufferContentAndReset(&buffer); (*response)->content = virBufferContentAndReset(&buffer);
if ((*remoteResponse)->responseCode == 500 || if ((*response)->responseCode == 500 ||
(remoteRequest->xpathExpression != NULL && (xpathExpression != NULL && (*response)->responseCode == 200)) {
(*remoteResponse)->responseCode == 200)) { (*response)->document = xmlReadDoc(BAD_CAST (*response)->content, "",
(*remoteResponse)->document = NULL, XML_PARSE_NONET);
xmlReadDoc(BAD_CAST(*remoteResponse)->response, "", NULL,
XML_PARSE_NONET);
if ((*remoteResponse)->document == NULL) { if ((*response)->document == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Could not parse XML response"); "Could not parse XML response");
goto failure; goto failure;
} }
if (xmlDocGetRootElement((*remoteResponse)->document) == NULL) { if (xmlDocGetRootElement((*response)->document) == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"XML response is an empty document"); "XML response is an empty document");
goto failure; goto failure;
} }
(*remoteResponse)->xpathContext = (*response)->xpathContext = xmlXPathNewContext((*response)->document);
xmlXPathNewContext((*remoteResponse)->document);
if ((*remoteResponse)->xpathContext == NULL) { if ((*response)->xpathContext == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Could not create XPath context"); "Could not create XPath context");
goto failure; goto failure;
} }
xmlXPathRegisterNs((*remoteResponse)->xpathContext, BAD_CAST "soapenv", xmlXPathRegisterNs((*response)->xpathContext, BAD_CAST "soapenv",
BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/"); BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/");
xmlXPathRegisterNs((*remoteResponse)->xpathContext, BAD_CAST "vim", xmlXPathRegisterNs((*response)->xpathContext, BAD_CAST "vim",
BAD_CAST "urn:vim25"); BAD_CAST "urn:vim25");
if ((*remoteResponse)->responseCode == 500) { if ((*response)->responseCode == 500) {
(*remoteResponse)->node = (*response)->node =
virXPathNode(conn, "/soapenv:Envelope/soapenv:Body/soapenv:Fault", virXPathNode(conn, "/soapenv:Envelope/soapenv:Body/soapenv:Fault",
(*remoteResponse)->xpathContext); (*response)->xpathContext);
if ((*remoteResponse)->node == NULL) { if ((*response)->node == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d. VI Fault is unknown, " "HTTP response code %d. VI Fault is unknown, "
"XPath evaluation failed", "XPath evaluation failed",
(int)(*remoteResponse)->responseCode); (int)(*response)->responseCode);
goto failure; goto failure;
} }
if (esxVI_Fault_Deserialize(conn, (*remoteResponse)->node, if (esxVI_Fault_Deserialize(conn, (*response)->node, &fault) < 0) {
&fault) < 0) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d. VI Fault is unknown, " "HTTP response code %d. VI Fault is unknown, "
"deserialization failed", "deserialization failed",
(int)(*remoteResponse)->responseCode); (int)(*response)->responseCode);
goto failure; goto failure;
} }
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d. VI Fault: %s - %s", "HTTP response code %d. VI Fault: %s - %s",
(int)(*remoteResponse)->responseCode, (int)(*response)->responseCode,
fault->faultcode, fault->faultstring); fault->faultcode, fault->faultstring);
goto failure; goto failure;
@ -599,38 +575,36 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
xmlNodePtr *nodeSet = NULL; xmlNodePtr *nodeSet = NULL;
int nodeSet_size; int nodeSet_size;
nodeSet_size = virXPathNodeSet(conn, remoteRequest->xpathExpression, nodeSet_size = virXPathNodeSet(conn, xpathExpression,
(*remoteResponse)->xpathContext, (*response)->xpathContext,
&nodeSet); &nodeSet);
if (nodeSet_size < 0) { if (nodeSet_size < 0) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"XPath evaluation of '%s' failed", "XPath evaluation of '%s' failed",
remoteRequest->xpathExpression); xpathExpression);
goto failure; goto failure;
} else if (nodeSet_size == 0) { } else if (nodeSet_size == 0) {
(*remoteResponse)->node = NULL; (*response)->node = NULL;
} else { } else {
(*remoteResponse)->node = nodeSet[0]; (*response)->node = nodeSet[0];
} }
VIR_FREE(nodeSet); VIR_FREE(nodeSet);
} else { } else {
(*remoteResponse)->node = (*response)->node = virXPathNode(conn, xpathExpression,
virXPathNode(conn, remoteRequest->xpathExpression, (*response)->xpathContext);
(*remoteResponse)->xpathContext);
if ((*remoteResponse)->node == NULL) { if ((*response)->node == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"XPath evaluation of '%s' failed", "XPath evaluation of '%s' failed",
remoteRequest->xpathExpression); xpathExpression);
goto failure; goto failure;
} }
} }
} else if ((*remoteResponse)->responseCode != 200) { } else if ((*response)->responseCode != 200) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"HTTP response code %d", "HTTP response code %d", (int)(*response)->responseCode);
(int)(*remoteResponse)->responseCode);
goto failure; goto failure;
} }
@ -639,7 +613,7 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
failure: failure:
free(virBufferContentAndReset(&buffer)); free(virBufferContentAndReset(&buffer));
esxVI_RemoteResponse_Free(remoteResponse); esxVI_Response_Free(response);
esxVI_Fault_Free(&fault); esxVI_Fault_Free(&fault);
return -1; return -1;
@ -653,16 +627,16 @@ esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteResponse * Response
*/ */
/* esxVI_RemoteResponse_Alloc */ /* esxVI_Response_Alloc */
ESX_VI__TEMPLATE__ALLOC(RemoteResponse); ESX_VI__TEMPLATE__ALLOC(Response);
/* esxVI_RemoteResponse_Free */ /* esxVI_Response_Free */
ESX_VI__TEMPLATE__FREE(RemoteResponse, ESX_VI__TEMPLATE__FREE(Response,
{ {
VIR_FREE(item->response); VIR_FREE(item->content);
xmlXPathFreeContext(item->xpathContext); xmlXPathFreeContext(item->xpathContext);
@ -1584,39 +1558,25 @@ esxVI_StartVirtualMachineTask(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference **task) esxVI_ManagedObjectReference **task)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL; char *xpathExpression = NULL;
esxVI_RemoteResponse *remoteResponse = NULL; esxVI_Response *response = NULL;
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0) { if (virAsprintf(&xpathExpression,
goto failure;
}
remoteRequest->request = (char *)request;
if (virAsprintf(&remoteRequest->xpathExpression,
ESX_VI__SOAP__RESPONSE_XPATH("%s_Task"), name) < 0) { ESX_VI__SOAP__RESPONSE_XPATH("%s_Task"), name) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
goto failure; goto failure;
} }
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request, xpathExpression, &response,
esxVI_Boolean_False) < 0 || esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Deserialize esxVI_ManagedObjectReference_Deserialize(conn, response->node, task,
(conn, remoteResponse->node, task, "Task") < 0) { "Task") < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(xpathExpression);
* Remove values given by the caller from the data structures to prevent esxVI_Response_Free(&response);
* them from being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->request = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
@ -1682,13 +1642,13 @@ esxVI_StartSimpleVirtualMachineTask
int int
esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx, esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
const char *name, const char *name,
esxVI_ManagedObjectReference *virtualMachine) esxVI_ManagedObjectReference *virtualMachine)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@ -1700,8 +1660,7 @@ esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
virBufferAdd(&buffer, name, -1); virBufferAdd(&buffer, name, -1);
virBufferAddLit(&buffer, " xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, " xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this",
esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this",
&buffer, &buffer,
esxVI_Boolean_True) < 0) { esxVI_Boolean_True) < 0) {
goto failure; goto failure;
@ -1717,21 +1676,23 @@ esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
esxVI_Boolean_False) < 0) { esxVI_Boolean_False) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
esxVI_RemoteRequest_Free(&remoteRequest); VIR_FREE(request);
esxVI_RemoteResponse_Free(&remoteResponse); esxVI_Response_Free(&response);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;

View File

@ -34,8 +34,7 @@
typedef enum _esxVI_APIVersion esxVI_APIVersion; typedef enum _esxVI_APIVersion esxVI_APIVersion;
typedef enum _esxVI_ProductVersion esxVI_ProductVersion; typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
typedef struct _esxVI_Context esxVI_Context; typedef struct _esxVI_Context esxVI_Context;
typedef struct _esxVI_RemoteResponse esxVI_RemoteResponse; typedef struct _esxVI_Response esxVI_Response;
typedef struct _esxVI_RemoteRequest esxVI_RemoteRequest;
typedef struct _esxVI_Enumeration esxVI_Enumeration; typedef struct _esxVI_Enumeration esxVI_Enumeration;
typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue; typedef struct _esxVI_EnumerationValue esxVI_EnumerationValue;
typedef struct _esxVI_List esxVI_List; typedef struct _esxVI_List esxVI_List;
@ -88,43 +87,26 @@ int esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx,
const char *password, int noVerify); const char *password, int noVerify);
int esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx, int esxVI_Context_Download(virConnectPtr conn, esxVI_Context *ctx,
const char *url, char **content); const char *url, char **content);
int esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
const char *request, const char *xpathExpression,
esxVI_Response **response, esxVI_Boolean expectList);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteRequest * Response
*/ */
struct _esxVI_RemoteRequest { struct _esxVI_Response {
char *request; /* required */
char *xpathExpression; /* optional */
};
int esxVI_RemoteRequest_Alloc(virConnectPtr conn,
esxVI_RemoteRequest **remoteRequest);
void esxVI_RemoteRequest_Free(esxVI_RemoteRequest **remoteRequest);
int esxVI_RemoteRequest_Execute(virConnectPtr conn, esxVI_Context *ctx,
esxVI_RemoteRequest *remoteRequest,
esxVI_RemoteResponse **remoteResponse,
esxVI_Boolean expectList);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* RemoteResponse
*/
struct _esxVI_RemoteResponse {
long responseCode; /* required */ long responseCode; /* required */
char *response; /* required */ char *content; /* required */
xmlDocPtr document; /* optional */ xmlDocPtr document; /* optional */
xmlXPathContextPtr xpathContext; /* optional */ xmlXPathContextPtr xpathContext; /* optional */
xmlNodePtr node; /* optional, list */ xmlNodePtr node; /* optional, list */
}; };
int esxVI_RemoteResponse_Alloc(virConnectPtr conn, int esxVI_Response_Alloc(virConnectPtr conn, esxVI_Response **response);
esxVI_RemoteResponse **remoteResponse); void esxVI_Response_Free(esxVI_Response **response);
void esxVI_RemoteResponse_Free(esxVI_RemoteResponse **remoteResponse);

View File

@ -50,8 +50,7 @@
"</soapenv:Envelope>" "</soapenv:Envelope>"
#define ESX_VI__SOAP__RESPONSE_XPATH(_type) \ #define ESX_VI__SOAP__RESPONSE_XPATH(_type) \
((char *)"/soapenv:Envelope/soapenv:Body/" \ "/soapenv:Envelope/soapenv:Body/vim:"_type"Response/vim:returnval"
"vim:"_type"Response/vim:returnval")
@ -59,57 +58,37 @@
* VI Methods * VI Methods
*/ */
static const char *_esxVI_RetrieveServiceContentRequest =
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;
int int
esxVI_RetrieveServiceContent(virConnectPtr conn, esxVI_Context *ctx, esxVI_RetrieveServiceContent(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ServiceContent **serviceContent) esxVI_ServiceContent **serviceContent)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL; const char *request = ESX_VI__SOAP__REQUEST_HEADER
esxVI_RemoteResponse *remoteResponse = NULL; "<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) { if (serviceContent == NULL || *serviceContent != NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
return -1; return -1;
} }
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0) { if (esxVI_Context_Execute(conn, ctx, request,
goto failure; ESX_VI__SOAP__RESPONSE_XPATH("RetrieveServiceContent"),
} &response, esxVI_Boolean_False) < 0 ||
esxVI_ServiceContent_Deserialize(conn, response->node,
remoteRequest->request = (char *)_esxVI_RetrieveServiceContentRequest;
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("RetrieveServiceContent");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse,
esxVI_Boolean_False) < 0 ||
esxVI_ServiceContent_Deserialize(conn, remoteResponse->node,
serviceContent) < 0) { serviceContent) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* esxVI_Response_Free(&response);
* Remove static values from the data structures to prevent them from
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->request = NULL;
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
@ -127,9 +106,9 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
esxVI_UserSession **userSession) esxVI_UserSession **userSession)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -144,8 +123,7 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<Login xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<Login xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->sessionManager, ctx->service->sessionManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
@ -164,32 +142,25 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression = ESX_VI__SOAP__RESPONSE_XPATH("Login");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("Login"),
esxVI_UserSession_Deserialize(conn, remoteResponse->node, &response, esxVI_Boolean_False) < 0 ||
userSession) < 0) { esxVI_UserSession_Deserialize(conn, response->node, userSession) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -202,9 +173,9 @@ int
esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx) esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -214,8 +185,7 @@ esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<Logout xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<Logout xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->sessionManager, ctx->service->sessionManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0) { esxVI_Boolean_True) < 0) {
@ -230,21 +200,23 @@ esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
esxVI_Boolean_False) < 0) { esxVI_Boolean_False) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
esxVI_RemoteRequest_Free(&remoteRequest); VIR_FREE(request);
esxVI_RemoteResponse_Free(&remoteResponse); esxVI_Response_Free(&response);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -259,9 +231,9 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
esxVI_Boolean *active) esxVI_Boolean *active)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -276,8 +248,7 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<SessionIsActive xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<SessionIsActive xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->sessionManager, ctx->service->sessionManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
@ -296,32 +267,25 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("SessionIsActive");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("SessionIsActive"),
esxVI_Boolean_Deserialize(conn, remoteResponse->node, active) < 0) { &response, esxVI_Boolean_False) < 0 ||
esxVI_Boolean_Deserialize(conn, response->node, active) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -336,9 +300,9 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ObjectContent **objectContentList) esxVI_ObjectContent **objectContentList)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -353,8 +317,7 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<RetrieveProperties xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<RetrieveProperties xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->propertyCollector, ctx->service->propertyCollector,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
@ -372,33 +335,26 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("RetrieveProperties");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_True) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("RetrieveProperties"),
esxVI_ObjectContent_DeserializeList(conn, remoteResponse->node, &response, esxVI_Boolean_True) < 0 ||
esxVI_ObjectContent_DeserializeList(conn, response->node,
objectContentList) < 0) { objectContentList) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -495,7 +451,9 @@ esxVI_MigrateVM_Task(virConnectPtr conn, esxVI_Context *ctx,
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -551,7 +509,9 @@ esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -567,9 +527,9 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference **propertyFilter) esxVI_ManagedObjectReference **propertyFilter)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -584,8 +544,7 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<CreateFilter xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<CreateFilter xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->propertyCollector, ctx->service->propertyCollector,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
@ -604,33 +563,27 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("CreateFilter");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("CreateFilter"),
esxVI_ManagedObjectReference_Deserialize &response, esxVI_Boolean_False) < 0 ||
(conn, remoteResponse->node, propertyFilter, "PropertyFilter") < 0) { esxVI_ManagedObjectReference_Deserialize(conn, response->node,
propertyFilter,
"PropertyFilter") < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -644,9 +597,9 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *propertyFilter) esxVI_ManagedObjectReference *propertyFilter)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -656,8 +609,7 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<DestroyPropertyFilter xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<DestroyPropertyFilter xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, propertyFilter, "_this",
esxVI_ManagedObjectReference_Serialize(conn, propertyFilter, "_this",
&buffer, &buffer,
esxVI_Boolean_True) < 0) { esxVI_Boolean_True) < 0) {
goto failure; goto failure;
@ -671,21 +623,23 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
esxVI_Boolean_False) < 0) { esxVI_Boolean_False) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
esxVI_RemoteRequest_Free(&remoteRequest); VIR_FREE(request);
esxVI_RemoteResponse_Free(&remoteResponse); esxVI_Response_Free(&response);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -699,9 +653,9 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
const char *version, esxVI_UpdateSet **updateSet) const char *version, esxVI_UpdateSet **updateSet)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -716,8 +670,7 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<WaitForUpdates xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<WaitForUpdates xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn,
esxVI_ManagedObjectReference_Serialize(conn,
ctx->service->propertyCollector, ctx->service->propertyCollector,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
@ -734,33 +687,25 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("WaitForUpdates");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("WaitForUpdates"),
esxVI_UpdateSet_Deserialize(conn, remoteResponse->node, &response, esxVI_Boolean_False) < 0 ||
updateSet) < 0) { esxVI_UpdateSet_Deserialize(conn, response->node, updateSet) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -799,9 +744,9 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
esxVI_Event **eventList) esxVI_Event **eventList)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -821,8 +766,7 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
"ServiceInstance" "ServiceInstance"
"</_this>"); "</_this>");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_SerializeList(conn, virtualMachineList,
esxVI_ManagedObjectReference_SerializeList(conn, virtualMachineList,
"vm", &buffer, "vm", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_VirtualMachinePowerState_Serialize(conn, powerState, "state", esxVI_VirtualMachinePowerState_Serialize(conn, powerState, "state",
@ -847,33 +791,25 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("ValidateMigration");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_True) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("ValidateMigration"),
esxVI_Event_DeserializeList(conn, remoteResponse->node, &response, esxVI_Boolean_True) < 0 ||
eventList) < 0) { esxVI_Event_DeserializeList(conn, response->node, eventList) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -889,9 +825,9 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference **managedObjectReference) esxVI_ManagedObjectReference **managedObjectReference)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -906,8 +842,7 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<FindByIp xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<FindByIp xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(conn, datacenter, esxVI_ManagedObjectReference_Serialize(conn, datacenter,
@ -928,35 +863,28 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("FindByIp");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("FindByIp"),
&response, esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Deserialize esxVI_ManagedObjectReference_Deserialize
(conn, remoteResponse->node, managedObjectReference, (conn, response->node, managedObjectReference,
vmSearch == esxVI_Boolean_True ? "VirtualMachine" vmSearch == esxVI_Boolean_True ? "VirtualMachine"
: "HostSystem") < 0) { : "HostSystem") < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -972,10 +900,10 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference **managedObjectReference) esxVI_ManagedObjectReference **managedObjectReference)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -992,8 +920,7 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<FindByUuid xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<FindByUuid xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
esxVI_ManagedObjectReference_Serialize(conn, ctx->service->searchIndex,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(conn, datacenter, esxVI_ManagedObjectReference_Serialize(conn, datacenter,
@ -1014,35 +941,28 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("FindByUuid");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_False) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("FindByUuid"),
&response, esxVI_Boolean_False) < 0 ||
esxVI_ManagedObjectReference_Deserialize esxVI_ManagedObjectReference_Deserialize
(conn, remoteResponse->node, managedObjectReference, (conn, response->node, managedObjectReference,
vmSearch == esxVI_Boolean_True ? "VirtualMachine" vmSearch == esxVI_Boolean_True ? "VirtualMachine"
: "HostSystem") < 0) { : "HostSystem") < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -1059,9 +979,9 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PerfMetricId **perfMetricIdList) esxVI_PerfMetricId **perfMetricIdList)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -1076,8 +996,7 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryAvailablePerfMetric xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<QueryAvailablePerfMetric xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_ManagedObjectReference_Serialize(conn, entity, esxVI_ManagedObjectReference_Serialize(conn, entity,
@ -1100,33 +1019,26 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("QueryAvailablePerfMetric");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_True) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("QueryAvailablePerfMetric"),
esxVI_PerfMetricId_DeserializeList(conn, remoteResponse->node, &response, esxVI_Boolean_True) < 0 ||
esxVI_PerfMetricId_DeserializeList(conn, response->node,
perfMetricIdList) < 0) { perfMetricIdList) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -1141,9 +1053,9 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PerfCounterInfo **perfCounterInfoList) esxVI_PerfCounterInfo **perfCounterInfoList)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -1158,8 +1070,7 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryPerfCounter xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<QueryPerfCounter xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_Int_SerializeList(conn, counterIdList, "counterId", &buffer, esxVI_Int_SerializeList(conn, counterIdList, "counterId", &buffer,
@ -1175,33 +1086,26 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression =
ESX_VI__SOAP__RESPONSE_XPATH("QueryPerfCounter");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_True) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("QueryPerfCounter"),
esxVI_PerfCounterInfo_DeserializeList(conn, remoteResponse->node, &response, esxVI_Boolean_True) < 0 ||
esxVI_PerfCounterInfo_DeserializeList(conn, response->node,
perfCounterInfoList) < 0) { perfCounterInfoList) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;
@ -1216,9 +1120,9 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
esxVI_PerfEntityMetric **perfEntityMetricList) esxVI_PerfEntityMetric **perfEntityMetricList)
{ {
int result = 0; int result = 0;
esxVI_RemoteRequest *remoteRequest = NULL;
esxVI_RemoteResponse *remoteResponse = NULL;
virBuffer buffer = VIR_BUFFER_INITIALIZER; virBuffer buffer = VIR_BUFFER_INITIALIZER;
char *request = NULL;
esxVI_Response *response = NULL;
if (ctx->service == NULL) { if (ctx->service == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call"); ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid call");
@ -1233,13 +1137,11 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER); virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
virBufferAddLit(&buffer, "<QueryPerf xmlns=\"urn:vim25\">"); virBufferAddLit(&buffer, "<QueryPerf xmlns=\"urn:vim25\">");
if (esxVI_RemoteRequest_Alloc(conn, &remoteRequest) < 0 || if (esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
esxVI_ManagedObjectReference_Serialize(conn, ctx->service->perfManager,
"_this", &buffer, "_this", &buffer,
esxVI_Boolean_True) < 0 || esxVI_Boolean_True) < 0 ||
esxVI_PerfQuerySpec_SerializeList(conn, querySpecList, "querySpec", esxVI_PerfQuerySpec_SerializeList(conn, querySpecList, "querySpec",
&buffer, &buffer, esxVI_Boolean_True) < 0) {
esxVI_Boolean_True) < 0) {
goto failure; goto failure;
} }
@ -1251,32 +1153,26 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
remoteRequest->request = virBufferContentAndReset(&buffer); request = virBufferContentAndReset(&buffer);
remoteRequest->xpathExpression = ESX_VI__SOAP__RESPONSE_XPATH("QueryPerf");
if (esxVI_RemoteRequest_Execute(conn, ctx, remoteRequest, &remoteResponse, if (esxVI_Context_Execute(conn, ctx, request,
esxVI_Boolean_True) < 0 || ESX_VI__SOAP__RESPONSE_XPATH("QueryPerf"),
esxVI_PerfEntityMetric_DeserializeList(conn, remoteResponse->node, &response, esxVI_Boolean_True) < 0 ||
esxVI_PerfEntityMetric_DeserializeList(conn, response->node,
perfEntityMetricList) < 0) { perfEntityMetricList) < 0) {
goto failure; goto failure;
} }
cleanup: cleanup:
/* VIR_FREE(request);
* Remove static values from the data structures to prevent them from esxVI_Response_Free(&response);
* being freed by the call to esxVI_RemoteRequest_Free().
*/
if (remoteRequest != NULL) {
remoteRequest->xpathExpression = NULL;
}
esxVI_RemoteRequest_Free(&remoteRequest);
esxVI_RemoteResponse_Free(&remoteResponse);
return result; return result;
failure: failure:
free(virBufferContentAndReset(&buffer)); if (request == NULL) {
request = virBufferContentAndReset(&buffer);
}
result = -1; result = -1;