* [PATCH container] fix #8162: status: always return 'cpus' as number
@ 2026-11-07 22:11 Lucas Barros
2026-11-14 21:33 ` applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Lucas Barros @ 2026-11-07 22:11 UTC (permalink / raw)
To: pve-devel
For containers that only have 'cpulimit' set, the 'cpus' property of
the status API endpoints was encoded as a JSON string, for example
"cpus":"2", while the API schema declares it as a number. Clients that
decode the response strictly by the schema, like the Terraform
provider for Proxmox VE, fail to parse it.
The config parser keeps values of 'number' typed options like
'cpulimit' as string, while 'integer' options like 'cores' are
converted with int(). Explicitly convert the value to a number, so
'cpus' has the same type regardless of which option it comes from.
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
---
Checked the JSON encoding of the resulting value for cpulimit only,
fractional cpulimit, cores and neither being set.
An alternative would be to return the value as number from the
'number' branch of check_type() in PVE::LXC::Config, which would fix
this for every 'number' option at once, but that also changes the value
that is used when writing the config, so I went with the narrower fix.
This patch was prepared with the help of an LLM based coding assistant;
I reviewed the change and ran the tests mentioned above myself.
src/PVE/LXC.pm | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 59d803d..09fb00a 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -290,8 +290,9 @@ sub vmstatus {
$d->{name} = $conf->{'hostname'} || "CT$vmid";
$d->{name} =~ s/[\s]//g;
- $d->{cpus} = $conf->{cores} || $conf->{cpulimit};
- $d->{cpus} = $cpucount if !$d->{cpus};
+ # cpulimit is a fractional value kept as string by the config parser, so
+ # convert it explicitly to have 'cpus' encoded as a JSON number
+ $d->{cpus} = ($conf->{cores} || $conf->{cpulimit} || $cpucount) + 0;
$d->{tags} = $conf->{tags} if defined($conf->{tags});
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* applied: [PATCH container] fix #8162: status: always return 'cpus' as number
2026-11-07 22:11 [PATCH container] fix #8162: status: always return 'cpus' as number Lucas Barros
@ 2026-11-14 21:33 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2026-11-14 21:33 UTC (permalink / raw)
To: pve-devel, Lucas Barros
On Sat, 07 Nov 2026 19:11:20 -0300, Lucas Barros wrote:
> For containers that only have 'cpulimit' set, the 'cpus' property of
> the status API endpoints was encoded as a JSON string, for example
> "cpus":"2", while the API schema declares it as a number. Clients that
> decode the response strictly by the schema, like the Terraform
> provider for Proxmox VE, fail to parse it.
>
> The config parser keeps values of 'number' typed options like
> 'cpulimit' as string, while 'integer' options like 'cores' are
> converted with int(). Explicitly convert the value to a number, so
> 'cpus' has the same type regardless of which option it comes from.
>
> [...]
Applied, thanks!
[1/1] fix #8162: status: always return 'cpus' as number
commit: a07edd2eda940504132f9300de6b730635e6a5ff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-14 21:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-07 22:11 [PATCH container] fix #8162: status: always return 'cpus' as number Lucas Barros
2026-11-14 21:33 ` applied: " Thomas Lamprecht
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.