VMware vSphere CLI tips & tricks with vPoller
As a sysadmin I often have the need to get information about an environment quickly and efficiently. I am sure that most of the fellow sysadmins out there also automate their daily tasks in some form of scripts and tools, which make their life easier.
In this post I will share with you some of the CLI tools I use in order to automate stuff when working in a VMware vSphere environment. Over time they’ve proven to be invaluable to me and saved me a lot of time, so hopefully it will do the same for you.
So, without further ado let’s see some VMware vSphere CLI tips & tricks, which hopefully will find it’s place in your sysadmin toolkit :)
Whetting your appetite
Let’s first see the tools we are going to talk about in this post.
As you can see from the above screenshot we have a pretty decent number of vSphere CLI tools which we can use. Now let’s see some of them in action.
Getting ‘about’ information from a vSphere host
This is how you could get the vSphere version and build numbers from a vSphere host from the command-line:
Wait, we can even request more info if we ask to:
Pretty useful, isn’t it? :)
Discovering objects in our vSphere environment
Let’s now see how we can discover various objects from our VMware vSphere environment.
This is how we can discover all datacenters for example:
What ESXi hosts do we have in our environment:
Okay, that’s good. We have one ESXi host in our environment, but what is it’s power state?
What about our datastores?
Let’s see the datastore URLs as well:
As you can see we can virtually discover any vSphere managed object in our environment. What we can also do is during discovery we can request additional properties to be collected, which I think is pretty neat.
Getting object properties from our vSphere environment
In the previous section we’ve seen how to discover various vSphere objects, but what about getting properties for a single object? Is that possible?
Sure, it is! :)
Let’s see what is the capacity and free space of our datastore1
datastore:
Okay, seems like our datastore is in good shape and is accessible.
Let’s see what is the amount of memory on our ESXi host and it’s status:
Let’s see what disks do we have on a Virtual Machine:
And what is the capacity and free space of the /storage/db
file
system:
Let’s find out on which host this Virtual Machine is running on:
And what are the datastores used by this Virtual Machine:
Let’s also check the network configuration for our Virtual Machine:
This is just a fraction of the properties you can get out of your VMware vSphere environment. For all the properties you can get please check the vSphere Web Services SDK documentation.
Do we have any events?
Let’s see what is the latest event registered in our vCenter server:
Okay, we can also see the events from our vCenter from the command-line, which I find as cool! :)
Wrapping it up
If you managed to get this far, probably you are already wondering
where to get the vcli-*
tools, so in case you thought I’ve forgotten
to mention that, you were wrong :)
The vcli-*
tools are shell aliases (or more precisely shell
functions) which are now part of the vPoller
project repository.
This is how to get the vcli-*
tools installed and ready for use:
- Go to the vPoller project at Github and get
vPoller
installed and configured - Source the
vcli.source
file which would get you the tools ready for use
$ source /path/to/py-vpoller/misc-tools/vcli.source
If you are working in a VMware vSphere environment frequently (as I
do) probably you would put the above line in your .bashrc
or
similar, so you don’t have to do it each time you need the tools.
And that was it, hope you find these tips & tricks useful! :)