pyvmomi-community-samples
pyvmomi-community-samples copied to clipboard
Need to capture console/screen for vsphere
Hi Guys,
I am trying to install virtual machine through pyvmomi (version : 6.0.0.2016.6) using python (version : 2.7.3) I need to input some boot parameters and based on that i need to input username, password and select other parameters from the menu displayed to start boot process Can you please let me know which library/api's will help me in doing this? How can i achieve this thing.
Hi,
I want to do something similar mentioned by devpanky2014:
install new custom ISO which ask options, and based upon the option selected install appropriate OS type on the virtual machine. How can i trigger keyboard action or say provide input for options while automating the ISO installation in the virtual machine?
thanks
Anyone know how to screenshot vm using pyvmomi?
pyVmomi doesn't provide a very usable API for capturing screenshots. There is createScreenshot, but you'll notice it just saves the png on the datastore of the VM.
You could try acquireTicket with webmks ticketType, which would return a uri for wss. I'm not sure if there are python packages that support mks over websockets. I noticed there is some javascript for html5 that supports it: https://developer.vmware.com/web/sdk/2.2.0/html-console.
Alternatively you could request a screenshot over http: url = f"http://{host}/screen?id={moId}"
where if your vim.VirtualMachine object is vm, then
host = vm._stub.host
moId = vm._moId
You could use username/password basic auth for above request.
If you plan to frequently get screenshots, then the webmks mechanism will likely be much lower load on the system.
@prziborowski thanks! this is the code I used
def screenshot(vm_name):
requests.packages.urllib3.disable_warnings()
ssl._create_default_https_context = ssl._create_unverified_context
si = SmartConnect(host=vsphere_host, user=vsphere_user, pwd=vsphere_pwd)
content = si.RetrieveContent()
vm = get_vm_by_name(content, vm_name)
screenshot_task = vm.CreateScreenshot_Task()
# Wait for the task to complete
while screenshot_task.info.state == vim.TaskInfo.State.running:
continue
# Check the task result
if screenshot_task.info.state == vim.TaskInfo.State.success:
screenshot_path = screenshot_task.info.result
print(f"Screenshot saved to: {screenshot_path}")
else:
return (f"Failed to create screenshot. Reason: {screenshot_task.info.error.msg}")
Disconnect(si)