@PSUStevens headshot

@PSUStevens blog

You are reading the blog of @PSUStevens.
You can reach me through one of the social accounts below.

Did you know about vCenter API Commands?

In this post I'm going to cover the vCenter API Commands. These API Commands are accessible from the vCenter CLI. Intrigued? Read on...

PSUStevens

5 minutes read

I recently wrote about a little issue where I had to quickly get my lab hosts and vCenter upgraded to vSphere 7.0U3k luckily vSphere Lifecycle Manager saved me. During that process I discovered in vCenter there are a bunch of API calls you can make directly from the CLI once you SSH into vCenter.

When you SSH into vCenter you are prompted with serveral help commands:

  • List APIs: “help api list”
  • List Plugins: “help pi list”
  • Launch BASH: “shell”

Generally, I breeze right by this and type “shell” and move on to the task at hand.

During my recent debacle I decided to investigate the “APIs.” You see, I was unable to make certain changes to vCenter because of a weird issue that miraculously fixed itself during the upgrade. I’ll write about how I got around the issue in a separate post. For now, let’s stay focused on the “APIs” in the text menu after logging into vCenter.

Before I continue, I want to refer you to descriptions about all the API commands for both vCenter 7 and 8. Click on the URLs below for your version of vCenter to learn more.

vCenter 7.0 API Commands

https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vcenter.configuration.doc/GUID-CCC172CB-7CCB-41E4-B46A-0B5876E24EF5.html

vCenter 8.0 API Commands

https://docs.vmware.com/en/VMware-vSphere/8.0/vsphere-vcenter-configuration/GUID-CCC172CB-7CCB-41E4-B46A-0B5876E24EF5.html

Let’s get back to it. After logging into vCenter using SSH type the following command:

help api list

You will see a very long list of API commands in table format. I have included a very abbreviated version of the table below:

API Command Description
com.vmware.appliance.health.applmgmt.get Get the health of the applmgmt service.
com.vmware.appliance.health.databasestorage.get Get the health of the database storage.
com.vmware.appliance.health.load.get Get the CPU load health.
. .
. .
com.vmware.appliance.version1.system.version.get Get the version of the appliance.
com.vmware.appliance.version1.timesync.get Get the time synchronization configuration.
com.vmware.appliance.version1.timesync.set Set the time synchronization configuration.

By now your probably thinking, so what? How do I use this information to my advantage? Great question! Enter the following command on the command line:

api com.vmware.appliance.version1.networking.dns.servers.get

You should see something similar to the following output:

Config: 
   Mode: static
   Servers: 192.168.124.31 192.168.124.32

This API command retrieves or gets (note the term “get” at the end of the call) the DNS servers you have configured for the vCenter appliance.

Try another API call.
Let’s get the version of code running in the appliance. Enter the following command on the command line:

api com.vmware.appliance.version1.system.version.get

Here is what my output looks like:

Version:
   Version: 7.0.3.01200
   Product: VMware vCenter Server
   Build: 20990077
   Type: vCenter Server with an embedded Platform Services Controller
   Summary: Patch for VMware vCenter Server 7.0
   Releasedate: December 22, 2022
   Installtime: 2023-02-22T00:09:11.184Z

You can see I am running 7.0U3j. At the time of this post there is no 7.0U3k update for vCenter, just ESXi. How did I glean that version number from the cryptic information returned by the API call? Go here to map the vCenter build number to the version number:

Build numbers and versions of VMware vCenter Server (2143838)

You can use this link to figure out the same thing for ESXi:

Build numbers and versions of VMware ESXi/ESX (2143832)

One last link. Here is a link for several other VMware products:

Correlating build numbers and versions of VMware products (1014508)

Apologies for digressing about build numbers and versions of VMware products.

API calls for retrieving or “get"ting information is nice. But what if you want to change a setting? It’s pretty simple find a call with the word “set” at the end of it. Let’s go change or set the DNS server settings for vCenter.

Look through the list of calls and find this API call:

com.vmware.appliance.version1.networking.dns.servers.set

For “set” API calls you will need to supply some information. Run the following command to figure what information is required.

help api com.vmware.appliance.version1.networking.dns.servers.set

The output from the call will look like this:

Usage:
         com.vmware.appliance.version1.networking.dns.servers.set
         [--help/-h] --mode ENUM --servers STR
Description:
         Set the DNS server configuration. If you set the mode
         argument to "DHCP", a DHCP refresh is forced.
Input Arguments:
 --mode ENUM
         Define how to determine the DNS servers. Leave the servers
         argument empty if the mode argument is "DHCP". Set the
         servers argument to a comma-separated list of DNS servers if
         the mode argument is "static". The DNS server are assigned
         from the specified list. 'static': ' DNS address is static.
         ', 'dhcp': ' DNS address is automatically assigned by a DHCP
         server. '
 --servers STR
         List of the currently used DNS servers.

I know my DNS server setting is static because this information was returned when I retrieved the DNS server setting. This means for the ENUM argument I’ll use ‘static’ and the list of servers I want to use are, “192.168.124.31”

The command looks like this:

api com.vmware.appliance.version1.networking.dns.servers.set --mode static --servers "192.168.124.31"

If I had mistyped any of the arguments or misformatted the arguments I would have received an error. Let’s confirm the new setting. Run the DNS get command I issued at the beginning of this post for comparison. You will see I’m now short a DNS server.

Config:
   Mode: static
   Servers: 192.168.124.31

If I want to add the second DNS server I don’t need to use the ADD command. I can run the following command:

api com.vmware.appliance.version1.networking.dns.servers.add --server "192.168.124.32"

Voila! I am back to where I started. I can run the DNS Servers get command to confirm this is true.

The entire point of this article was to introduce you, at a very basic level of how to use APIs and how you as a non-programmer/non-DevOps person can use them for getting and setting configuration changes in vCenter. This is also easier than trying to figure out how to change the DNS server in some mystery file under the covers or when the vCenter GUI isn’t cooperating with you.

I hope this post has helped you.

If there is something you think I’m missing and feel should be added, please let me know.

Thanks for reading!

Recent posts

See more

Categories

About

This is my personal blog about technical topics including virtualization, storage, networking, backups, and some random IT stuff that strikes my fancy.