WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple

Having some fun with the Marvel Comics API & vSphere SDK for Python

02.10.2014 by William Lam // 2 Comments

As a child of the 80's, I still remember waking up super early on a Saturday morning to watch some of my favorite cartoons including Transformers, GI Joe, Ninja Turtles and many of the Marvel cartoon series. Last week I saw an interesting tweet from our former VMware CTO, Steve Herrod:

It looks like Marvel has just released a Marvel Comics REST API which allows developers to access the entire Marvel Comics Universe and build custom applications and websites with that data. So, you might be wondering what does this have to do with VMware and virtualization? Well, when I heard about this API, I knew I had to find a way to incorporate this into a cool VMware project.

I decided to create a sample vSphere SDK for Python (also known as pyvmomi) script that would allow a user to specify a number of random Marvel Characters to select from the Marvel database and then automatically create dummy VMs based on those names which could be used for testing. There were a variety of VMware SDK's (Perl, Ruby, PowerCLI, Java, etc) that I could have used, but I opted for the vSphere SDK for Python given my Python skills were not very strong. This also gave me a good reason to play around with our Python SDK.

There are a couple of things you will need to setup before you can use the sample script:

  1. Setup a Marvel API key
  2. Install vSphere SDK for Python, you can take a look here.
  3. Download the create_random_marvel_vms.py

Disclaimer: There is not much error handling built into the sample script, please use at your own risk.

You will need to edit the script and replace the following two variables: marvel_public_key & marvel_private_key with the API key after creating an account on Marvel's website. One thing I really like about the Marvel API and I know many other vendors also provide this which is an interactive API tester. This allows a user to explore and execute a particular API requests without writing a single line of code to get a better understanding of the results before one starts to develop their application.

To run the script, you will need to pass in the following parameters:

--host : Name of your vCenter Server (only tested with vCenter)
--user : User to login with
--password : Password for the user
--datastore : Name of the datastore in which VMs will be created in
--count : The number of Dummy VMs to create

Here is an example of running the script:

./create_random_marvel_vms.py --host vcenter --user root --password vmware --datastore mini-local-datastore-1 --count 10

As you can see from the screenshot above I have just created 10 random VMs where each name is a random Marvel character extracted using a GET request on /v1/public/characters. If we head over to our vSphere Web Client, we should now see our 10 newly created VMs which contain 1vCPU and 128MB of memory. To keep things simple, I did not add a vDisk but you can easily tweak the dummy VM configuration based on your requirements.

Disclaimer: Data provided by Marvel. © 2014 Marvel

Categories // Uncategorized Tags // createvm, marvel, python, pyVmomi, REST API, vmware

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

  • 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
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/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