2014-03-31 15:46 GMT+02:00 Michal Privoznik <mprivozn(a)redhat.com>:
On 30.03.2014 21:03, Matthias Bolte wrote:
>
> This implementation uses the
https://esx-server/screen?id=<id> way to get
> a screenshot of a running domain. Compared to the CreateScreenshot_Task
> way this works since ESX 2.5 while CreateScreenshot_Task was added in
> version 4.0.
>
> The newly added libcurl stream driver is used to directly provide the
> downloaded data without saving it to a temporary file first.
> ---
> src/esx/esx_driver.c | 120
> +++++++++++++++++++++++++++++++++++++++++++++++++-
> src/esx/esx_private.h | 1 +
> 2 files changed, 120 insertions(+), 1 deletion(-)
>
> +static char *
> +esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
> + unsigned int screen, unsigned int flags)
> +{
> + char *mimeType = NULL;
> + esxPrivate *priv = domain->conn->privateData;
> + esxVI_Boolean supportsScreenshot = esxVI_Boolean_Undefined;
> + esxVI_String *propertyNameList = NULL;
> + esxVI_ObjectContent *virtualMachine = NULL;
> + esxVI_VirtualMachinePowerState powerState;
> + virBuffer buffer = VIR_BUFFER_INITIALIZER;
> + char *url = NULL;
> +
> + virCheckFlags(0, NULL);
> +
> + if (screen != 0) {
> + virReportError(VIR_ERR_INVALID_ARG, "%s",
> + _("Screen cannot be selected"));
> + return NULL;
> + }
> +
> + supportsScreenshot = esxSupportsScreenshot(priv);
> +
> + if (supportsScreenshot == esxVI_Boolean_Undefined)
> + return NULL;
> +
> + if (supportsScreenshot != esxVI_Boolean_True) {
> + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> + _("Screenshot feature is unsupported"));
> + return NULL;
> + }
> +
> + if (esxVI_EnsureSession(priv->primary) < 0)
> + return NULL;
> +
> + if (esxVI_String_AppendValueToList(&propertyNameList,
> + "runtime.powerState") < 0 ||
> + esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
> + propertyNameList,
> &virtualMachine,
> + esxVI_Occurrence_RequiredItem) <
> 0 ||
> + esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) <
> 0)
> + goto cleanup;
> +
> + if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) {
> + virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> + _("Domain is not powered on"));
> + goto cleanup;
> + }
> +
> + /* Build URL */
> + virBufferAsprintf(&buffer, "%s://%s:%d/screen?id=",
> priv->parsedUri->transport,
> + domain->conn->uri->server,
> domain->conn->uri->port);
> + virBufferURIEncodeString(&buffer, virtualMachine->obj->value);
> +
> + if (virBufferError(&buffer)) {
> + virReportOOMError();
> + goto cleanup;
> + }
> +
> + url = virBufferContentAndReset(&buffer);
> +
> + if (VIR_STRDUP(mimeType, "image/png") < 0)
> + goto cleanup;
> +
> + if (esxStreamOpenDownload(stream, priv, url, 0, 0) < 0) {
> + VIR_FREE(mimeType);
> + goto cleanup;
> + }
> +
> + cleanup:
> + if (!url)
> + virBufferFreeAndReset(&buffer);
The 'if' is redundant. Ether we get here with partially allocated buffer, or
buffer is already reset.
True, I removed the if.
ACK
Michal
Thanks, pushed... finally :)
--
Matthias Bolte
http://photron.blogspot.com