Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vsphere API Script for getting Information

I am playing with the vSphere API and it worked good over the Web Interface, now I would like to write a Python Script that communicates with the API and give me some answers to my question like how many VM´s do I have in my Environment or which VM is currently running, for that I need to pass my Username and password to enter the vCenter, and ask the vCenter this questions, have somebody already did it this? and have the code for me or somebody a idea for fixing this problem?

like image 925
Daniel Moreira Avatar asked Dec 21 '25 21:12

Daniel Moreira


1 Answers

Are you using an SDK to connect to the vCenter server?

  • vSphere Automation SDK for Python guide - Authentication: https://code.vmware.com/docs/7327/vmware-vsphere-automation-sdks-programming-guide-6-7-update-1#/doc/GUID-FBE84F97-5AAC-4D08-9727-299CCC22C300.html
  • pyvmomi SDK - Sample to retrieve VMs: https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/get_vm_names.py

Here's a sample to use Python to interact directly with the REST service, instead of an SDK: https://blog.dchidell.com/2016/11/23/vcenter-6-5-rest-api-w-python/

like image 76
Kyle Ruddy Avatar answered Dec 23 '25 10:12

Kyle Ruddy