[SOLVED] Best way to launch one VM from remote ?

iouej

Member
Aug 28, 2018
10
1
23
37
Hello,

I have set up a gaming w10 VM for my little brother on my server which he accesses using parsec.
Parsec is only working when the VM is up and running but It is a waste of resource to let the VM always on.
To turn off the VM you can do it once you are in parsec however I can't come with a simple idea to let him launch the VM and then launch parsec.

It seems that a pve user can not have its rigth on one vm and I don't want to let him the possibility to nuke my others VM.

Thank you in advance for your help !

EDIT: The absolute best way would be to launch the VM when he launches parsec with one click but I'm not shure how could I implement this.
 
Last edited:
It seems that a pve user can not have its rigth on one vm and I don't want to let him the possibility to nuke my others VM.
You can actually do exactly this in PVE:
1. Create a user for your brother (datacenter->permissions->users->add), with Realm as Proxmox VE authentication server.
2. Create a new role on the system with whatever privileges your brother needs (permissions->roles->create). I guess in this case you would want VM.PowerMgmt for power control, and VM.Audit to see the vm from the web interface (see [1]).
3. From permissions, select "Add->User Permission" and set the following:
Path: /vms/VMID
User: brother@pve
Role: role from step 2.
4. Your brother can now log in to the web interface, but will only see his VM and only be able to view the configuration and manage power options.

See the user management section of the admin guide for more details [2].

[1] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pveum_permission_management
[2] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#chapter_user_management

Edit: And sorry, I am not familiar with parsec, so can't make any suggestions on how to launch the vm from there.
 
Last edited:
Thank you from my little brother, it worked perfectly ! I have an access through the UI exatcly to this VM now :)
 
  • Like
Reactions: dylanw
I am interested in the one button solution as well, as most of the coworkers are on Mac and doesn't know anything about VM or Proxmox dashboard. Really need to have some kind of script that I can construct with Apple Script editor and make it into an executable app so they can double click it, and the Windows VM starts, ready to be remoted in.
thanks
 
I am interested in the one button solution as well, as most of the coworkers are on Mac and doesn't know anything about VM or Proxmox dashboard. Really need to have some kind of script that I can construct with Apple Script editor and make it into an executable app so they can double click it, and the Windows VM starts, ready to be remoted in.
thanks
hi, you can use Microsoft Remote Desktop,or use spice,https://git.proxmox.com/?p=pve-manager.git;a=blob_plain;f=spice-example-sh;hb=HEAD
 
Exact same situation, I have a Windows VM and I wanted a one-click solution for my brother to be able to turn it on. Came up with the following Powershell script. Note that you need to set your own default values in the param() block at the top of the script to match your login details.

If you want to re-use the script with different arguments than the default, here are some examples of how to call it:

.\VMControl.ps1 123 on
.\VMControl.ps1 123 off root@pam password nodename 192.168.1.10:8006
.\VMControl.ps1 -VM_ID "123" -OnOrOff "on" -Username "root@pam" -Password "password" -NodeName "nodename" -ProxmoxHost "192.168.1.10:8006"

I tried to add a decent error message if any of the params are wrong.

Written in Powershell 5.1 using Proxmox 8.1
Code:
# Description: This script is used to start or stop a VM on a Proxmox server.

param(
    [string]$VM_ID="101",
    [ValidateSet("on", "off")] [string]$OnOrOff = "on",
    [string]$Username = "root@pam",
    [string]$Password = "<your_password>",
    [string]$NodeName = "<your_node_name>",
    [string]$ProxmoxHost = "<your_ip_here>:8006"
)
$taskTimeout = 30 # How long to wait for the task to complete, before timing out.

function ExitAndWaitForKeypress {
    Write-Host "Press any key to continue..."
    $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
    exit 1
}

$curlCommand = "curl.exe -sS -k"; # -sS is to suppress the progress bar and show errors, -k is to ignore SSL certificate errors
$proxmoxApiBaseUrl = "https://$ProxmoxHost/api2/json"
# Authenticate and get the tickets
$getTicketJson = ConvertFrom-Json (Invoke-Expression "$curlCommand -d 'username=$Username' --data-urlencode 'password=$Password' '$proxmoxApiBaseUrl/access/ticket'")
$ticket = $getTicketJson.data.ticket
$preventionToken = $getTicketJson.data.CSRFPreventionToken
if (-not $ticket -or -not $preventionToken) {
    Write-Error "Failed to retrieve authentication ticket. Your login credentials may be incorrect."
    ExitAndWaitforKeypress
}
$curlCommandWithTicket = "curl.exe -sS -k -H `"Cookie: PVEAuthCookie=$ticket`" -H `"CSRFPreventionToken: $preventionToken`""
# Create the task to start or stop the VM
if ($OnOrOff -eq "on") {
    $curlPostTask = "$curlCommandWithTicket -X POST -i `"$proxmoxApiBaseUrl/nodes/$NodeName/qemu/$VM_ID/status/start`"" # -i to include the headers in output
} elseif ($OnOrOff -eq "off") {
    $curlPostTask = "$curlCommandWithTicket -X POST -i `"$proxmoxApiBaseUrl/nodes/$NodeName/qemu/$VM_ID/status/shutdown`""
} else {
    Write-Error "Invalid value for OnOrOff: $OnOrOff. OnOrOff must be 'on' or 'off'."
}
$postResponse = Invoke-Expression $curlPostTask
$responseParts = $postResponse.Split("`r`n");
$postTaskResponseStatus = $responseParts[0] # First line of the response contains the HTTP version followed by the status code and the reason phrase
$postTaskResponseJson = ConvertFrom-Json $responseParts[-1] # json body is at the end of the response
$upid = $postTaskResponseJson.data
if (-not $upid) {
    Write-Error "Failed to create the task. Proxmox returned response: '$postTaskResponseStatus'."
    ExitAndWaitForKeypress
}
# Wait for the task to complete, print the result.
$startTime = Get-Date
do {
    $curlGetTaskStatus = "$curlCommandWithTicket -X GET `"$proxmoxApiBaseUrl/nodes/$NodeName/tasks/$upid/status`""
    $taskStatusJson = ConvertFrom-Json (Invoke-Expression $curlGetTaskStatus)
    if ($taskStatusJson.data.status -eq "stopped") {
        Write-Host "TASK COMPLETED. | command='$($taskStatusJson.data.type)' | status='$($taskStatusJson.data.status)' | reason='$($taskStatusJson.data.exitstatus)' `r`n" -NoNewline
        break
    }
    Write-Host "TASK RUNNING... | command='$($taskStatusJson.data.type)' | status='$($taskStatusJson.data.status)'"
    $currentTime = Get-Date
    $elapsedTime = ($currentTime - $startTime).TotalSeconds
    if ($elapsedTime -ge $taskTimeout) {
        Write-Error "Timeout: Task is still running after $taskTimeout seconds."
        break
    }
    Start-Sleep -Milliseconds 250
} while ($true)
ExitAndWaitForKeypress
 
Last edited:

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!