[SOLVED] Connect to VM by vnc/spice

yonatan1346

New Member
Apr 20, 2020
6
0
1
Hi,
I want to connect to my machine (currently PROXMOX on VM on my computer) through external VNC and not what's on the site.
When I send the following command to the REST API:


https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/vncproxy

I receive the following information:
JSON:
{"data":{"ticket":"PVEVNC:5EB811CF::YTUMA1+n/HwCpsxnB[...]oMOI6yg==","upid":"UPID:pve:0[...]4:0[...]3:5[...]F:vncproxy:100:root@pam:","port":"5900","user":"root@pam","cert":"-----BEGIN CERTIFICATE-----\\nMIIFzTCCA7WgAwIBAg[...]AC\\n9CJQ+5Yunc45UtlEHzafpX/Aj33w+U4X\\n1g==\\n-----END CERTIFICATE-----\\n"}}

I got a bit stuck, what am I doing from here?
Does anyone know of a Python library or any other way to connect?

Thanks
 
I mostly want to connect to the display and less with a terminal
And I don't want to run it on a computer with Proxmox or start compiling it...
So maybe you know about something else?

Thank you very much
 
hi,

take a look here[0]

you will need to modify your network/firewall settings to allow access from outside

[0]: https://pve.proxmox.com/wiki/VNC_Client_Access
It works

Now I would like to restrict connection to the VM with a password (and not rewrite it because the VM does a restart) or preferably a certificate.
As I wrote in the beginning, I can send the following command to the rest API:
https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/vncproxy
And get a cert

JSON:
{"data":{"ticket":"PVEVNC:5EB811CF::YTUMA1+n/HwCpsxnB[...]oMOI6yg==","upid":"UPID:pve:0[...]4:0[...]3:5[...]F:vncproxy:100:root@pam:","port":"5900","user":"root@pam","[B]cert[/B]":"-----BEGIN CERTIFICATE-----\\nMIIFzTCCA7WgAwIBAg[...]AC\\n9CJQ+5Yunc45UtlEHzafpX/Aj33w+U4X\\n1g==\\n-----END CERTIFICATE-----\\n"}}

Is it possible to configure the machine such that you can only connect with this cert?
Or am I mistaken about the cert's purpose?

Thanks
 
Last edited:
cert is an ssl certificate to be used in the connection (is the same cert for the https connection to the gui)

as @tim said you can take a look at the spice example to see how it can be accomplished
 
The first option was to use a VNC Client (see: https://pve.proxmox.com/wiki/VNC_Client_Access)
I config the VM in 'Monitor' panel with
Code:
change vnc 0.0.0.0:100,password
set_password vnc mypassword
expire_password vnc +30
and then using RealVNC I connected to the VM on myproxmoxhost:6000
The problem is that I want to set a fixed password and not rewrite it because the VM does a restart.

The second option was to use SPICE (see: https://pve.proxmox.com/wiki/SPICE)

I made a short python code that downloads the SPICE runner - This is an unprepared example, but if it helps someone then it is great
(It is base on https://pypi.org/project/proxmoxer/ )
To tun the file spiceconnection.vv you can download virt-viewer from https://virt-manager.org/download/

Python:
from proxmoxer import ProxmoxAPI

# User params
HOST='192.168.253.155'
USER='root@pam'
PASSWORD='Aa1234'
VERIFY_SSL=False
spicecPath= "spiceconnection.vv"

# Main proxmox object
proxmox = None

def urlCreator(node, vmid, method, proxmoxHost=HOST, formatData="json"):
    return "https://{0}:8006/api2/{1}/nodes/{2}/qemu/{3}/{4}".format(proxmoxHost, formatData, node, vmid, method)

def initProxmox(host, user, password, verify_ssl):
    initproxmox = ProxmoxAPI(host=host, user=user, password=password, verify_ssl=verify_ssl)
    global proxmox
    proxmox = initproxmox

def postRequest(url, data=None, params=None):
    if proxmox:
        resp = proxmox._store["session"].request("POST", url, data, params)
        return resp
    else:
        return None

def startVM(node, vmid):
    url = urlCreator(node=node, vmid=vmid, method="status/start")
    resp = postRequest(url)
    print(resp.content)

def stopVM(node, vmid):
    url = urlCreator(node=node, vmid=vmid, method="status/stop")
    resp = postRequest(url)
    print(resp.content)

def spiceproxyVM(node, vmid):
    url = urlCreator(formatData="spiceconfig", node=node, vmid=vmid, method="spiceproxy")
    resp = postRequest(url, params={"proxy": HOST})
    with open(spicecPath, 'wb') as spiceconfig:
        spiceconfig.write(resp.content)

def statusVMs():
    for vm in proxmox.cluster.resources.get(type='vm'):
        print("{0}. {1} => {2}" .format(vm['vmid'], vm['name'], vm['status']))

def main():
    initProxmox(HOST, USER, PASSWORD, VERIFY_SSL)
    spiceproxyVM('pve', 100)

if __name__ == "__main__":
    main()

My problem with this right now is that this file can be run multiple times

I haven't checked xterm.js yet

I would love to know if anyone discovered anything that bothered me
 
hello the problem with your script is what contain spiceconnection.vv and your link of spiceconnection.vv is bad
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!