* [PATCH container] fix #8162: status: always return 'cpus' as number
@ 2026-11-07 22:11 Lucas Barros
0 siblings, 0 replies; only message 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] only message in thread
only message in thread, other threads:[~2026-11-07 22:11 UTC | newest]
Thread overview: (only message) (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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox