[SOLVED] Set HA on VM

spacemancw

New Member
Feb 2, 2024
15
0
1
I'm looking for an API call or a qm command to set HA on a new VM in Proxmox.
I've looked in the qm man page and API guide.
AI sites tell me this:

Code:
$body = 'ha=started,group=PXGroup,max_restarts=3,max_relocate=1'

$apiUrl = "https://$pxhost/api2/json/nodes/$node/qemu/$vmid/config"

Invoke-RestMethod -Uri $apiUrl -Headers $headers -Body $body -Method POST -ContentType 'application/x-www-form-urlencoded'

But that doesn't work, I get the error " "ha": "property is not defined in schema and the schema does not allow additional properties""
 
Thanks very much. This worked! This is my powershell code.

Code:
       $endpoint = "cluster/ha/resources"
        $apiUrl = "https://$pxhost/api2/json/$endpoint"
        Invoke-RestMethod -Uri $apiUrl -Headers $pHeaders
        
        $body = @{
            sid = $nextVmid
            type = "vm"
            max_restart = "3"
            max_relocate = "3"
            group= $haGroup
            state= "started"
        } | ConvertTo-Json
        
        try {
            Invoke-RestMethod -Uri $apiUrl -Headers $pHeaders -Body $body -Method POST -ContentType "application/json"
            write-host " Successfully set HA on $vmname  - " (get-date)
            }
        catch {write-host " ATTENTION: Failed to set HA on $vmname  - " (get-date)}