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.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

~ # esxcli
Usage: esxcli [options] {namespace}+ {cmd} [cmd options]
                        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.

~ # which esxcli
~ # ls -l /sbin/esxcli
lrwxrwxrwx 1 root root 15 Mar 23 2013 /sbin/esxcli -> /sbin/esxcli.py

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:

      self.formatters = {
         "xml": XmlVisitor,
         "csv": CsvVisitor,
         "keyvalue": KeyValueVisitor,
      # For testing purpose
      self.debugFormatters = {
         "python": PythonVisitor,
         "json": JsonVisitor,
         "html": HtmlOutputFormatter,
         "table": TextOutputFormatter,
         "tree": TextOutputFormatter,
         "simple": TextOutputFormatter,

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.

~ # esxcli system version get
   Product: VMware ESXi
   Version: 5.1.0
   Build: Releasebuild-1065491
   Update: 1
~ # esxcli --debug --formatter=python system version get
{"Build": "Releasebuild-1065491", "Product": "VMware ESXi", "Update": "1", "Version": "5.1.0"}
~ # esxcli --debug --formatter=json system version get
{"Build": "Releasebuild-1065491", "Product": "VMware ESXi", "Update": "1", "Version": "5.1.0"}
~ # esxcli --debug --formatter=html system version get
<tr><th class="rt">Product</th><td width="90%">VMware ESXi</td></tr>
<tr><th class="rt">Version</th><td width="90%">5.1.0</td></tr>
<tr><th class="rt">Build</th><td width="90%">Releasebuild-1065491</td></tr>
<tr><th class="rt">Update</th><td width="90%">1</td></tr>
~ # esxcli --debug --formatter=table system version get
Product      Version  Build                 Update
-----------  -------  --------------------  ------
VMware ESXi  5.1.0    Releasebuild-1065491  1
~ # esxcli --debug --formatter=tree system version get
Runtime error
~ # esxcli --debug --formatter=simple system version get
   Product: VMware ESXi
   Version: 5.1.0
   Build: Releasebuild-1065491
   Update: 1
~ # esxcli --debug --formatter=xml system version get
<?xml version="1.0" encoding="utf-8"?>
<output xmlns="http://www.vmware.com/Products/ESX/5.0/esxcli">
   <structure typeName="VersionGet">
      <field name="Build">
      <field name="Product">
         <string>VMware ESXi</string>
      <field name="Update">
      <field name="Version">
~ # esxcli --debug --formatter=csv system version get
Releasebuild-1065491,VMware ESXi,1,5.1.0,
~ # esxcli --debug --formatter=keyvalue system version get
VersionGet.Product.string=VMware ESXi

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.

This entry was posted in Virtualization and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    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.