Comparison of Python VMware vSphere client libraries

I recently had the need to manage VMware vSphere from Python code so I went about looking for examples and open source libraries. The vCenter management server has a SOAP web service that exposes most (if not all) of the administrative capabilities that you can perform on vSphere. At first thought, this seemed like a simple endeavor. However once I got into it I found it not as simple as interacting with a RESTful web service.

The first thing I had to do is setup a vSphere test environment. More details on this in another blog post, but basically I created a login at My VMware and downloaded a 60 day trial of the vSphere hypervisor and vCenter.

Next I went searching for Python client libraries for the vSphere SOAP web service.

Here is a summary of what I found:

  • psphere – pure Python library  for the vSphere SDK by Jonathan Kinred
  • pyvisdk – pure Python library  for the vSphere SDK by Eric Plaster
  • pysphere – pure Python library  for the vSphere SDK by Sebastian Tello
  • vijava – vSphere Java api by Steve Jin extended to Python with the Jython interpreter

Here are some details on each:

psphere

source: https://github.com/jkinred/psphere

docs: http://psphere.readthedocs.org/

irc: #psphere on Freenode

mailing list or forum: https://groups.google.com/forum/?fromgroups#!forum/psphere

Psphere is a pure Python library which uses the Suds client Python library to communicate via SOAP. It is actively maintained with activity picking up the summer of 2012. Recently moved from Bitbucket to Github which is nice. Also recently create an irc channel on freenode. Apache 2.0 license.

Advantages

  • Actively maintained
  • Good author response, acknowledges shortcomings and wants to work with the community to resolve them
  • Very easy to work with
  • Fast once initial connection is made
  • Decent user base

Disadvantages

  • “Compiles” WDSL on every connection made
  • CPU and memory footprint is large (see benchmarks)
  • Need more and more examples

pyvisdk

source: https://github.com/xuru/pyvisdk

docs: http://xuru.github.com/pyvisdk/

irc: n/a

mailing list or forum: none I could find

Another pure Python library that uses Suds for the SOAP client. The author recognizes psphere for giving him some idea on how to communicate with vSphere. Also on Github. MIT license. Also actively maintained.

Advantages

  • Pretty easy to code with

Disadvantages

  • “Compiles” WDSL on every connection made
  • Slowest of the pure Python libraries
  • Really high memory and cpu footprint

pysphere  

source: https://code.google.com/p/pysphere/source/checkout

docs: https://code.google.com/p/pysphere/wiki/TableOfContents

irc: n/a

mailing list or forum: https://groups.google.com/forum/?fromgroups=#!forum/pysphere

Pysphere seems to be the oldest of the pure Python libraries, released into the open source world in 2011. It uses a fork of the ZSI Soap library for the Soap client layer. Seems to be actively maintained. Source is on the Google Code site which (is less than optimal for forking). BSD license.

Advantages

  • Actively maintained
  • Pretty easy to work with
  • Fastest of the pure Python libraries
  • Lowest memory and cpu footprint

Disadvantages

  • “Compiles” WDSL on every connection made

vijava 

source: http://sourceforge.net/projects/vijava/

docs: http://vijava.sourceforge.net/

irc: n/a

mailing list or forum: http://sourceforge.net/projects/vijava/forums/forum/826592

Vijava is actually a Java library that utilizes the VMware vSphere Java SDK to communicate with the web service. Vijava was created by Steve Jin while he was at VMware Labs, though the project is not officially supported by VMware.

The interesting thing is that the SOAP WSDL is “pre-loaded” as code so that it doesn’t need to be compiled at runtime. You can write Python scripts which calls vijava using the Jython interpreter. This library seems to have the largest user base but code commits are made much less frequently, usually to coincide with vSphere releases. License BSD.

Advantages

  • Fast, once the Java interpreter is running
  • Good for longer running processes

Disadvantages

  • Java interpreter is slow (IMHO) to start up
  • Not so good for small scripts or single API calls
  • Non-python software to install and configure: Java Runtime Environment, Jython
  • Have to have your Java class path set up “just right”

Examples

Let look at some sample code for each, performing the same exact task. Each script will establish a connection to the vCenter server, retrieve a list of virtual machines and  print some properties.

psphere – 0.5.2

from psphere.client import Client

from psphere.managedobjects import VirtualMachine
client = Client(“192.168.0.104”, “root”, “vmware”)
vms = VirtualMachine.all(client)
for x in vms:
    print x.config.guestFullName, x.name, x.overallStatus, x.config.template

pyvisdk – 0.9.20

from pyvisdk.vim import Vim

server = Vim(server=”192.168.0.104″)
server.login(“root”,”vmware”)
vms = server.getVirtualMachines()
for x in vms:
print x.config.guestFullName, x.name, x.overallStatus, x.config.template

pysphere – 0.1.6

from pysphere import VIServer

server = VIServer()
server.connect(“192.168.0.104”, “root”, “vmware”)
vms = server.get_registered_vms()
for x in vms:
vm = server.get_vm_by_path(x)
print vm.properties.config.guestFullName, vm.properties.name, \
vm.properties.overallStatus, vm.properties.config.template

vijava – 5.0.1

import sys
sys.path.insert(0, ‘/usr/local/lib/vijava/vijava50120120518.jar’)
sys.path.insert(0, ‘/usr/local/lib/vijava/dom4j-1.6.1.jar’)
from java.net import URL
from com.vmware.vim25.mo import *
server = ServiceInstance(URL(“https://192.168.0.104/sdk”),”root”,”vmware”, True)
rootFolder = server.getRootFolder()
vms = InventoryNavigator(rootFolder).searchManagedEntities(“VirtualMachine”);
for x in vms:
print x.config.guestFullName, x.name, x.overallStatus, x.config.template

Benchmarks
I tested the above scripts on OSX going against the vCenter appliance running inside Virtual Box. The ESX server is on the local network. There are two virtual machines returned in the results.
psphere – 8 seconds, 160M memory used
pyvisdk – 11 seconds, 550M memory
pysphere – 2 seconds, 50M memory
vijava –  5 seconds, 130M memory
Conclusion
Pysphere would seem to win the race. When I get time I will dig deeper into why the results are what they are. In the meantime please share your thoughts.
Advertisements
Leave a comment

6 Comments

  1. This posting seems to support the conclusion that pysphere is the library to use:

    http://stackoverflow.com/questions/7889762/python-vmware-vsphere-web-sdk-suds

    Reply
  2. Rothwerx

     /  May 17, 2013

    Thanks for this. I just wish I had seen this before I gave up and decided to use the Perl SDK.

    Reply
  3. Rangu

     /  August 7, 2013

    pysphere does not seem to support creation of VMs.

    Reply
  4. There is also the VMware provided Python SDK for vSphere call pyVmomi https://github.com/vmware/pyvmomi

    Reply
    • I had noticed that recently (it’s fairly new, newer than the blog post) but haven’t played with it at all.

      Reply
  1. PySphere’s Missing Pieces | Snapfiber

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: