WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / ESXCLI / Extending ESXCLI commands

Extending ESXCLI commands

05.02.2023 by William Lam // 2 Comments

Back on the first of April, I had shared the following video:


While many thought it was an April Fools's joke, that was certainly the original intention, but I also wanted the joke to be based on something realistic and not made up. Everything that you saw in that video is completely real, this was a real ESXCLI command that integrated with ChatGPT and was running on an ESXi 8.0 Update 1 release! 😊

So how did I do it?

ESXCLI was introduced back in vSphere 4.0 and from the very beginning, it has been designed to be extensible. In the early days, it only included commands from VMware but over the years, it started to include functionality from 3rd party vendors that could integrate with ESXi and the ESXCLI framework enabled these vendors to provide a consistent CLI experience for managing and configuring their solutions.

At a high level, to add a custom ESXCLI command(s), a special XML configuration file is required that describes the new namespace and the set of command(s) that maps to either a binary or script found within ESXi Shell, which is installed via ESXi VIB/Component for persistency. In fact, you can actually see a few examples by looking at the following directory /usr/lib/vmware/esxcli/ext within the ESXi Shell.

It was these examples that I came across which helped me piece together the demo that you see above. I decided to use a Python script that would talk to ChatGPT API and while the Python libraries on ESXi Shell is limited by default, I did come across this basic example HERE that provided me with a starting point. The ESXCLI framework expects the output to be formatted via XML, so that was another reason to use Python as the existing ESXCLI examples already provide XML examples that I could model after.

Step 1 - Obtain a ChatGTP API key from OpenAI by following the directions HERE.

Step 2 - Download the example esxgpt.py and update L31 with your ChatGPT API key and upload that to your ESXi host and place it under /bin/esxgpt.py

step 3 - Copy the contents below into a file called esxgpt.xml and upload that to your ESXi host and place it under /usr/lib/vmware/esxcli/ext/esxgpt.xml

<?xml version="1.0"?>
<plugin
    xmlns="http://www.vmware.com/Products/ESX/5.0/esxcli/">
    <version>1.0.0</version>
    <namespaces>
        <!-- esxcli gpt -->
        <namespace path="gpt">
            <description>ChatGPT on ESXi host.</description>
        </namespace>
    </namespaces>
    <commands>
        <!-- esxcli gpt ask -->
        <command path="gpt.ask">
            <description>Ask ChatGPT on ESXi host.</description>
            <input-spec>
                <parameter name="question" shortname="q" type="string" required="true">
                    <description>Ask ChatGPT on ESXi host.</description>
                </parameter>
            </input-spec>
            <output-spec>
                <structure typeName="Result">
                    <field name="Answer">
                        <string />
                    </field>
                </structure>
            </output-spec>
            <format-parameters>
                <formatter>table</formatter>
            </format-parameters>
            <execute>/bin/esxgpt '$val{question}'</execute>
        </command>
    </commands>
</plugin>

Step 4 - You will need to restart hostd for the changes to go into effect by running the following command:

/etc/init.d/hostd restart

Step 5 - You can now interact with ChatGPT via ESXCLI using the following command:

esxcli gpt ask -q "your question to ask"

Note: You can also manually run the Python script without going through ESXCLI to ensure everything is working correctly by running following:

esxgpt.py your question

More from my site

  • Minimum vSphere privileges to install or remove patch from ESXi
  • ESXi Advanced & Kernel Settings Reference
  • Quick Tip - ESXCLI CSV --format-param options
  • Quick Tip - Don't always assume your local HDs will be claimed correctly
  • Quick Tip - Marking an HDD as SSD or SSD as HDD in ESXi

Categories // ESXCLI, ESXi Tags // chatgpt, esxcli, ESXi

Comments

  1. *protectedGearMesh says

    05/02/2023 at 6:24 pm

    No way. This is incredible. Not that I need it but worth playing with in the lab.

    Reply
  2. *protectedDennis Wieringa says

    05/03/2023 at 1:08 pm

    After reading from the ChatGPT hack, I would definitely remove all ties with them.
    Like ESXI hasn't had enough targeting the last few times.

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • VMware Flings is now available in Free Downloads of Broadcom Support Portal (BSP) 05/19/2025
  • VMUG Connect 2025 - Minimal VMware Cloud Foundation (VCF) 5.x in a Box  05/15/2025
  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025