This quick article has been written and assumes that you are using either the evaluation or a fully licenced copy of ESXi. as VIX will only run (fully functionally) on a 60 day evaluation or fully licensed ESXi server. Also, the guest OS will need to have had VMTools installed in order for this to work.
grab the latest set of the VIX tools from vmware.com for your architecture,ie:VMware-VIX-1.10.3-368992.x86_64.bundle.sh
run VMware-VIX-1.10.3-368992.x86_64.bundle.sh from the server you will use as your admin machine to talk to ESXi or vCenter, in my test environment I used Ubuntu 64bit 10.4 LTS, which worked great.
Once installation is complete, there are a full suite of commands that can be run against a GuestOS whilst it is ‘on’ or ‘off’, networked or not-networked.
Pull back a list of the Guests managed at that ESXi servers location ( This is a handy way of finding out all the DataStore syntax, as it has to be exact )
vmrun -T server -h https://ESXihostipaddress/sdk -u root -p passwd listRegisteredVM
This will only show the VMs that are running actively on the ESXi Host
vmrun -T server -h https://ESXihostipaddress/sdk -u root -p passwd list
vmrun -T server -h https://ESXihostipaddress/sdk -u root -p passwd -gu guestrootacct -gp guestrootpasswd readVariable “[ha-datacenter/host_DataStore] guest_VM/guest_VM.vmx” guestEnv “SHELL”
This will logon to the ESXi host and then into the VM running under the relevant Datastore, then I pass guestEnv as an command option and “SHELL” as an argument to guestEnv.
this will echo back “/bin/bash” as this is the default shell that is running on the root account on that guest.
Its also possible to manipulate files in and out of the guest, list files in directories, stop, start, clone the guest and run programs and scripts. – Using this approach you can aim towards full automation of a guest system with little need for interaction or the possibility of human error which sometimes sneaks in when your performing the same actions repeatedly.
some other command options to look at are:
writeVariable. – These are what I have found most useful in getting ESXi guest deployment fully automated. For example I used runScriptInGuest to run a network config script to automatically change the IP address of a newly cloned system, to pick the next address available in the range.
If you have an environment that requires some manual configuration after its been cloned, or maybe you just want to work towards a fully automated and managed environment, then I would definitely recommend that you give this a whirl. You can have a simple test set up in minutes to show the potential power that this tool offers you.
Matt Palmer – 16/07/2011
Edit: I’m part way reading through this awesome book on Automation of ESXi/vSphere using PowerCLI, and strongly suggest if your interested in making your admin tasks quicker and easier that you give it a go. I got it on Kindle so that I can annotate and flick to specific sections if I need to.
[amazon asin=B004V4ES7M&template=iframe image&chan=default]