[GH-ISSUE #152] Panic while looping proxmox.VirtualMachines #38

Closed
opened 2026-03-03 15:29:48 +03:00 by kerem · 4 comments
Owner

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.VirtualMachines and when I use VirtualMachineConfig.Memory field, it throws a panic error:
panic: runtime error: invalid memory address or nil pointer dereference

Here's the program snippet:

func showVMs(vm proxmox.VirtualMachines) {
	for i := range vm {
			fmt.Println(vm[i].VMID, vm[i].Name, vm[i].VirtualMachineConfig.Memory)
	}
}

Any help would be appreciated! Thanks for this awesome API.

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.VirtualMachines` and when I use `VirtualMachineConfig.Memory` field, it throws a panic error: `panic: runtime error: invalid memory address or nil pointer dereference` Here's the program snippet: ```go func showVMs(vm proxmox.VirtualMachines) { for i := range vm { fmt.Println(vm[i].VMID, vm[i].Name, vm[i].VirtualMachineConfig.Memory) } } ``` Any help would be appreciated! Thanks for this awesome API.
kerem closed this issue 2026-03-03 15:29:48 +03:00
Author
Owner

@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 VirtualMachine type itself : https://github.com/luthermonson/go-proxmox/blob/main/types.go#L207
In your specific case, I'd use the vm[i].Mem field rather than vm[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.

<!-- gh-comment-id:2241574105 --> @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 `VirtualMachine` type itself : https://github.com/luthermonson/go-proxmox/blob/main/types.go#L207 In your specific case, I'd use the `vm[i].Mem` field rather than `vm[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.
Author
Owner

@thebigbone commented on GitHub (Jul 22, 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 VirtualMachine type itself : https://github.com/luthermonson/go-proxmox/blob/main/types.go#L207 In your specific case, I'd use the vm[i].Mem field rather than vm[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.

Thanks for the detailed explanation. I tried the Mem field, 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.

<!-- gh-comment-id:2243138943 --> @thebigbone commented on GitHub (Jul 22, 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 `VirtualMachine` type itself : https://github.com/luthermonson/go-proxmox/blob/main/types.go#L207 In your specific case, I'd use the `vm[i].Mem` field rather than `vm[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. Thanks for the detailed explanation. I tried the `Mem` field, 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.
Author
Owner

@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 info for 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.

<!-- gh-comment-id:2243635365 --> @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 info` for 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.
Author
Owner

@thebigbone commented on GitHub (Jul 24, 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 info for 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.

After fiddling around, it seems like the unit is byte which can be converted to Gibibyte or Mebibyte as you mentioned. Thanks for the help.

<!-- gh-comment-id:2248154231 --> @thebigbone commented on GitHub (Jul 24, 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 info` for 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](https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/%7Bnode%7D/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. After fiddling around, it seems like the unit is `byte` which can be converted to `Gibibyte` or `Mebibyte` as you mentioned. Thanks for the help.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-proxmox#38
No description provided.