WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • 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

  • 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
  • Quick Tip - Correlating VMFS Datastore to Storage Device Using ESXCLI

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

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC) across Private, Hybrid and Public Cloud

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • vSphere Code Capture is your ChatGPT for vSphere Automation 11/30/2023
  • ESXi 8.0 Update 2 not detecting Apple NVMe on Apple Mac Mini 2018 11/28/2023
  • Is there a vSphere REST API for ... 11/21/2023
  • Custom vSAN HCL JSON for VMware Cloud Foundation (VCF) 5.1 and vSAN ESA using Nested ESXi 11/20/2023
  • Heads Up - Performance Impact with VMware Workstation on Windows 11 with Intel Hybrid CPUs 11/19/2023

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 © 2023