[libvirt] [PATCH 1/2] ESX: Allow method calls for VI version > 2.5

Matthias Bolte matthias.bolte at googlemail.com
Sun Mar 30 19:19:42 UTC 2014


2014-03-27 23:24 GMT+01:00 Dawid Zamirski <dzamirski at dattobackup.com>:
> Currently, ESX driver can only issue VI method calls available in version
> 2.5. To send method calls available in newer versions, a SOAPAction
> header needs to be set in the following format:
>
> 'SOAPAction: "urn:vim25/<version_number>"'
>
> This patch modifies the Python code generator to optionally read
> 'apiVersion' token from .input file  which is then passed to the
> ESX_VI_METHOD macro. If the apiVersion is not specified, "2.5" is passed
> by default. Finally, the esx_VI_Context_Execute function takes this
> argument and conditionally sets SOAPAction header, performs CURL
> request, and then unsets it again so that any subsequest 2.5 call gets
> 2.5 formatted XML response.
>
> In conclusion, this patch allows to make method calls for VI API greater
> than v2.5 wthout braking existing v2.5 calls.
> ---
>  src/esx/esx_vi.c            | 26 +++++++++++++++++++++++++-
>  src/esx/esx_vi.h            |  2 +-
>  src/esx/esx_vi_generator.py | 20 +++++++++++++++-----
>  src/esx/esx_vi_methods.c    | 12 +++++++-----
>  4 files changed, 48 insertions(+), 12 deletions(-)
>
> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
> index 6188139..393a009 100644
> --- a/src/esx/esx_vi.c
> +++ b/src/esx/esx_vi.c

> @@ -1251,8 +1253,29 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
>      curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDS, request);
>      curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDSIZE, strlen(request));
>
> +    if (!STRPREFIX(apiVersion, "2.5")) {
> +        origHeader = ctx->curl->headers;
> +
> +        virBufferAsprintf(&buffer, "SOAPAction: \"urn:vim25/%s\"", apiVersion);
> +        versionHeader = virBufferContentAndReset(&buffer);
> +
> +        ctx->curl->headers = curl_slist_append(ctx->curl->headers,
> +                                               versionHeader);
> +        curl_easy_setopt(ctx->curl->handle, CURLOPT_HTTPHEADER,
> +                         ctx->curl->headers);
> +    }
> +
>      (*response)->responseCode = esxVI_CURL_Perform(ctx->curl, ctx->url);
>
> +    if (origHeader) {
> +        curl_slist_free_all(origHeader->next);
> +        origHeader->next = NULL;
> +
> +        ctx->curl->headers = origHeader;
> +        curl_easy_setopt(ctx->curl->handle, CURLOPT_HTTPHEADER,
> +                         ctx->curl->headers);
> +    }
> +
>      virMutexUnlock(&ctx->curl->lock);

This works but is inefficient if you do many calls to non-2.5
functions. I the context of this series this is okay as you're only
calling a single non-2.5 function.

As a more general approach I would add multiple header lists to the
esxVI_CURL struct, one for each API version we want to call. Also the
esxVI_CURL struct would keep that of which header list is currently in
use. Then esxVI_Context_Execute would only have to change the used
header list if the API version is different from the last call. The
header lists for the different API version would be created beforehand
and not in esxVI_Context_Execute.

-- 
Matthias Bolte
http://photron.blogspot.com




More information about the libvir-list mailing list