Ganesh Satpute
Ganesh Satpute

Reputation: 3951

ESXi: auto assign vnc port for each machine

I need to take remote console of VM running on ESXi host. I need to take VNC for that purpose. To this to happen I need to assign TCP Port to each VM manually or programmatically (of course, by editing VMX file) using settings given below.

remotedisplay.vnc.port="5900"
remotedisplay.vnc.enabled="true"
remotedisplay.vnc.password = "yourpassword"

Is there any mechanism (preferrably psphere API) that I can tell ESX to assign port automatically for all machine or single machine for that matter?

Thanks & Regards,
Ganesh

PS. I'm using Ubuntu 14 and want to connect VMs via browser.

Upvotes: 1

Views: 703

Answers (2)

Ganesh Satpute
Ganesh Satpute

Reputation: 3951

This is what I did to get it working using pysphere

>>> from pysphere import VIServer
>>> s = VIServer()
>>> s.connect('10.11.100.220', 'root', 'password')
>>> vm = s.get_vm_by_name("VMNAME")
>>> settings = {'remotedisplay.vnc.port': '8949', 'remotedisplay.vnc.enabled' : 'true'}
>>> vm.set_extra_config(settings)
>>> s.disconnect()

Upvotes: 2

SomeGuyOnAComputer
SomeGuyOnAComputer

Reputation: 6248

What you can do is ssh into the esx server and append the vmx file with those properties.

echo -e "RemoteDisplay.vnc.enabled = true\nRemoteDisplay.vnc.port = 5900\nRemoteDisplay.vnc.password = \"yourpassword\"" >> /vmfs/volumes/YOURDATASTORE/YOURVMNAME/YOURVMNAME.vmx

or in one command

sshpass -p PASSWORD ssh [email protected] "echo -e \"RemoteDisplay.vnc.enabled = true\nRemoteDisplay.vnc.port = 5900\nRemoteDisplay.vnc.password = \"yourpassword\"\" >> /vmfs/volumes/YOURDATASTORE/YOURVMNAME/YOURVMNAME.vmx"

If that's not your vmx path, you can also dynamically get it using

vim-cmd vmsvc/getallvms | grep VMNAME | awk '{print $4}'

or all in one line

sshpass -p PASSWORD ssh [email protected] "echo -e \"RemoteDisplay.vnc.enabled = true\nRemoteDisplay.vnc.port = 5900\nRemoteDisplay.vnc.password = \"yourpassword\"\" >> $(vim-cmd vmsvc/getallvms | grep VMNAME | head -1 | awk '{print $4}')"

Upvotes: 0

Related Questions