Hidden esxcli Command Output Formats You Probably Don’t Know

Besides the vim-cmd command I covered earlier, there is another powerful set of commands in ESXi – esxcli. As you can find from the help of the command, it covers 10 namespaces and drills down several layers down. The typical operations with the namespaces are get, set, and list. If you are familiar with REST API, you can think of the bottom level namespaces are resources.

As there are already many coverage about esxcli command, I will only talk about something hidden and can be very helpful for your administering and scripting. I only find these hidden options while playing with VMware private python APIs. Believe or not, the esxcli command is built on top of the private Python API that I had introduced not long ago. So if you need more samples on how to code against the private python API, you can check out the esxcli script. I will show you where to find the esxcli source code.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

~ # esxcli
Usage: esxcli [options]{namespace}+ {cmd}[cmd options]
Options:
--formatter=FORMATTER
Override the formatter to use for a given command. Available formatter: xml, csv, keyvalue
--debug Enable debug or internal use options
--version Display version information for the script
-?, --help Display usage information for the script
Available Namespaces:
esxcli Commands that operate on the esxcli system itself allowing users to get additional information.
fcoe VMware FCOE commands.
hardware VMKernel hardware properties and commands for configuring hardware.
iscsi VMware iSCSI commands.
network Operations that pertain to the maintenance of networking on an ESX host. This includes a wide variety of commands to manipulate virtual networking components (vswitch, portgroup, etc)as well aslocal host IP, DNS and general host networking settings.
sched VMKernel system properties and commands for configuring scheduling related functionality.
software Manage the ESXi software image and packages
storage VMware storage commands.
system VMKernel system properties and commands for configuring properties of the kernel core system.
vm A small number of operations that allow a user to Control Virtual Machine operations.

~ # esxcli
Usage: esxcli [options] {namespace}+ {cmd} [cmd options]
Options:
--formatter=FORMATTER
Override the formatter to use for a given command. Available formatter: xml, csv, keyvalue
--debug Enable debug or internal use options
--version Display version information for the script
-?, --help Display usage information for the script
Available Namespaces:
esxcli Commands that operate on the esxcli system itself allowing users to get additional information.
fcoe VMware FCOE commands.
hardware VMKernel hardware properties and commands for configuring hardware.
iscsi VMware iSCSI commands.
network Operations that pertain to the maintenance of networking on an ESX host. This includes a wide variety of commands to manipulate virtual networking components (vswitch, portgroup, etc)
as well as local host IP, DNS and general host networking settings.
sched VMKernel system properties and commands for configuring scheduling related functionality.
software Manage the ESXi software image and packages
storage VMware storage commands.
system VMKernel system properties and commands for configuring properties of the kernel core system.
vm A small number of operations that allow a user to Control Virtual Machine operations.

As it shows clearly that the esxcli command is essentially a link for the /sbin/esxcli.py Python script. I am not going to list all the source here, but Within the esxcli.py file, you would find the following lines:

The trick is to turn on the debug mode with the –debug switch in the command line. In fact, the help of the esxcli has hinted “Enable debug or internal use options,” but it does not explicitly state what these options are.

To show how different formatters work, I just use a very simple esxcli command for the version information. You can try other more complicated ones by yourself.

You may be wondering what is the big deal of these formats? The public formatters are mostly good enough for most use cases. I like the csv formatter a lot as it makes the parsing the output a lot easier. But remember that the order of fields may be different when using different formatters. So you cannot assume there is a standard order and always check the output carefully. The XML format may be very interesting for programming. If you remember what I introduced about the XML based interface for managing Cisco Nexus, this XML format makes possible similar APIs.

The private formmater for json would be very helpful if you have something written in JavaScript or Node.js. The Python formatter seems no difference from json one.

The HTML formmater is a very interesting one. For command line tool, you don’t need HTML at all. What could be usage? I will continue to discuss it for a powerful use case. Stay tuned.

NEED HELP?

My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.