mirror of
https://github.com/luthermonson/go-proxmox.git
synced 2026-04-26 17:35:48 +03:00
[GH-ISSUE #152] Panic while looping proxmox.VirtualMachines #38
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/go-proxmox#38
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @thebigbone on GitHub (Jul 21, 2024).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/152
Hi, I was trying to loop through
proxmox.VirtualMachinesand when I useVirtualMachineConfig.Memoryfield, it throws a panic error:panic: runtime error: invalid memory address or nil pointer dereferenceHere's the program snippet:
Any help would be appreciated! Thanks for this awesome API.
@jqueuniet commented on GitHub (Jul 21, 2024):
The details tend to vary depending on the endpoint as the PVE API is not very normalized, and there are multiple ways to get VM lists (cluster list, node list, etc) with slightly different results. But overall, lists will only return a very limited subset of attributes, which you can find on the
VirtualMachinetype itself : https://github.com/luthermonson/go-proxmox/blob/main/types.go#L207In your specific case, I'd use the
vm[i].Memfield rather thanvm[i].VirtualMachineConfig.Memory.The full VM configuration is a subobject you need to retrieve by doing a VM GET query, but unless you don't have a choice, you should use the field from the list instead to avoid doing an API query per listed VM.
@thebigbone commented on GitHub (Jul 22, 2024):
Thanks for the detailed explanation. I tried the
Memfield, but I am not sure if it's returning bytes or megabytes or something else. After knowing which kind of unit it is, I can convert it according to the need.@jqueuniet commented on GitHub (Jul 22, 2024):
I haven't worked with this endpoint in a while and can't really tell you from memory, so I'd advise you to check for yourself. The PVE API is sadly all over the place as far as size units are concerned, you'll find bytes, megabytes, mebibytes, gigabytes, gibibytes and surely others on different endpoints. Check with actual system values like
qemu-img infofor disk images, as the web UI can be wrong on some endpoints, like showing base 2 values with base 10 units.There's an API documentation you can check if it helps: https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu
But sadly, this specific field does not seem documented. And even if it was, the doc is sometimes wrong too and can't always be taken at face value.
@thebigbone commented on GitHub (Jul 24, 2024):
After fiddling around, it seems like the unit is
bytewhich can be converted toGibibyteorMebibyteas you mentioned. Thanks for the help.