From: Lucas Barros <lucasbarros.kam@gmail.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH container] fix #8162: status: always return 'cpus' as number
Date: Sat, 7 Nov 2026 19:11:20 -0300 [thread overview]
Message-ID: <20261107221120.13176-1-lucasbarros.kam@gmail.com> (raw)
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)
reply other threads:[~2026-11-07 22:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261107221120.13176-1-lucasbarros.kam@gmail.com \
--to=lucasbarros.kam@gmail.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox