VMware {code} Community
johnofsaint
Contributor
Contributor

Manage VMWARE by python

Good morning to everybody,

I'm working to write a script python to manage a virtual machine, I choose, for example, VMware. To realize this script I need vmware's API and a library, called libvirt. Anyway, at the moment I couldn't write any line of code Smiley Sad  Who can help me?

Tags (3)
0 Kudos
5 Replies
fruers
Contributor
Contributor

You might want to try https://bitbucket.org/jkinred/psphere, a Python library which will give you access the entire vSphere Web Services SDK.

Install it:

$ pip install psphere

Get the number of CPUs a virtual machine has:

>>> from psphere.client import Client
>>> from psphere.managedobjects import VirtualMachine
>>> client = Client(server="vcenter.mydomain.com", username="Administrator", password="strong")
>>> vm = VirtualMachine.get(client, name="genesis")
>>> vm
<psphere.managedobjects.VirtualMachine object at 0xd3fbccc>
>>> print("%s has %s CPUs" % (vm.name, vm.config.hardware.numCPU))
genesis has 2 CPUs

You can find more examples in the documentation at http://packages.python.org/psphere.

Disclaimer: I am the author of psphere.

0 Kudos
stello
Contributor
Contributor

Hi John,

   I've recently released a python library for managing virtual machines. Here the project site: http://pysphere.googlecode.com

   You can find the getting started guide here: http://code.google.com/p/pysphere/wiki/GettingStarted

you can install the last stable version with easy_install or pip:

easy_install pysphere

or

pip install pysphere

regards,

Sebastian

0 Kudos
johnofsaint
Contributor
Contributor

Thank you Sebastian! I try your solution Smiley Happy

0 Kudos
NikunjB
Contributor
Contributor

Hi,

Can I use PSphere or PySphere to deploy OVF files on ESX servers.?

Please put any suitable code snippet.!

Thanks

Nikunj

0 Kudos
stello
Contributor
Contributor

Hi Nikunj,

   I know we've already discussed how to deploy OVF on pysphere's discsussion group. I'm posting the link to that thread in case someone else needs the same:

https://groups.google.com/group/pysphere/browse_thread/thread/3644cecbf19268ac

Regards,

Sebastián.

0 Kudos