Send a Tweet Directly from a VMware ESXi Host

For my VMworld 2016 breakout sessions this year, I wanted to demonstrate new functionality that was added to Auto Deploy.  After exploring a few ideas, I settled on leveraging the new Script Bundle feature to send a post-boot tweet directly from stateless ESXi hosts.  I figured sending a tweet would be an effective way to highlight the ability to integrate with arbitrary REST-based services. Interestingly, I ran into someone recently who was part of a DevOps team that used a private Twitter account for posting various alerts for the group to see – so it’s not as far-fetched as it seems!

I heard you like tweeting about vSphere.

Below is a Python script that can send a tweet directly from the console of a VMware ESXi 6.0 host.  vCenter Server 6.5 with Auto Deploy supports multiple versions of ESXi, and I chose to use 6.0 here.  Note that ESXi 6.5 includes Python 3, so this script would need some modification to work with that release.  I got a head start on the functionality by taking some ideas from Chris Wood.

In order to authenticate with Twitter, it is first necessary to visit the Twitter App Management portal to generate a consumer key and access token.  Plug them into the script accordingly.

The script accepts one argument: a string, wrapped in quotes, that will be posted to your Twitter timeline.

./tweet_from_esxi.py "Sent from an ESXi host"

The demo I ran at the INF8920 breakout session was slightly different because scripts cannot accept arguments in that case. Hopefully the recording will eventually be posted on the VMworld site, but the fate is unclear at the moment.

For more information on the Script Bundle feature, check out William Lam’s recent post on the topic.

Tags: ,