Any actual Python libraries to work with VmWare VIX API? - python

Anybody here uses such a library? Or using ctypes with VIX API dll is enough for the task of managing VMWare images?
What do you think and what you can suggest based on your experience? Is there any active and up-to-date solution written in Python?

I'd recommend the official library released by VMware instead: pyVmomi. It mirrors the vSphere Web Services SDK and works in Python 2 or 3.
There's a discussion here: What is the Difference between PySphere and PyVmomi?

It seems that pysphere, vix fit.
It's updated to the last version of VMware API, and it's been developed and maintainted for a while now.
Even though for really complex scripts you should use the official bindings for powershell: VMWare PowerCLI.

If your VirtualMachine objects are part of a vSphere environment you should use pyVmomi and use the GuestOperations. VIX has actually been deprecated from vSphere https://www.vmware.com/support/developer/vix-api/VIX-1.14-ReleaseNotes.html#Deprecate and should really only be used for Fusion or Workstation.

I used ctypesgen to generate a ctypes wrapper for the VIX dylib and wrote some helper classes (Host, VM, Job, etc.). I use it to revert VMs to named snapshots and run scripts in the guest.

Related

python library which can be used for vSphere WS SDK

I am looking for a python library which can be used for accessing vSphere WS SDK. I have came across two which are having non GPL license:
psphere - https://github.com/jkinred/psphere
pysphere - https://code.google.com/p/pysphere/
Has anybody used these in production. I do not want these for test automation but for a product which could go on a scale of upto 25K VMs.
I saw this post Python - VMWare vSphere (WEB SDK) - SUDS. But there he seems to be using it for test automation only. Also I am not only looking for VM operations but also other objects like Host, Cluster, PortGroup, vDS etc.
Regards,
Litty
VMware has published an initial release of their vSphere SDK for Python two weeks ago: pyVmomi
I don't know psphere or pysphere but I've used Suds to access the vSphere Web Services. Worked pretty well.
The vSphere WS API is SOAP based and,to the best of my knowledge, exposes everything that's possible via vCenter. It's a bit tricky sometimes, but you can do it.
I don't know what you try to achieve but you should be able to do it with Suds. Of course, you'd have to familiarize yourself with the API: vSphere Web Services SDK
At the moment, we're playing around a bit with vCenter Orchestrator. It's a nice tool (since 5.0). Maybe that's an option for you, too.

libspotify Python package for calling Spotify api?

I'm building an app that needs to get artwork information out of the libspotify Spotify API.
I'm building the app in python on google appengine. Does anyone know of a package that will enable me to access the libspotify API? The official page is C and I've googled around to try and find a suitable wrapper but can't seem to find one.
Thanks
Tom
There is also https://github.com/mopidy/pyspotify which is actively used in some applications and up to date.
I don't think you will be able to call libspotify at all. From the docs:
"The Python interpreter runs in a secured "sandbox" environment to isolate your application for service and security. The interpreter can run any Python code, including Python modules you include with your application, as well as the Python standard library. The interpreter cannot load Python modules with C code; it is a "pure" Python environment."
Check Spotimeta
http://pypi.python.org/pypi/spotimeta/

What is the advantage of using Python Virtualbox API?

what is the advantage of using a python virtualbox API instead of using XPCOM?
The advantage is that pyvb is lot easier to work with.
On the contrary the documentation for the python API of XPCOM doesn't exist, and the API is not pythonic at all. You can't do introspection to find methods/attributes of an object, etc. So you have to check the C++ source to find how it works or some python scripts already written (like vboxshell.py and VBoxWebSrv.py).
On the other hand pyvb is really just python wrapper that call VirtuaBoxManager on the command line. I don't know if it's a real disadvantage or not?
I would generally recommend against either one. If you need to use virtualization programmatically, take a look at libvirt, which gives you cross platform and cross hypervisor support; which lets you do kvm/xen/vz/vmware later on.
That said, the SOAP api is using two extra abstraction layers (the client and server side of the HTTP transaction), which is pretty clearly then just calling the XPCOM interface.
If you need local host only support, use XPCOM. The extra indirection of libvirt/SOAP doesn't help you.
If you need to access virtualbox on a various hosts across multiple client machines, use SOAP or libvirt
If you want cross platform support, or to run your code on Linux, use libvirt.
From sun's site on VirtualBox python APIs:
SOAP allows to control remote VMs over
HTTP, while XPCOM is much more
high-performing and exposes certain
functionality not available with SOAP.
They use very different technologies
(SOAP is procedural, while XPCOM is
OOP), but as it is ultimately API to
the same functionality of the
VirtualBox, we kept in bindings
original semantics, so other that
connection establishment, code could
be written in such a way that people
may not care what communication
channel with VirtualBox instance is
used.
From that article, I'm having trouble seeing the difference between "python virtualbox API" and "XPCOM". Could you provide a link to the API you're thinking of?

Communication between Windows Client and Linux Server

I want to provide my colleagues with an interface (using Windows Forms or WPF) to control the states of virtual machines (KVM based) on a linux host. On the command line of this server, I'm using a tool, called libvirt, which provides python bindings to access its functionality.
What whould be the best pratice to remotely access several function like libvirt or reading logfiles on the server. I thought about a REST Full Webservice generated by Python. Are there other viable options to consider?
Thanks,
Henrik
I'd develop an intranet web application, using any python web framework of choice.
That way you don't have to develop/install software on your client. They just point the browser and it works.
Because you are using a server-side tool that has Python bindings, you should give a serious look at PYRO which is a Python RPC library.
http://pyro.sourceforge.net/
To use this you would also have to use Python on the client, but that shouldn't be a problem. If you haven't start writing your client, then you could do it all in IronPython. Or, if you need to add this to an already existing client, then you could still bind in either IronPython or CPython as an embedded scripting engine.
For more on PYRO and Ironpython, see this wiki page http://www.razorvine.net/python/PyroAndIronpython
Proxmox VE is a complete solution to manage KVM (and OpenVZ) based virtual machines, including a comprehensive web console, so maybe you can get a full solution without developing anything?

Setup Python environment on Windows

How do I setup a Python environment on windows computer so I can start writing and running Python scripts, is there an install bundle? Also which database should i use?
I should of mentioned that I am using this for web based applications. Does it require apache? or does it use another http server? What is the standard setup for Python running web apps?
Download the Python 2.6 Windows installer from python.org (direct link). If you're just learning, use the included SQLite library so you don't have to fiddle with database servers.
Most web development frameworks (Django, Turbogears, etc) come with a built-in webserver command that runs on the local computer without Apache.
Bundle: go with Activestate's Python, which bundles many useful win32-related libraries. It has no version 2.6 yet, but most code you'll find online refers to 2.5 and lower anyway.
Database: any of the popular open-source DBs are simple to configure. But as John already suggested, for simple beginning stuff just use SQLite which already comes bundled with Python.
Web server: depends on the scale. You can configure Apache, yes, but for trying simple things the following is a quite complete web server in Python that will also serve CGI scripts writte in Python:
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["/cgi"]
PORT = 9999
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
I strongly recommend ActiveState Python for python on windows development. It comes with Win32Com and various other goodies, has a mature and clean installer, a chm version of the docs and works really well. I use this all of the time.
As for a database, Activestate comes with odbc support, which plays very nicely with SQL server. I've also had it working with Sybase and DB2/400 (although the connection strings for the latter tend to be rather convoluted). For Oracle, I recommend CX_Oracle as the best interface library. Native drivers for most proprietary and open-source databases (such as MySQL and PostGreSQL) also exist. Recent versions of Python (from 2.5 onwards IIRC) come with SQLite bundled as standard.
Don't forget to install pywin32 after installing the official (command line) installer. This will define additional start menu items and the highly useful PythonWin IDE.
An installer for both is available at Activestate (no 2.6 yet). The Activestate distribution contains additional documentation.
Might I suggest taking a look at Karrigell? It's really a nice Python web framework if you don't require everything Django and Turbogears offers. It might be easier for you to work with web frameworks until you get comfortable with them.
For development, I recommend downloading the latest SPE IDE. It should provide you nearly all the tools you will need, plus it includes wxGlade for GUI development.
Django tutorial How to install Django provides a good example how a web-development Python environment may look.

Categories

Resources