WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Uncategorized / Automating the New Integrated VIX/Guest Operations API in vSphere 5

Automating the New Integrated VIX/Guest Operations API in vSphere 5

07.26.2011 by William Lam // 27 Comments

VMware hinted earlier this year that the future of the VIX API would eventually be integrated into the core vSphere API, it looks like the wait is finally over. With the latest release of vSphere 5, the VIX API is no longer a separate API but consolidated into the core vSphere API which allows users to perform guest level operations directly to a virtual machine that is running VMware Tools.

There is now a new managed object called GuestOperationsManager which provides functionality for Authentication (authManager), File management (fileManager) and process management (processManager). The API is actually quite easy to use as you need to first acquire a guest auth credential within the guest and then you can perform any of the various guest operations using this credential cache.

I wanted to show the power of the VIX API by creating a vSphere SDK for Perl script called guestOpsManagement.pl that implements majority of the VIX/Guest Operations for users to manage from a centralized script. You will need to have a system that has the vCLI installed or use VMware vMA and to utilize the new VIX operations, your virtual machines must have the latest VMware Tools installed.

You can download guestOpsManagement.pl script here. 

The script supports 12 different VIX Operations which are described below:

Operation Description
validate Allows a user to validate guest credentials without performing any VIX Operation
ps Performs a process listing within the guestOS
startprog Starts a program within the guestOS
kill Kills a particular process within the guestOS
ls Perorms a listing of a particular directory within the guesOS
mkdir Creates a directory within the guestOS
rmdir Removes a directory within the guestOS
rm Removes a file within the guestOS
mv Move/Rename a file within the guestOS
mvdir Move a directory within the guestOS
copyfromguest Download a file from within the guestOS to local system
copytoguest Upload a file to the guestOS from a local system
Here is an example of performing the "validate" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation validate --guestusername root

Here is an example of performing the "ps" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation ps --guestusername root

In the next example, we will kill off the "tail" process as listed above.

Here is an example of performing the "kill" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation kill --guestusername root --pid 13198

Here is an example of performing the "startprog" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation startprog --guestusername root --working_dir /root --program_path /usr/bin/touch --program_args /root/virtuallyghetto

Note: There is known vSphere SDK for Perl bug for the return value of a "long" which will be resolved in GA release of vSphere SDK for Perl 5.0. You should not see the "error" message when running this operation

Here is an example of performing the "ls" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation ls --guestusername root --filepath_src /var/log

Here is an example of performing the "mkdir" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation mkdir --guestusername root --filepath_src /tmp/virtuallyghetto

Here is an example of performing the "rmdir" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation rmdir --guestusername root --filepath_src /tmp/virtuallyghetto

Note: If you would like to perform a recursive directory delete, you will need to specify the --recursive, please use with caution

Here is an example of performing the "rm" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation rm --guestusername root --filepath_src /root/virtuallyghetto

Here is an example of performing the "mv" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation mv --guestusername root --filepath_src /root/steve_jablonsky --filepath_dst /root/hans_zimmer

Here is an example of performing the "mvdir" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation mvdir --guestusername root --filepath_src /tmp/foo --filepath_dst /tmp/bar

Here is an example of performing the "copyfromguest" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation copyfromguest --guestusername root --filepath_src /var/log/messages

Here is an example of performing the "copytoguest" operation:

./guestOpsManagement.pl --server vcenter50-1 --username root --vm vMA5 --operation copytoguest --guestusername root --filepath_src /home/vi-admin/test.pl --filepath_dst /root/test.pl

There is also complete perl docs for this script which can be called using the following command:

perldoc guestOpsManagement.pl

More from my site

  • Whitepaper: Migrating From VIX API to the vSphere Guest Operations API
  • Using PowerCLI to invoke Guest Operations API to a Nested ESXi VM
  • Automating VCSA Network Configurations For Greenfield Deployments
  • Running ESXi 5.0 & 5.1 on 2012 Mac Mini 6,2
  • Nested Virtualization Resources

Categories // Uncategorized Tags // ESXi 5.0, guest, vix, vix api, vSphere 5.0

Comments

  1. *protectedBob says

    08/19/2011 at 1:43 am

    Calling these methods in the MOB always returns "Not initialized: boolean interactiveSession"

    Here is the auth param (ListProcessesInGuest):


    MyUsername MyPassword false

    Reply
  2. *protectedWilliam says

    08/19/2011 at 2:34 am

    Are you creating a new NamePasswordAuthentication? which is then passed to any of the VIX functions? Curious on why you're going directly through the MOB versus one of the vSphere SDKs?

    Reply
  3. *protectedBob says

    08/19/2011 at 11:34 pm

    Just wanting to test it out before I put in the effort. NamePasswordAuthentication inherits from GuestAuthentication. Have you tried this from the MOB?

    Reply
  4. *protectedWilliam says

    08/20/2011 at 5:34 am

    @Bob,

    I've already created a Perl script that implements majority of the VIX operations, I would say the hard work is pretty much done 🙂 It works very well, but no I've not used the MOB test VIX operations. I only use the MOB if I have to, else I use the SDKs which is what they're there for.

    Reply
  5. *protectedTim says

    01/19/2012 at 5:15 pm

    This is a really useful script for me, now that VMware have dropped guest customisation for Ubuntu and Debian - I can use this to write a script to perform my customisations again (and do a lot more besides). However, I'm having trouble getting it to work on my vSphere 5 setup. It dies with this error:

    Can't locate object method "guestOperationsManager" via package "ServiceContent" at /usr/local/vmware/bin/guestOpsManagement.pl line 370.

    When I use a web browser to look at ServiceContent, I can see GuestOperationsManager, so it is there, but for some reason the script can't see it.

    Any ideas?

    Tim

    Reply
  6. *protectedWilliam says

    01/21/2012 at 4:31 pm

    @Tim, Are you sure you're using the latest vSphere SDK for Perl 5.0? It sounds like that might be the problem and not so much for the actual host itself.

    Reply
  7. *protectedvExpert2011 says

    03/08/2012 at 1:30 am

    Hi William, thanks for the script!

    I'm trying to iterate over all the *nix hosts to run a mkdir /tmp/vmware-root in each Guest OS - but at each iteration it is asking for the vcenter password (see community thread below) - is there a way to cache the vcenter password btw iterations or hard code it in the perl script as a workaround?

    http://communities.vmware.com/message/2003225#2003225

    thanks!

    Reply
  8. *protectedWilliam says

    03/09/2012 at 7:47 pm

    @vExpert2011 - You can easily do so by setting --password option and then use a simple "for" loop to iterate through all your VMs

    Reply
  9. *protectedWouter van Bommel says

    07/25/2012 at 6:23 pm

    Interesting topic and tried to implement some of it myself.
    I did find however, that the script only works ons a vma installation related to the function of uploaden data to a guest vm. This function simply fails with a http 500 error.

    A second issue I noticed is that vmware tools does not allocate an tty (or pty) on linux, meaning that you cannot use the sudo command.

    Any suggestions on how to tackle these problems?

    Reply
  10. *protectedJavier says

    09/05/2012 at 11:08 am

    This is working great.
    How does it handle duplicate VM names? Is there any way to specify where the TestVMName1 resides (Cluster, Host) inside the vCenter tree?

    This script can be great to configure /etc/network/interfaces and hostname on new guests.

    I've been searching for something that would allow to launch a "deploy from template" from command line, and if possible, specify guest customization options (if this is not possible, it can be easily done using guestOpsManagement anyway.) Do you know of any or accept such script suggestion?

    Thanks for this great content!

    Reply
    • *protectedWilliam says

      09/05/2012 at 3:28 pm

      @Javier,

      vCenter does not allow for duplicated VM names, so you should not have to worry about that. Regarding your customization question, today you can do basic network customization (UNIX/Linux) via the Customization process in vCenter. If you need further customization such as application or other OS configurations, I would recommend using the Guest Operations Management OR via traditional SSH

      Reply
    • *protectedJavi says

      09/06/2012 at 6:51 am

      Thanks for the quick response 🙂
      vCenter allows duplicate VM names. Just to be sure, i just created 3 VMs named "1", in different hosts, same & different datacenter.

      The problem is, having such repeated VM names, how can i specify the source (datacenter, host) to take it from?

      Regarding the customization. I already have a debian customization spec that works like a charm when deploying templates from the vsphere client (click click), however, we wanted to automate this from command. (although i am already using your great datastoredeploy + guestmgmt scripts to do it)

      Reply
    • *protectedWilliam says

      09/06/2012 at 6:58 am

      @Javier,

      Ah sorry, you're right, uniqueness is defined at the Datacenter boundary (though good rule of thumb to generate unique names or at least check if you're deploying it programmatically).

      If you want to filter a VM by Datacenter, you can use the following when searching for a VM:

      my $vm_view = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $datacenter_view);

      where $datacenter_view is Datacenter you want to search in. Recommend taking a look at the vSphere SDK for Perl docs for more details

      Reply
  11. *protectedBalu says

    03/01/2014 at 4:21 pm

    For the InitiateFileTransfer(...), the fileattributes are not populated. Is this not required ? If this field is needed, then what should be the time format ?

    Reply
    • lamw says

      03/01/2014 at 4:31 pm

      That's correct, it is not required as defined by the API reference http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.guest.FileManager.FileAttributes.html There are defaults or you can follow the specification

      Reply
  12. *protectedVikky says

    10/31/2014 at 11:44 pm

    Hi William,

    I am trying to download the guestOpsManagement.pl script but it is not available at the link you provided.
    Do you have an alternate location to download the script.

    Reply
    • William Lam says

      11/01/2014 at 12:15 am

      Try now. I've moved my scripts from SVN over to Github

      Reply

Trackbacks

  1. Automating VCSA Network Configurations For Greenfield Deployments | virtuallyGhetto says:
    02/28/2014 at 9:08 pm

    […] Windows system to access the vSphere C# Client. You can actually get around this by leveraging the GuestOperations API (previously known as VIX API) which allows you to perform operations within the guestOS that is […]

    Reply
  2. Using PowerCLI to invoke Guest Operations API to a Nested ESXi VM | virtuallyGhetto says:
    07/14/2015 at 9:05 pm

    […] my opinion, the Guest Operations API in vSphere is still one of the most powerful Virtual Machine capabilities that is available to […]

    Reply
  3. How to remotely run appliancesh & other shell commands on VCSA w/o requiring SSH? | virtuallyGhetto says:
    02/25/2016 at 7:50 am

    […] can do so by leveraging one of my all time favorite features of the vSphere Platform which is the Guest Operations API which allows you perform guest operations (running commands, transferring files, etc) directly […]

    Reply
  4. How to properly clone a Nested ESXi VM? | virtuallyGhetto says:
    10/17/2016 at 1:55 pm

    […] Nested ESXi VM and manually change the IP Address and hostname which you of course can leverage the Guest Operations API if you have VMware Tools for Nested ESXi […]

    Reply
  5. VMWare vSphere Customize linux guest with a shell script – CyberGround says:
    01/03/2018 at 7:35 am

    […] Download guestOpsManagement.pl from here. This script has written by lamw, so all credits belongs to him. You should read his full documentation about this Perl script's functions and parameters in his post here. […]

    Reply
  6. New Instant Clone Architecture in vSphere 6.7 – Part 2 says:
    07/16/2018 at 12:07 pm

    […] This steps can also be automated using either Guest Operations API (Invoke-VMScript for PowerCLI users) or using the VM keystrokes API. One thing to be aware of if […]

    Reply
  7. Quick Tip – Requirements for using Guest Operation APIs (Invoke-VMScript & Copy-VMGuestFile) in VMC says:
    08/02/2018 at 6:33 am

    […] up again today, I figure it was worth sharing in case others also had trouble using the vSphere Guest Operations API in VMware Cloud on AWS (VMC), which includes PowerCLI's Invoke-VMScript and Copy-VMGuestFile […]

    Reply
  8. vSphere 6.7 Instant Clones – Geek's Blog says:
    05/15/2019 at 2:05 am

    […] that the GuestOS will pickup the newly assigned MAC Address. This can be automated using the Guest Operations API and the process to refresh the network interface will depend on the GuestOS type. See some […]

    Reply
  9. Using PowerCLI to automate the retrieval of VCSA Password Policies says:
    02/06/2020 at 1:25 pm

    […] familiar with the extremely powerful vSphere Guest Operations API functionality (details here and here), which can easily be consumed using PowerCLI's Invoke-VMScript cmdlet. If not, highly recommend […]

    Reply
  10. Quick Tip - Using PowerCLI to query VMware Tools Configuration at scale  says:
    10/11/2024 at 6:30 am

    […] of the most powerful and versatile VM management capability in vSphere is the Guest Operations API, providing a rich set of operations from transferring files to/from the guest to running commands […]

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • VMware Flings is now available in Free Downloads of Broadcom Support Portal (BSP) 05/19/2025
  • VMUG Connect 2025 - Minimal VMware Cloud Foundation (VCF) 5.x in a Box  05/15/2025
  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025