How To Use VMware Datacenter CLI (DCLI)

How To Use VMware Datacenter CLI (DCLI)

VMware Datacenter CLI (DCLI) is a newly released command line interface which can be interact with the vCenter Server. It directly work with the vSphere Automation API (REST API). Accessing the tool and usage is quite easy, and I thought to explain the steps of using this wonderful tool in this post.

VMware Datacenter CLI (DCLI) operate in two modes, interactive and scripting mode. While interactive mode provides suggested commands which makes your life more easier, scripting mode allows you to run the scripts and commands against the vCenter Server.

To getting started with the VMware Datacenter CLI (DCLI) tool, you need to open a ssh session to the vCenter Server. Let’s see how to use VMware Datacenter CLI (DCLI) tool in these modes separately.

How To Use VMware Datacenter CLI (DCLI) In Interactive Mode

To begin, start the command with “dcli +interactive” to specify the shell which you are going to use. You can directly open a ssh session to the vCenter server and start the interactive shell with dcli.

For example, to work directly with a ssh session to the server execute the below command. This will work both with “bash” and “appliancesh” shells.

dcli +interactive

Datacenter CLI (DCLI) : Directly on the vCenter server ssh session

If you are using a remote session you can specify the server as below. Here I used “+skip-server-verification” option to avoid the security warning at the login

dcli +server [server IP or FQDN] +skip-server-verification +interactive

Datacenter CLI (DCLI) : connect remotely to a vCenter server

once you successfully logged in to the dcli console prompt will automatically change in to “dcli>” prompt. The importance of this interactive mode is it will suggest the command you enter and it is really easy to build the command with relevant parameters. It has less likelyhood of going wrong and you don’t need to keep the commands in mind, I’d say it is really useful for the sysadmins who did not come from the coding background.

Datacenter CLI (DCLI) : Command will appear

Hit space to get the available commanding options under any command, a drop down will appear and it will list the available options

Datacenter CLI (DCLI) : space to get the list of commands

Relevant credentials must be used to run a query against the vCenter server and do not confused this with the root credentials as you need to specify an account which as some vSphere level privileges. It’s obvious you are getting information in the inventory, but I have noticed some people still going wrong with the root credentials. Also, there is an option to store the credentials in the store for future usage, it’s your choice to store or not the credentials. Output will display in a very convenient way as below along with the relevant object IDs.

Datacenter CLI (DCLI) : Store credentials

Filtering options are available and you need to specify the object ID to filter the output. Filtering options will be displayed as below

Datacenter CLI (DCLI) : Filters

Specify the object IDs to filter the output

Datacenter CLI (DCLI) : Filter output

Also, you can filter the output with the names using “–names” flag. Here I have filtered my resource pools which are contain “Resources” in the name

Datacenter CLI (DCLI) : Filter using names

Please note that if you have a very large inventory and resources you might not get the entire list of resources as it has some limit in displaying the output. You need to use filters in order to reduce the output size. Here I have run a command to display the entire Virtual Machine inventory which has large number of Virtual Machines.

Datacenter CLI (DCLI) :  Too large

How To Use VMware Datacenter CLI (DCLI) In Scripting Mode

To work with the DCLI Scripting mode provide the full command along with “com” at the beginning, in this mode it does not provide the suggestions to run the command. I ran the below command to view the appliance version in the scripting mode

dcli +server [IP or FQDN of the vCenter Server] +skip-server-verification com vmware appliance system version get

Datacenter CLI (DCLI) : Scripting mode command

I have tested it with a bash script and it’s perfectly working as I expected and we need to specify the command with “com” flag at the beginning

Datacenter CLI (DCLI) :  with a script

VMware Datacenter CLI (DCLI) Formatting

Datacenter CLI (DCLI) provide some formatting options for the output such as csv, html, json, simple, table, xml. You can specify the output format along with “+formatter” flag

Datacenter CLI (DCLI) : Formatting Options

Here is a sample output for a Virtual Machine CPU configuration

Datacenter CLI (DCLI) :  Output formats

VMware Datacenter CLI (DCLI) Credential Store

VMware Datacenter CLI (DCLI) can be stored in a Credentail store for the repeated access to the vCenter server. Credential List can be viewed with “+credstore-list” command and can be used to add, specify from a file or remove

Here is the output of “+credstore-list” command

How To Get The Help Of VMware Datacenter CLI commands

It’s quite easy, just specify, “dcli –help” to view the available options and commands

Article Short Link:

If You Found This Post As Useful Please Rate The Post And Share It!

Click to rate this post!
[Total: 13 Average: 4.7]

Leave a Reply

Your email address will not be published. Required fields are marked *