2

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?

Toure Dunnon
  • 19
  • 1
  • 5

1 Answers1

1

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

Mark Segal
  • 5,427
  • 4
  • 31
  • 69
YFP
  • 331
  • 3
  • 8
  • can you be a little bit more specific? Which call does the "Create/Prepare the command"? Thanks – Johnny Feb 11 '15 at 08:22
  • Hi @Johnny - I have just seen this - If you have a look at https://github.com/ITV/vSPLAT/blob/master/vSphere.py - Line 522 - this project is something I threw together to help automated some VM deployment. Line 522 holds a function called run_a_command that should hopefully show you how to prepare your variables and get them set up to run commands on your VMs from the API. Please get back in contact if you need more :-) – YFP Feb 17 '15 at 11:01
  • can anyone help me fire a command like "ls -a" in venter vm server,python function – sumesh shetty Jun 17 '21 at 06:21