VMware {code} Community
tshamul
Contributor
Contributor

create screenshot for a vm

hi.

I'm using vShpere web service SDK and i want to take a screenshot of my working vm.

I used the function CreateScreenshot_Task, the API returns that task had success, but i have no screenshot.

I have searched on the vmx folder in the ESX but it's also not there.

Maybe it's in some other place? may i set the output path (can it be on the client side?)

Thanks!

Reply
0 Kudos
13 Replies
stumpr
Virtuoso
Virtuoso

I haven't actually tried it myself, so maybe someone else can provide more hands on information but I found this:

screenshotSupported	xsd:boolean	
Indicates whether the screenshot retrival over https is supported for this host's virtual machines. If true, a screenshot can be retrieved at the HTTPS relative path /screen?id=<managed object ID of virtual machine or snapshot>. If any of the optional parameters 'top', 'left', 'bottom', and 'right' is specified, the returned image will be cropped from the rectangle with upper left corner (left, top) and bottom right corner (right - 1, bottom - 1). These values default to the top, left, bottom and right edges of the image. The client must use an authenticated session with privilege VirtualMachine.Interact.ConsoleInteract on the requested virtual machine or, in the case of a snapshot, the virtual machine associated with that snapshot.
Since VI API 2.5

I found it under hostCapability. Looks like it would be off the host you created it on, so something like: https://esxhost/screen?id=vm1 for example. Should be able to build the string with a little code.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
jbugwadia
Contributor
Contributor

Hello,

I am having the same problem and would like to find a way to retrieve the VM screenshot. The CreateScreenshot_Task returns success but I am unable to find or retrieve the screenshot file. Were you able to get this to work?

I tried the URL (e.g. https://esxhost/screen?id=vm1) but do not get back any content. The "screenshotSupported" property is enabled for the host. I also searched the on the ESX host but do not see an image file.

What is the filename and format for the screenshot? Is there a way to retrieve the screenshot using vCenter?

Thanks!

Jim

Reply
0 Kudos
lamw
Community Manager
Community Manager

Take a look at this script that captures a screenshot for a specific VM:

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
jbugwadia
Contributor
Contributor

Thanks for the pointer to the PERL script!

The script only allows execution against a ESX host. Is this SDK call not supported on vCenter? In the application I am developing, I have credentials to connect to vCenter but not the ESX host.

Jim

Reply
0 Kudos
nikitamakarov
Contributor
Contributor

What is the filename and format for the screenshot?

Screenshot will be captured as PNG image.

I've tried to take it,after the Task have been successfully executed I found following value

/vmfs/volumes/4acb13ba-589015d6-9aeb-001a6496f275/AT-WindowsXP-SP3/AT-Manager-screenshot-0.png

in

task.getTaskInfo().getResult().

Unfortunatelly I still can't retrieve image from ESX using HTTPS request.

Anybody solved that problem???

Reply
0 Kudos
abhinavkatiyar
Enthusiast
Enthusiast

Any solution?

Reply
0 Kudos
nikitamakarov
Contributor
Contributor

Any solution?

Yes, I found solution for my case.

After CreateScreenshot_Task becomes complete I invoke getResult method of the Task which returns UNC path of screenshot file on ESX host.

Then I open SFTP session to ESX, and copy screenshot.

Also I've tried to send different HTTPS request to ESX host in order to get screenshot image - no results.

The best of all would be that getResult return URL for HTTPS request or Task object should have any method for retrieving screenshot from ESX and removing scrrenshot file after retrieve.

Reply
0 Kudos
Steve_Jin
Expert
Expert

You can also try the HTTP(s) Access to download the file. For more details, check out this blog on Web Based Datastore browser:

http://www.doublecloud.org/2010/06/web-based-datastore-browser-in-vsphere/






Steve JIN

Author of VMware VI and vSphere SDK (Prentice Hall)

Creator of open source vSphere (VI) Java API(Tutorial, Testimonials, Download, Samples, Forum)

Blog: DoubleCloud.ORG ( Top 10 Best Practices,[Object Model|http://www.doublecloud.org/2010/02/object-model-of-vmware-vsphere-api-a-big-picture-in-2-minutes/],[Common Mistakes|http://www.doublecloud.org/2010/01/31/common-mistakes-using-vmware-vi-and-vsphere-sdk/], Tiny REST API, Cloud Application Architecture)

Twitter: @sjin2008

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
nikitamakarov
Contributor
Contributor

Steve, thanks for reply, your blog is really helpfull for me.

But what is about retrieving screenshot in way described in javadoc of Web Service SDK:

If true, a screenshot can be retrieved at the HTTPS relative path /screen?id=<managed object ID of v...

What "managed object ID of VM oк snapshot" i should pass ???

Reply
0 Kudos
Steve_Jin
Expert
Expert

Normally the managed object id is the value of the ManagedObjectReference referring to a managed object. In your case, it's the value of MOR to a VM or a snapshot.

Steve JIN

Author of VMware VI and vSphere SDK (Prentice Hall)

Creator of open source vSphere (VI) Java API(Tutorial, Testimonials, Download, Samples, Forum)

Blog: DoubleCloud.ORG ( Top 10 Best Practices,[Object Model|http://www.doublecloud.org/2010/02/object-model-of-vmware-vsphere-api-a-big-picture-in-2-minutes/],[Common Mistakes|http://www.doublecloud.org/2010/01/31/common-mistakes-using-vmware-vi-and-vsphere-sdk/], Tiny REST API, Cloud Application Architecture)

Twitter: @sjin2008

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
nikitamakarov
Contributor
Contributor

Thanks a lot, it works. vm.getMOR().getVal() returned ID of VM and https://esxhost/screen?id=ID returned screenshot.

Reply
0 Kudos
mbutler
Contributor
Contributor

I tried all the solutions above but it doesn't work for me.

What I'm trying to do is download the captured image so I can show it locally but I can't find a way of doing that using soap

When using the https://esxhost/screen?id=xxx, it is asking for the username and password.

Any idea ???

Thanks

Reply
0 Kudos
Steve_Jin
Expert
Expert

Very detailed info is here:

http://www.doublecloud.org/2010/09/really-easy-ways-to-capture-vm-screenshot/

Steve Jin, author of VMware VI and vSphere SDK, creator of VI (vSphere) Java API (http://vijava.sf.net)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos