From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id DEB971FF0E1 for ; Mon, 16 Nov 2026 01:49:22 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0F2B7217D3; Mon, 16 Nov 2026 01:48:32 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH container 25/34] api: status: return the guest uid Date: Mon, 16 Nov 2026 01:46:37 +0100 Message-ID: <20261116004703.2908294-26-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261116004703.2908294-1-t.lamprecht@proxmox.com> References: <20261116004703.2908294-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794790030259 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.217 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 4YKQMOR4LBTN55E2GFJPXTMBTQXTTSS6 X-Message-ID-Hash: 4YKQMOR4LBTN55E2GFJPXTMBTQXTTSS6 X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Return the uid with the container's current status so tools can follow the guest across restores and migrations without parsing the 'meta' property of its config. Signed-off-by: Thomas Lamprecht --- src/PVE/API2/LXC/Status.pm | 10 ++++++++++ src/test/lifecycle_tests.pl | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm index c95fc3c..3972424 100644 --- a/src/PVE/API2/LXC/Status.pm +++ b/src/PVE/API2/LXC/Status.pm @@ -98,6 +98,12 @@ __PACKAGE__->register_method({ description => "HA manager service status.", type => 'object', }, + uid => { + description => "Random identifier of the guest, see the 'uid' member of the" + . " 'meta' config property.", + type => 'string', + optional => 1, + }, }, }, code => sub { @@ -112,6 +118,10 @@ __PACKAGE__->register_method({ $status->{ha} = PVE::HA::Config::get_service_status("ct:$vmid"); + if (my $identity = PVE::LXC::Config->get_identity($conf)) { + $status->{uid} = $identity->{uid}; + } + return $status; }, }); diff --git a/src/test/lifecycle_tests.pl b/src/test/lifecycle_tests.pl index e2fdb9f..42497c5 100755 --- a/src/test/lifecycle_tests.pl +++ b/src/test/lifecycle_tests.pl @@ -32,6 +32,7 @@ use PVE::Tools qw(file_get_contents file_set_contents); use PVE::API2::LXC; use PVE::API2::LXC::Config; +use PVE::API2::LXC::Status; use PVE::CLI::pct; use PVE::LXC; use PVE::LXC::Config; @@ -1847,6 +1848,31 @@ subtest 'remote migration keeps the source if the target fails to take over the is(identity_of(987)->{uid}, 'sourcesourcesourceso', 'source keeps its uid'); }; +subtest 'current status reports the uid' => sub { + reset_configs(); + write_raw_config( + 200, + existing_config('ctime=1500000000,rtime=1500000000000,uid=existingexistingexis'), + ); + write_raw_config(201, existing_config('ctime=1500000000')); + + $lxc_module->mock( + vmstatus => sub { + my ($vmid) = @_; + return { $vmid => { vmid => int($vmid), status => 'stopped' } }; + }, + ); + my $ha_config_module = Test::MockModule->new('PVE::HA::Config'); + $ha_config_module->mock(get_service_status => sub { return { managed => 0 } }); + + my $status = PVE::API2::LXC::Status->vm_status({ node => $NODENAME, vmid => 200 }); + is($status->{uid}, 'existingexistingexis', 'uid is reported'); + $status = PVE::API2::LXC::Status->vm_status({ node => $NODENAME, vmid => 201 }); + ok(!exists($status->{uid}), 'no uid is reported for a container without identity'); + + $lxc_module->unmock('vmstatus'); +}; + remove_tree($WORKDIR); done_testing(); -- 2.47.3