Fetching the VNC information
curl -X 'POST' 'http://CLOUDTOWER_ENDPOINT/api' \
-H 'accept: application/json' \
-H 'content-language: en-US' \
-H 'Authorization: YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"operationName": "vnc",
"variables": { "input": { "vm": { "id": $VM_ID } } },
"query": "query vnc($input: VncInput!) { vnc(input: $input) { vm_uuid host_ip cluster_ip raw_token token}}"
}'
Here, $VM_ID represents the virtual machine ID, and endpoint refers to /api.
An example response is shown below:
{
"data": {
"vnc": {
"raw_token": "a 32-character hexadecimal number",
"token": "a string encrytped by Base64",
"vm_uuid": "vm_uuid",
"cluster_ip": "cluster_ip",
"host_ip": "host_ip"
}
}
}
If your current environment can directly connect to the cluster, you can construct a direct noVNC link to the cluster using the following fields: cluster_ip, vm_uuid, raw_token, and host_ip.
[wss/ws]://${cluster_ip}/websockify/?uuid=${vm_uuid}&token=${raw_token}&host=${host_ip}
Alternatively, you can construct a noVNC link via the management platform's proxy using token, vm_uuid, and host_ip. Since token is a base64-encoded string, it may contain characters that cannot be included in a URL (for example, /, +, and =). In such cases, you need to escape them into hexadecimal values.
[wss/ws]://CLOUDTOWER_ENDPOINT/websockify/?token=${token}&host=${host_ip}&uuid=${vm_uuid}
For the usage of the link, refer to the usage of noVNC in react-vnc.
The following is an example:
Suppose that you received the following response:
{
"data": {
"vnc": {
"raw_token": "1a2bc3d4567e89f0a1b2c3d4e5f6a7b8",
"token": "MTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=",
"vm_uuid": "00000000-0000-0000-0000-000000000000",
"cluster_ip": "192.168.5.2",
"host_ip": "192.168.5.4"
}
}
}
If you want to establish a direct connection, you can construct the following URL:
wss://192.168.5.2/websockify/?uuid=00000000-0000-0000-0000-000000000000&token=1a2bc3d4567e89f0a1b2c3d4e5f6a7b8&host=192.168.5.4
Suppose that the token is MTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo= (base64-encoded from 123456789abcdefghijklmnopqrstuvwxyz). You need to escape special characters such as /, +, and =.
token = "MTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="
encodeURIComponent(token) = "MTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="%3D"
wss://192.168.5.1/websockify/?token=MTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo%3D&uuid=00000000-0000-0000-0000-000000000000&host=192.168.5.4