Skip to content

vm: Expose memory, CPU topology, host affinity, and HA settings#13

Open
olivierlambert wants to merge 1 commit intomainfrom
vm-settings-issue-2
Open

vm: Expose memory, CPU topology, host affinity, and HA settings#13
olivierlambert wants to merge 1 commit intomainfrom
vm-settings-issue-2

Conversation

@olivierlambert
Copy link
Member

Summary

Addresses #2 — adds the ability to retrieve and modify VM settings like memory, CPU topology, host affinity, and high availability.

Get-XoVm — new properties on VM objects

Property Source field Description
AffinityHost affinityHost Preferred host UUID for VM placement
MemorySize memory.size Memory allocation in bytes
CoresPerSocket coresPerSocket Cores per socket (CPU topology)
AutoPoweron auto_poweron Auto-start on host boot
HA high_availability HA restart priority

These are added as friendly named properties (same pattern as VmUuid, Name, PowerState, etc.). The raw API fields affinityHost, coresPerSocket, and high_availability are now included in the fields query.

Set-XoVm — new parameters

Parameter Type API field Description
-AffinityHost string (UUID) affinityHost Set preferred host
-Memory long memory Set memory in bytes
-CPUs int CPUs Set vCPU count
-CoresPerSocket int coresPerSocket Set cores per socket
-AutoPoweron bool auto_poweron Set auto power-on
-HA string high_availability Set HA priority ("", "restart", "best-effort")

-AffinityHost supports ValueFromPipelineByPropertyName and has UUID validation, consistent with other UUID parameters in the module.

Use case from the issue

We are looking for a specific method to get VMs, check their current host and set this as the host affinity.

# Set each running VM's affinity to its current host
Get-XoVm -PowerState Running | ForEach-Object {
    Set-XoVm -VmUuid $_.VmUuid -AffinityHost $_.HostUuid
}

# Report on VM settings
Get-XoVm -Limit 0 | Select-Object Name, MemorySize, CPUs, CoresPerSocket, AffinityHost, HA

Test plan

  • Get-XoVm returns AffinityHost, MemorySize, CoresPerSocket, AutoPoweron, HA properties
  • Get-XoVm | Select-Object Name, AffinityHost, MemorySize, CoresPerSocket shows expected values
  • Set-XoVm -VmUuid <id> -AffinityHost <host-uuid> sets the affinity
  • Set-XoVm -VmUuid <id> -Memory <bytes> sets memory
  • Set-XoVm -VmUuid <id> -CPUs <n> -CoresPerSocket <n> sets CPU topology
  • Set-XoVm -VmUuid <id> -AutoPoweron $true enables auto power-on
  • Set-XoVm -VmUuid <id> -HA "restart" sets HA priority
  • Existing Set-XoVm -Name / -Description / -Tags still work

🤖 Generated with Claude Code

Closes #2

Get-XoVm now returns these additional friendly properties:
- AffinityHost: preferred host UUID for VM placement
- MemorySize: memory allocation in bytes (from memory.size)
- CoresPerSocket: CPU topology (cores per socket)
- AutoPoweron: whether the VM auto-starts on host boot
- HA: high availability restart priority

Set-XoVm now accepts these new parameters:
- -AffinityHost: set the preferred host (with UUID validation)
- -Memory: set memory size in bytes
- -CPUs: set vCPU count
- -CoresPerSocket: set cores per socket (CPU topology)
- -AutoPoweron: set auto power-on behavior
- -HA: set HA priority ("", "restart", "best-effort")

The fields affinityHost, coresPerSocket, and high_availability are
added to the API query so they are fetched from Xen Orchestra.

Example — set each running VM's affinity to its current host:

  Get-XoVm -PowerState Running | ForEach-Object {
      Set-XoVm -VmUuid $_.VmUuid -AffinityHost $_.HostUuid
  }

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dinhngtu
Copy link
Collaborator

Hi, the Patch endpoint of VM seems to have disappeared? It doesn't work nor show up in the Swagger doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants