Toure Dunnon
Toure Dunnon

Reputation: 29

Is there a way to execute shell commands on VMWare server via PyVMomi

I am looking to take full advantage of the recently introduce pyvmomi module to further management and I would like to remove the use of ssh and convert utility calls through the API; Is this possible?

Upvotes: 3

Views: 5102

Answers (1)

YFP
YFP

Reputation: 337

Sorry for the slow reply! I found your Q looking for some info on this myself. In vSphere 5 and above there is a provision to run commands as long as you are a registered user on the system (and can abide by the authentication mechanisms).

If you are a Pythonista life is going to get semi-easy for you! There is a beautiful module called Pyvmomi - https://github.com/vmware/pyvmomi

This allows easy communication with the API of vSphere.

The steps are:

  • Create a Connection (SmartConnect) and it is wise to use an atexit to destroy!
  • Get the content from the API
  • Find the VM you want to run on
  • Create/Prepare the command
  • Fire the command
  • Verify the process is alive and get the data back

There are many samples in the community samples page at https://github.com/vmware/pyvmomi-community-samples that will wet your apitite!

I have tried getting this functionality in lower versions of vSphere but found I really had to abuse the console API - sadly that code has become propriety now so I cannot share :-(

Happy Automating! //P

Upvotes: 0

Related Questions