Vcdriver is a wrapper around pyvmomi that lets you manage virtual machines on your Vsphere in an easy way.
- Create, find or destroy virtual machines.
- Power on/off, shutdown, reboot and reset them.
- Snapshot management.
- Remote management:
- SSH protocol for remote commands (Requires the SSH service).
- SFTP protocol for file transfers (Requires the SSH service).
- WinRM protocol for remote commands and file transfer on Windows machines (Requires the WinRM service).
How does it work underneath?
- Vsphere is driven using its official python API, pyvmomi.
- The virtual machines are manipulated with Fabric3 and pywinrm.
- It currently supports Python 2.7, 3.4, 3.5 and 3.6.
- It works with latest versions of Vsphere, 6.0 and 6.5.
Why would I use vcdriver instead of using pyvmomi directly?
Pyvmomi is powerful but its learning curve is overkill for most of the tasks you might want to execute programmatically with Vsphere. All the complexity has been abstracted out so you can do in 5 lines of vcdriver code what you would do in 50 lines of pyvmomi code. That makes your testing and automation scripts way easier to read and maintain.
pip install vcdriver
Documentation and examples can be found on the wiki.
Prepare your python environment:
pip install -e . && pip install pytest pytest-cov mock.
pytest -v --cov=vcdriver --cov-fail-under 100 test/unit.
As you might expect, the unit tests can only test the logic of the driver, as all the vcenter components have to be mocked out. You can run some integration tests to check it works fine for your Vsphere instance. To do so:
- You need the following Vsphere resources:
- An empty folder which will serve as a sandbox environment for the tests.
- A Unix virtual machine template with the SSH service allowing remote username/password SSH/SFTP connections.
- A Windows Server virtual machine template with the WinRM service allowing remote username/password WinRM connections. The ansible people have done a great job about this, and you can set it up with their script: ConfigureRemotingForAnsible.ps1.
- Read through the setup section and create your configuration file.
- Provide the following extra environment variables:
vcdriver_test_config_file: The path to your file config.
vcdriver_test_unix_template: The name of the UNIX virtual machine template that will be cloned for the tests.
vcdriver_test_windows_template: The name of the Windows Server virtual machine template that will be cloned for the tests.
vcdriver_test_folder: An empty vm folder to perform the tests in it.
pytest -v -s test/integration.