On my list of things to try: Python with ESXi
Posted by jpluimers on 2021/10/28
After doing a lot of – historically grown – dash
scripting for ESXi, I found out there is Python
available on ESXi:
- Python 3.5.10 on VMware ESXi 6.7.0 build-17700523 (VMware ESXi 6.7.0 Update 3)
- Python 3.5.6 on VMware ESXi 6.5.0 build-13932383 (VMware ESXi 6.5.0 Update 3)
- VMware 7: to be determined.
Yes I know that Python 3.5 is end-of-life (and 3.5.10 was the latest version), but it is a lot better than shell scripts.
So now some links for my list of things to try in order to use Python
for scripting ESXi operations:
- [Wayback] virtualization – Accessing vSphere ESX/ESXi server through python – Server Fault answer by [Wayback] Yohann:
Take a look at the pyVmomi project which is the official Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi and vCenter.
Moreover, the pyvmomi-community-samples repository contains lot of examples.
- [Wayback] vmware – List all vm of ESXI, vsphere with python – Stack Overflow
Also, checkout the pyvmomi Community Samples repo. It has all kinds of great samples, including one that could fit this request: github.com/vmware/pyvmomi-community-samples/blob/master/samples/… – [Wayback] Kyle Ruddy
- [Wayback] Get All VMs – Samples – VMware {code}
- [Wayback] pyvmomi-community-samples
Welcome to the pyvmomi-community-samples project
This is a place for anyone to learn about working with the vSphere Management SDK’s native python binding library pyVmomi. Samples here are contributed by developers like you and curated by your fellow developers. The quality and validity of the samples will vary, however, if you see a problem report it! If you can solve someone’s problem, contribute a fix! If you need a new sample ask for one!
- [Wayback] vmware/pyvmomi: VMware vSphere API Python Bindings
pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter.
- [Wayback] pyvmomi-community-samples/samples at master · vmware/pyvmomi-community-samples
Executable Samples
This directory contains a collection of executable sample scripts that use the pyVmomi library. There is atools
directory that holds a collection of tools and atests
directory that holds the tests for those tools.Quality and License
Scripts are provided as-is by numerous contributors and the status of any sample at any point is subject to change. The project is intended as a collaborative exercise in community learning and may not contain best practice methods.All samples revert to the license of the project and all ownership reverts to the community project.Contribution Notes
- If a script is in this directory, it is an executable sample.
- conform to pep8
- avoid using any special tools beyond pyVmomi.
- do not extend the pyVmomi API in this project we have two separate projects dedicated to that.
- tests are appreciated but optional because of this sample quality must be manually assessed bug reports and fixes are much appreciated.
- A reviewer will pull a new sample for testing and will attempt to run the sample. If the reviewer can do this, the sample can be merged
Getting Help
- Question can be opened as issues at https://github.com/vmware/pyvmomi-community-samples/issues
- The IRC forum #pyvmomi is for developers working with pyVmomi
of which there are many, for instance:
- [Wayback] pyvmomi-community-samples/getallvms.py at master · vmware/pyvmomi-community-samples
- [Wayback] pyvmomi-community-samples/virtual_machine_device_info.py at master · vmware/pyvmomi-community-samples
- [Wayback] pyvmomi-community-samples/samples/tools at master · vmware/pyvmomi-community-samples
Any reusable classes or methods that you develop can be included in packages under this directory. When adding a reusable component we highly recommend that you include tests.Only some samples will make use of reusable components. This is where to put those.
- [Wayback] How did I get started with the vSphere Python SDK “pyvmomi” on ubuntu distro? | vThinkBeyondVM
- [Wayback] pyVmomi tutorial : How to get all the core vCenter server inventory objects and play around? | vThinkBeyondVM
–jeroen
Leave a Reply