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

Early Xmas gift from VMware - pyVmomi (vSphere SDK for Python)

12.17.2013 by William Lam // 13 Comments

For vSphere customers and partners who use the Python programming/scripting language, Christmas may have just arrived early. I just found today, VMware has published an initial release of their vSphere SDK for Python called pyVmomi on Github this past weekend. A Python-based SDK has always been a very popular feature request among customers and partners that I have spoken with in the past. It looks like VMware Engineering has heard you loud and clear and have been working hard to get this released.

pyVmomi Github Repository:
https://github.com/vmware/pyvmomi

pyVmomi Pypi package:
https://pypi.python.org/pypi/pyvmomi

One of the nice things about releasing pyVmomi on Github versus trying to package it with a particular vSphere release is that the larger VMware community can contribute to the project as well as more frequent updates from VMware. This has also been quite successful for another popular VMware SDK called rbvmomi (vSphere SDK for Ruby) which is seeing a huge uptick with RVC (Ruby vSphere Console) which is built on top of rbvmomi and is a great tool for managing and troubleshooting VMware VSAN.

In this first release, you will notice there is a limited amount documentation and samples exercising the various capabilities of vSphere and you will see further enhancements in these areas with future updates. If there are specific things you would like to see or samples that you think would be useful to have or that you have built, feel free to file an issue or send pull requests to the pyVmomi Github.

If you wish to quickly get started, you can install pyVmomi using a variety of methods including pip, easy_install and pypi package. Below are the steps I took to install pyVmomi on my Mac OS X system using pip and git.

Step 1 - Install pyVmomi using pip by running the following command:

sudo pip install pyvmomi

Step 2 - Clone the pyVmomi Github repo to your system using Git by running the following command:

git clone https://github.com/vmware/pyvmomi.git

After the above command, you will have a folder called pyVmomi which contains the source code as well as the two sample scripts. You can contribute back if you create additional samples or enhancements to pyVmomi by simply sending a pull requests.

Try the getallvms.py sample run the following command:

python sample/getallvms.py --host mini.primp-industries.com --password [PASS]

To try the poweronvm.py sample run the following command:

python sample/poweronvm.py --host mini.primp-industries.com --password [PASS] --vmname [VM]

 
Hopefully we will see many more samples from VMware as well as from our customers who will be using the new SDK. If there is anything that is missing or things you would like to see, feel free to file an issue on pyVmomi Github repository.

Categories // vSphere Tags // ESXi, pypi, python, pyVmomi, sdk, vSphere API

  • « Previous Page
  • 1
  • 2
  • 3
  • 4

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