websocketvmwarevncvmware-tools

VMware HTML Console SDK connection failed


Hello VMware Community,

I'm encountering an issue when trying to connect to an HTML console via WebSocket. Below is the process I followed and the error I'm experiencing. Any guidance would be greatly appreciated.

Using Python, I retrieved VNC connection information for a virtual machine. The code snippet used is as follows:

try:
    ticket = vm.AcquireMksTicket()
    print("VNC connection information for {}:".format(vm_name))
    print("Host: {}".format(ticket.host))
    print("Port: {}".format(ticket.port))
    print("Ticket: {}".format(ticket.ticket))
    print("SSL thumbprint: {}".format(ticket.sslThumbprint))
except vmodl.MethodFault as e:
    print("Failed to get VNC connection information: {}".format(e.msg))
    exit(1)

This resulted in the following

VNC connection information for dev-test - 10.xxxxxxxxxxxx:
Host: ch1-dev-esxi1.lab.local
Port: 902
Ticket: 52xxxxxxxxxxxxxxxxxxxxxxxx
SSL thumbprint: [Thumbprint]

Issue:

However, when attempting to use this information to connect to the HTML console, I'm facing a WebSocket connection failure. The error message is:

WebSocket connection to 'wss://[IP]:[Port]/ticket/[Ticket-ID]' failed

Here's the HTML and JavaScript code I used for the connection:

<!DOCTYPE html>
... [Rest of the HTML code] ...
<script>
var wmks = WMKS.createWMKS("wmksContainer",{})
  .register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(event, data){
    if(data.state == WMKS.CONST.ConnectionState.CONNECTED){
      console.log("connection state change: connected");
    }
  });
wmks.connect("wss://ch1-dev-esxi1.lab.local:902/ticket/52dxxxxxxxxxxxxxxx");
</script>
</body>
</html>

Additional Checks:

The VM is running without issues.

VMware Tools are installed, current, and running (Version 12288, 12.0.0).

I'm unsure why this WebSocket connection is failing. Has anyone experienced a similar issue or can provide some insights into what might be going wrong?

Thank you in advance for your help!


Solution

  • The issue is resolved now. The issue was related to ticket that was created by following line in my Python Script

    ticket = vm.AcquireMksTicket()
    

    I replaced above line with the following line.

     ticket = vm.AcquireTicket(ticketType='webmks')
    

    AcquireMksTicket only works with very old vSphere versions.