VMware {code} Community
kcreed
Contributor
Contributor
Jump to solution

GuestOperationsUnavailable

Hello,

I need to use the InitiateFileTransferToGuest method to put a file(s) on a VM(s).  I could not get my code to work (no GuestFileManager available?), so I tried to invoke the method using the MOB.  When I do that, I get a message saying, "GuestOperationsUnavailable".  Can anybody tell me what to do to make GuestOperationsAvailable?

Much Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

The pattern (the same in any language kit, but some may abstract some of the lower-level details) is the following -

gom_mor = RetrieveServiceContent().guestOperationsManager

// Some language kits require you instantiate a GuestOperationsManager object using the managed object reference provided by ServiceContent (gom)

gomfm = gom.fileManager

// This returns another moref, again some language kits handle it differently and you may not need to instantiate the object (fetch it's properties)

auth = new NamePasswordAuthentication() // subclass of GuestAuth object

auth.username = "username"

auth.password = "password"

auth.interactiveSession = false // usually false, basically should it initialize a user environment for the process

gomfm.auth = auth

moref = virtualmachineMoRef // have to get this by querying the vCenter inventory

guestFilePath = "c:/coolfile.txt"

fileAttributes = new GuestFileAttributes() // use default or set appropriately

fileSize = coolfile_bytes // important, this determines the buffer when you submit the PUT request later for the transfer

overwrite = false // who would ever want to overwite coolfile?

put_url = InitiateFileTransferToGuest(gomfm, moref, guestFilePath, fileAttributes, fileSize, overwrite)

// most language kits add this function to the gomfm itself so --

put_url = gomfm.InitiateFileTransferToGuest(moref, guestFilePath, fileAttributes, fileSize, overwrite)

Then you have to do an HTTP PUT request to that put_url, set your content-length header to the bytes you set in fileSize.  Similarly with the content-type.  Your language may have a simple PUT library that does it all for you of course, William used Perl's LWP to do the PUT.

You probably are having issues b/c you technically need to get contents of GuestOperationsManager to get the GuestFileManager, AuthManager, etc.  You can't just jump to GuestFileManager, you need the MOREF value you get from the GuestOperationsManager.guestFileManager for the InitiateFileTransferToGuest(). 

What language kit are you using for your project?

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

Reply
0 Kudos
15 Replies
lamw
Community Manager
Community Manager
Jump to solution

Take a look at the sample script here (http://www.virtuallyghetto.com/2011/07/automating-new-integrated-vixguest.html) which implements the new methods in the Guest Operations API

stumpr
Virtuoso
Virtuoso
Jump to solution

vSphere 5.0 added GuestOperations to the core API, so you can invoke those operations directly without additional libraries.

If you're targeting vSphere versions <5.0, you'll need to use the VIX API, which includes a set of libraries that have to be installed to run GuestOperations.

There were also some minor changes between VIX and GuestOperations, but both still require VMware Tools to be running in the GuestOS and use the HostSystem (not the VirtualMachine) network to run operations.  This means you can run in-GuestOS scripts through GuestOps even on a Virtual Machine with no network interfaces.

Here's a technote link for the 5.0 GuestOps - http://www.vmware.com/support/developer/vix-api/guestOps50_technote.pdf

Reuben Stump | http://www.virtuin.com | @ReubenStump
stumpr
Virtuoso
Virtuoso
Jump to solution

The pattern (the same in any language kit, but some may abstract some of the lower-level details) is the following -

gom_mor = RetrieveServiceContent().guestOperationsManager

// Some language kits require you instantiate a GuestOperationsManager object using the managed object reference provided by ServiceContent (gom)

gomfm = gom.fileManager

// This returns another moref, again some language kits handle it differently and you may not need to instantiate the object (fetch it's properties)

auth = new NamePasswordAuthentication() // subclass of GuestAuth object

auth.username = "username"

auth.password = "password"

auth.interactiveSession = false // usually false, basically should it initialize a user environment for the process

gomfm.auth = auth

moref = virtualmachineMoRef // have to get this by querying the vCenter inventory

guestFilePath = "c:/coolfile.txt"

fileAttributes = new GuestFileAttributes() // use default or set appropriately

fileSize = coolfile_bytes // important, this determines the buffer when you submit the PUT request later for the transfer

overwrite = false // who would ever want to overwite coolfile?

put_url = InitiateFileTransferToGuest(gomfm, moref, guestFilePath, fileAttributes, fileSize, overwrite)

// most language kits add this function to the gomfm itself so --

put_url = gomfm.InitiateFileTransferToGuest(moref, guestFilePath, fileAttributes, fileSize, overwrite)

Then you have to do an HTTP PUT request to that put_url, set your content-length header to the bytes you set in fileSize.  Similarly with the content-type.  Your language may have a simple PUT library that does it all for you of course, William used Perl's LWP to do the PUT.

You probably are having issues b/c you technically need to get contents of GuestOperationsManager to get the GuestFileManager, AuthManager, etc.  You can't just jump to GuestFileManager, you need the MOREF value you get from the GuestOperationsManager.guestFileManager for the InitiateFileTransferToGuest(). 

What language kit are you using for your project?

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

Thank you Reuben!  You're awesome!

I haven't tried it yet, but it looks like what I need.  I'm gonna start on it right now.

I'm using Python 2.7.2 (another first for me).

I'll let you all know how it turns out.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

So, with Python are you using low level REST calls or using Suds (or similar)?  I think you should be ok for what you want to do here, but bear in mind some more complex serialization from the SOAP don't come through completely with the SOAP parsers in Python.  I tried it in the past Smiley Sad  But you basically just need to keep retrieving morefs until you get the fileManager, then you can construct the rest. The NamePasswordAuth and FileAttributes may require a little bit of custom SOAP body construction.

Constructing TraversalSpecs to get property values can be a bit intimidating for someone new to the API.  Without a toolkit, you will probably have to call RetrievePropertiesEx to get the properties of GuestOperationsManager, which contains the ref you need for GuestFileManager.  You have a single object here and a single property you want, so you can probably fake it easily, but the SOAP body will be a few objects deep.

There are some posts on the forums around Python and PHP.  I think even some that tackle creating SOAP envelopes the hard way that might help getting properties you need Smiley Happy.  Search on PHP, similar process and some useful posts.  There is also a python vsphere module out there, but I'm not sure about the support for GuestOps/vSphere 5.

If this just a one off, you could also grab William's script, call the method you want while running a packet capture through vCenter (the Programming guide describes how to disable SSL so you can get it in clear text). 

Also, you can look into Project Onyx, which sits between the script and vCenter.  It can extract and generate code.  LucD (PowerCLI guru) posted some notes on using Onyx, which can output the SOAP IIRC.  http://www.lucd.info/2010/09/06/taking-the-new-onyx-2-0-for-a-spin/

You could possibly use Williams script to capture the steps upto a InitiateFileTransferToGuest(), save the soap envelopes and do some search/replace for the vCenter specific values.  Aagain, not pretty but might be useful and others have done similar work in the past.  However, it probably won't scale if you need a lot more vSphere API functions in your solution.

Of course, the Perl API is well documented, supported and much easier to use, but I know William and I are a lonely breed in terms of Perl Smiley Wink

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

You got it.  We're using REST, as well as Suds.  Many complexities here, so I am expecting the most complex scenario.  Yep, we're using PropertyCollector and TraversalSpecs, and I am intimidated by it all.  :smileyconfused:

Thank you (and Will.I.Am) for all of your help.  You have a lot of things for me to look into here, and I am certain that I can solve this problem, now that I have some more ammo to work with.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

What's the status of the GuestTools?  They need to be installed and running for GuestOps to work.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

Wow!  That was a speedy reply!  Thanks!

Pardon my ignorance, but are GuestTools different from VMware Tools?

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

Nope, same thing.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

Nevermind.

guestToolsRunning, guestToolsCurrent, and guestOperationsReady.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

I found this with a quick search -

http://communities.vmware.com/thread/345460?start=15&tstart=0

At the end of the thread they mentioned there is a fix coming in the next 5.0 and 5.1 update releases.

I wonder if it's related.  Someone indicated that restarting the Tools service in the guestOS got it working.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

Got it.  I'll check it out.  Thanks stumpr!

Reply
0 Kudos
kcreed
Contributor
Contributor
Jump to solution

Hey stumpr,

I don't know what happened, but it works now.  I just changed the vm_moref in the parameters to an actual instance of a vm, then changed it back.  When I did that, I got an error msg saying that a parameter was wrong.  So, I looked at the parameters and realized that I was using a Windows filepath instead of a Linux path.  Changed that and viola, InitiateFileTransferToGuest worked!  It returned a URL for me to send a PUT request to.  Now, I just have to do the PUT request.

Thanks a bunch!

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

Great, it's possible that error message is message is re-used and a little misleading. Smiley Happy

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
sayvikas
Contributor
Contributor
Jump to solution

Dear All,

I am C#, C++ programmer, and I have C++ component that was using VIX, now I want to migrate it to VSPhere ?

can someone help me what is the pre-requisite and how to call VSPhere API's.

I have read its now supporting SOAP-based calls but how actually the calls are made and what the endpoint should be if someone can explain?

Thanks,

Vikas

Reply
0 Kudos