X_LIN
Contributor
Contributor

Install VMware Tools with VMware Sphere SDK

Can we install VMware tools with VMware Sphere SDK?

In vSphere API/SDK Documentation writes follows:

VirtualMachine includes three methods for automating installation and upgrade of VMware Tools.
MountToolsInstaller – Mounts the VMware Tools CD installer as a CD-ROM for the guest operating system. To monitor the status of the tools installallation, check GuestInfo.toolsStatus. Check GuestInfo.toolsVersionStatus and GuestInfo.toolsRunningStatus for related information.
UnmountToolsInstaller – Unmounts the VMware Tools installer CD.
UpgradeToolsTask – Performs an upgrade of VMware Tools. This method assumes VMware Tools has been installed and is running. The method takes one argument, InstallerOptions, which allows you to specify command-line options passed to the installer to modify the installation procedure for tools.
Use theToolsConfigInfo data object in VirtualMachineConfigSpec.toolsInfo property to specify the settings for the VMware Tools software running on the guest operating system.
After my test,I can only upgrade tools but can't install.
Could you give me some advice to solve this problem?
Tags (3)
X_LIN
Contributor
Contributor

Someone can solve this problem?

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

You can wrap the following instructions with a GuestOps RunProgramInGuest call. 

http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.vmtools.install.doc%2FGUID-CD6ED7DD-...

Others have also created custom installation scripts for VMware Tools that you can invoke as well.

Without VMware Tools, you won't have access to the GuestOperations API and your VM may not have proper drivers for network connectivity.  For this reason, VMware Tools are usually baked into Templates and deployed by cloning and customization.  However, if you can run some remote scripting execution, you can execute the remote installation process and reboot your VM.

For example, you could create a custom ISO image with the automated installation command in a batch file.  Then use WMI to remotely execute it (may be some permission issues, been a while).  May also be possible to use the autoplay functionality, though I know that has some caveats that may prevent an automated install.  I have some customers who run an SSHD instance on their Windows VMs for consistency between Linux VMs for remote automation.

Linux is a similar process, but you may want to rebuild your tools package and pack it into an RPM or DEB file for simplicity of install.

Most tend to incorporate the tools installation process into their OS build process or templates.  However, with a little automation and the right permissions you can remotely install them as well.

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

Could you please clarify what you are referring to by 'GuestOps' and 'RunProgramInGuest'? I am looking how to automate VMware Tools installation on Windows virtual machines using vSphere API with Perl SDK.

Thanks,

YM.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

Yes, so GuestOps lets you run scripts or progams in the GuestOS through the VMware Tools channel.  However, since you are trying to install VMware Tools, that's not an option Smiley Wink

In terms of automating the VMware Tools install, you can get more information from the vSphere 5 documentation.  There's an option for unattended installation of VMware tools in vCenter.

vSphere Documentation Center


Sorry, missed the original question.  For API invocation, I haven't tried it, but UpgradeTools_Task() may be the solution.  You'll see the installerOptions property, which is just a string command line argument.  So I would guess despite the name it will also invoke the base setup.exe (and do an install).  Never tried it myself though.  I found a reference to using it with PowerCLI (which is the same API call) for installation, so once you have your command line arguments correct, should do what you need.


Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
ymnick
Enthusiast
Enthusiast

Thank you for your response. I tried the suggested in the documentation arguments before posting my question but it didn't work, perhaps I am not doing it the right way:

$target_vm->UpgradeTools_Task('/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"');

throws the following exception:

Error: Failed to handle message: Undefined subroutine &Unexpected arguments: /S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs" at (eval 82) line 143

        VimService::build_arg_string('ARRAY(0xae34d08)', 'HASH(0xae34c88)') called at (eval 82) line 3033

        VimService::UpgradeTools_Task('VimService=HASH(0xb187868)', '_this', 'ManagedObjectReference=HASH(0xa8cb7f8)', '/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"', undef) called at .../VICommon.pm line 1699

        ViewBase::invoke('VirtualMachine=HASH(0xb4106c8)', 'UpgradeTools_Task', '/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"', undef) called at ...

        VirtualMachineOperations::UpgradeTools_Task('VirtualMachine=HASH(0xb4106c8)', '/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"') called at ...

Anything obvious I miss?

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

I think you forgot the installerOptions named parameter:

$target_vm->UpgradeTools_Task(installerOptions => qq|/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"|);

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
ymnick
Enthusiast
Enthusiast

Thanks, it doesn't fail now, but cannot install due to the following error:

Initiated VMware Tools install or upgrade

...

Cannot complete

operation because

VMware Tools is not

running in this

virtual machine.

I would expect it to install the VMware Tools if not present...

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

Yeah, afraid of that.  You'll have to use WinRM or WMI to remote execute the tools installer.  Or bake it into the Windows templates.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
ymnick
Enthusiast
Enthusiast

Understood, thanks!

Reply
0 Kudos