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
GearMesh says
No way. This is incredible. Not that I need it but worth playing with in the lab.
Dennis Wieringa says
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.