简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM