By William Lam, Sr. Technical Marketing Engineer
A question that has comes up from time to time for vCloud Director is how to tell when a vApp and its associated Virtual Machines is ready for use after the initial power on operation?
If you look at the vCloud UI, the status of the Virtual Machine shows “Powered On” which is also represented in the vCloud API using the “Status” property for a Virtual Machine. However, this status does not necessarily mean the guestOS is ready, it just means that it is powered on. The Virtual Machines could still be booting up or going through their OS customization. So how might you go about determining when the guestOS is actually ready for use?
In talking to one of my fellow colleagues over in the VMware COE (Center of Excellence), Timo Sugliani, Timo came up with a pretty neat idea by leveraging the guest customization script for a Virtual Machine. The idea was to create a file within the guestOS filesystem at the end of the “Post Customization” section which could then be checked periodically to see if the guestOS has completed its customization.
To enable guest OS customization, it is a two step process in the vCloud UI:
1) Right click on the Virtual Machine and select the “Guest OS Customization” tab and check the box “Enable guest customization”.
2) Next, att the very bottom, you can then either upload a script or paste the contents of the script. The script must be either a Windows Batch script or Linux Shell script.
Below are two sample scripts that I used to test on both a Windows and Linux VM running in vCloud Director:
if [ x$1 == x”precustomization” ]; then
echo Do Precustomization tasks
elif [ x$1 == x”postcustomization” ]; then
/bin/date > /var/run/vm-is-ready
if “%1%” == “precustomization” (
echo Do precustomization tasks
) else if “%1%” == “postcustomization” (
echo %DATE% %TIME% > C:vm-is-ready
As you can see both script is pretty simple by just printing the date into a file which is stored within the guestOS.
We can also use the vCloud API by performing a PUT operation on the Virtual machine’s guestCustomizationSection. Here is an example curl call:
$ curl -i -k -H “Accept:application/*+xml;version=1.5” -H “x-vcloud-authorization: PaHt58xx53ezIKJRYXT/VGWEricT5vh7xqyZHLEgSOY=” -X PUT https://vcd/api/vApp/vm-ab10d2ab-37da-402f-9f66-277a64c19076/guestCustomizationSection/ -H “Content-Type: application/vnd.vmware.vcloud.guestCustomizationSection+xml” -d @customization-script
Here is an example of what the customization-script file looks like:
Note: You will need to ensure the script body is in UNICODE format (e.g. < > is < >)
Let’s go ahead and test this these two scripts. In my lab, I have a single vApp which contains two Virtual Machines: Windows and Linux. We will go ahead and initiate the power and see when the power operation was initiated and completed.
As you can see from the above screenshot, the power on started at 4:23 PM and completed at 4:25 PM. Now if we login to our two Virtual Machines, we should see the “vm-is-ready” file in /var/run for our Linux VM and in C: for our Windows VM:
If you take a look at the time stamp, we can see that this file is created a few minutes after vCloud Director has noted the Virtual Machines is in a powered on state. If we had an external system which could periodically monitor the Virtual Machines, we could then send an email or notification through a custom portal on when the vApp is fully ready for use. Another option is to have the script perform a “call out” to an external system such as vCenter Orchestrator on when the Virtual Machine is ready versus polling the system.
Get notification of new blog postings and more by following lamw on Twitter: @lamw