Esempio n. 1
0
def vm_console(vmid):
    user = User(session['userinfo']['preferred_username'])
    proxmox = connect_proxmox()
    if user.rtp or int(vmid) in user.allowed_vms:
        vm = VM(vmid)
        port = str(5900 + int(vmid))
        token = add_vnc_target(port)
        node = "{}.csh.rit.edu".format(vm.node)
        tunnel = next(
            (tunnel
             for tunnel in ssh_tunnels if tunnel.local_bind_port == int(port)),
            None)
        if tunnel:
            if tunnel.ssh_host != node:
                print(
                    "Tunnel already exists for VM {} to the wrong Proxmox node."
                    .format(vmid))
                tunnel.stop()
                ssh_tunnels.remove(tunnel)
                print("Creating SSH tunnel to {} for VM {}.".format(
                    node, vmid))
                tunnel = start_ssh_tunnel(node, port)
                ssh_tunnels.append(tunnel)
                vm.start_vnc(port)
            else:
                print("Tunnel already exists to {} for VM {}.".format(
                    node, vmid))
        else:
            print("Creating SSH tunnel to {} for VM {}.".format(node, vmid))
            tunnel = start_ssh_tunnel(node, port)
            ssh_tunnels.append(tunnel)
            vm.start_vnc(port)
        return token, 200
    else:
        return '', 403
Esempio n. 2
0
def vm_console(vmid):
    user = User(session['userinfo']['preferred_username'])
    connect_proxmox()
    if user.rtp or int(vmid) in user.allowed_vms:
        vm = VM(vmid)
        stop_ssh_tunnel(vm.id, ssh_tunnels)
        port = str(5900 + int(vmid))
        token = add_vnc_target(port)
        node = '{}.csh.rit.edu'.format(vm.node)
        logging.info('creating SSH tunnel to %s for VM %s', node, vm.id)
        tunnel = start_ssh_tunnel(node, port)
        ssh_tunnels.append(tunnel)
        vm.start_vnc(port)
        return token, 200
    else:
        return '', 403