Automate VMware Tools upgrade using vCenter Orchestrator

Keeping VMware Tools up to date can be somewhat challenging as up until vSphere 5.1 installing updated version of VMware Tools requires a guest OS reboot which in many cases is not possible during normal operation hours. There is a simple solution though, in Virtual Machine settings on options tab and in VMware Tools settings there is a checkbox “Check and upgrade Tools during power cycling

CheckAndUpgradeToolsDuringPowerCycling

What this setting does, is that in case VMware Tools are out of date, and there are updated version available on ESXi host, VM will perform automatic VMware Tools update during any guest OS shutdown or startup event. I have used this feature with Windows VMs for years and it has proven to be reliable and very useful. With Linux VMs I would still go with manual VMware Tools update process, although automatic update of VMware Tools is supported on Red Hat Linux VMs.

So this is very handy feature, but this setting is not set by default, and going through all VMs in your infrastructure can be quite tedious task if done manually. Instead of clicking through all your VMs you can use an pretty simple vCenter Orchestrator workflow to configure all your Windows VMs for this.

With vSphere 5.1 vCenter Orchestrator (vCO) is configured automatically so I won’t go through all steps required for manual vCO configuration. If your vCO installation is not set up, please go through “Installing and Configuring VMware vCenter Orchestrator” document, you can get vCO up and running in no time with vSphere 5.1. Or you can leave a comment below and I will try to assist.

vCenter Orchestrator workflow

I have created a simple vCO workflow to set VMware Tools update policy to automatic for all Windows VMs in a vSphere cluster. Workflow has following steps:

  1. Get list of all VMs of a vCenter Server cluster object
  2. Loop through all VMs
  3. Check the guest OS id returned by VM object, if Windows check VMware Tools upgrade policy
  4. If Tools update policy is automatic already, skip to a next VM
  5. If Tools update policy is manual, reconfigure VM with automatic VMware Tools upgrade policy

Schema of workflow looks like this, click the image below to see it in greater detail

vco-enableVMtoolsUpgrade-schema

JavaScript used in the workflow

vCenter Orchestrator uses JavaScript as its scripting language. Usually you just need to write simple logic code which does not require much of learning if you already know any other scripting language like Perl, Python or PowerShell. I am no programmer by any means and I was able to pick necessary skills for JavaScript in few days.

More complex code like vSphere API calls can be generated automatically with help of VMware Fling Onyx. For example I used Onyx to create API call code for “Set VM Tools Update” script block in this workflow. Onyx is available at http://labs.vmware.com/flings/onyx.

Here are key parts of JavaScript code used in this workflow so you get an idea how Orchestrator scripting looks like.

NeedToSet
Custom decision object “Need to set?” script to check guest OS type and Tools upgrade policy

curVM is a VM object picked up from array of all VMs in a cluster. In that VM object you have all properties of a VM, including guest OS type.

By matching guest OS type to a keyword “windows” we are able to figure out if VM we are processing is a Windows VM or not. If guest OS type is Windows then we check its VMware Tools upgrade policy to avoid unnecessary reconfiguration operations. If VMware Tools update policy is not “upgradeAtPowerCycle” we will exit this Custom description type workflow object with return code “true” which will lead to “Set VM Tool Update” workflow object.

SetVMtoolsUpdate
“Set VM Tools Update” script object code

In this workflow object we have a code which will set VMware Tools update policy of a current VM to “upgradeAtPowerCycle”. Before we apply this configuration script will sleep for a one second to avoid sending configuration tasks to a vCenter Server with too high rate.

These are two most complex JavaScript code blocks used in this simple workflow.

How to import workflow

To install this workflow download it from a link at the end of this article. Once you have downloaded workflow file open vCO client, login to vCO server and in client select workflows tab as shown on image below

Workflows_Tab

First you need to decide where to import workflow. You can either create a new folder for imported workflows by right clicking at the top most menu item and selecting “Add folder…”, or you could import workflow to a existing folder, like “Library”.

Now right click desired folder and select “Import workflow…” and browse workflow you downloaded. Once done should have “Enable VM Tools upgrade on VM power cycle” workflow added into your workflow inventory.

NewWorkflowImported

How to execute workflows

With release of vSphere 5.1 accessibility of vCO workflows has improved a lot. Before vSphere 5.1 you had either to use vCO client or some custom interface to run workflows, in vSphere 5.1 ability to execute vCO workflows is integrated in new vSphere Web Client!

You can execute workflow from vCO client by right clicking a workflow and selecting “Start workflow…” or you can just select it and press CTRL+R. vCO client will then open a dialog window to ask necessary input parameters for a workflow. In case of workflow show here you need to select vCenter Server cluster object in which you wish to execute this workflow. To get list of cluster objects click “Not set” link and press enter in “Filter:” input box, vCO client will then search for all cluster objects and list them for you to choose.

Alternatively you can associate this workflow to a cluster object in vSphere Web Client for easy access.

Login to vSphere Web Client with administrator privileges, and click “vCenter Orchestrator” link on the left side menu.

WebClient_vCenter_Orchestrator

In next view you should see “vCO Servers: 1” on left side menu if your vCO is properly registered with VMware SSO and Web Client services. Integration is configured automatically when doing vCenter Server Simple install.

If you have vCO registered select “Manage” tab, and click green plus sign to add a new workflow association.WebClient_vCenter_Orchestrator_Manage

Next browse workflow from the tree menu on the left side, click “Add” and select “Cluster” from available type list.

WebClient_vCenter_Orchestrator_AddWorkflow

Now you have associated this workflow with vSphere cluster object, to run workflow go and right click any cluster in Web Client and select workflow from “All vCenter Orchestrator Actions” menu. Any changes made by workflow are listed in Cluster –> Monitor –> Tasks view.

WebClient_All_Orchestrator_Actions

Workflow download

Feel free to download this workflow from link below, you may use, distribute and modify it as you wish. I will not provide any guarantee that this workflow will work as intended in your environment.

http://v-reality.info/files/EnableVMToolsUpgradeOnVMPowerCycle.workflow

4 comments to Automate VMware Tools upgrade using vCenter Orchestrator

  • Henkka

    Or use PowerCLI:

    get-cluster CLUSTER_NAME_HERE | get-vm VM_NAME_HERE_OR_REMOVE_FOR_ALL_VMS | where-object {
    $_.guest.OSFullname -match “^Microsoft Windows*.”
    } | foreach-object {
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
    (Get-View $_.ID).ReconfigVM($vmConfigSpec)
    }

    • Tomi Hakala

      It is true that same can be achieved using PowerCLI. Point of this blog post is however to show capabilities of vCenter Orchestrator for people new to it.

  • tivs

    Could you help me for creating a workflow to display list of “clusters names and resource pool in that cluster in a multi vcenter environment “.

  • Shrikant Jain

    Hi,

    Thank you for such a helpful article.
    Our requirement is , whenever new VM created from available template , host name should be pre-defined and incremental manner and should take from vcloud.
    like – VM01, VM02 VM 03 …etc.

    Need your expert advice to configure the same.

    Thank you
    Regards,
    Shrikant Jain
    Duba

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">