Example 7 - Osirium/vcdriver GitHub Wiki
Virtual machine management: WinRM
Remote windows machines can be managed with WinRM.
This method needs the two corresponding configuration values you can
find in the [Virtual Machine Remote Management]
section of the
configuration (See Example 1).
The winrm
method lets you run powershell scripts on the target
machine, using pywinrm.
Additional pywinrm connection parameters can be passed as the
winrm_kwargs
argument, which should be a dictionary.
You can use the quiet
mode.
>>> from vcdriver.vm import VirtualMachine
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> vm = VirtualMachine(name='vm_name', template='vm_template')
>>> vm.create()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Create virtual machine "vm_name" from template "vm_template"] ... 0:00:10.074632
>>> vm.winrm('ls')
Waiting for [Get IP] ... 0:01:03.292489
Executing remotely on 10.0.0.1 ...
ls
CODE: 0
>>> vm.winrm('ls', quiet=True)
>>>
You can also upload small files (It's too slow for big binary files). At the moment, this feature only works for Python 2.
The same applies for the quiet
mode.
>>> from vcdriver.vm import VirtualMachine
>>> from vcdriver.config import load
>>> load('path/to/vcdriver.ini')
>>> vm = VirtualMachine(name='vm_name', template='vm_template')
>>> vm.create()
Vcenter session opened with ID 52d75977-360d-0923-39ff-b914fd323d61
Waiting for [Create virtual machine "vm_name" from template "vm_template"] ... 0:00:10.074632
>>> vm.winrm_upload(local_path='src.txt', remote_path='C:\\dest.txt')
Copying "src.txt" to "C:\dest.txt" ... [==============================] 100 %
>>> vm.winrm_upload(local_path='src.txt', remote_path='C:\\dest.txt', quiet=True)
>>>