From 132875a5c59b7aadf6f3421ed5b14b0d69f286d5 Mon Sep 17 00:00:00 2001 From: Kevin Adams Date: Sat, 23 May 2026 21:42:19 -0400 Subject: [PATCH] fix: replace /iscsi/targetgroup with target.groups[] for CORE compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TrueNAS CORE 13.0 does not expose /iscsi/targetgroup as a REST endpoint (returns 404). Both CORE and SCALE include the portal group associations inline in each target's 'groups' array from GET /iscsi/target, which is all we need to filter targets by reachable portal IP. Remove the /iscsi/targetgroup call entirely — use target.groups[].portal cross-referenced against /iscsi/portal results instead. Co-Authored-By: Claude Sonnet 4.6 --- perl5/PVE/Storage/Custom/TrueNAS.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/perl5/PVE/Storage/Custom/TrueNAS.pm b/perl5/PVE/Storage/Custom/TrueNAS.pm index b47bc61..ec299cd 100644 --- a/perl5/PVE/Storage/Custom/TrueNAS.pm +++ b/perl5/PVE/Storage/Custom/TrueNAS.pm @@ -222,13 +222,12 @@ sub _resolve_target { . "Configure a portal in TrueNAS iSCSI settings or set truenas_portal_ip.\n"; } - my $tgroups = _api($scfg, 'GET', '/iscsi/targetgroup') // []; - my %matched_target_ids; - for my $g (@$tgroups) { - $matched_target_ids{$g->{target}} = 1 if $our_portal_ids{$g->{portal}}; - } - - my @matched = grep { $matched_target_ids{$_->{id}} } @$targets; + # Filter targets by portal using target.groups[].portal. + # This works on both TrueNAS CORE (no /iscsi/targetgroup endpoint) and SCALE. + my @matched = grep { + my $t = $_; + grep { $our_portal_ids{ $_->{portal} } } @{ $t->{groups} // [] }; + } @$targets; if (@matched == 0) { die "No iSCSI targets found for portal $portal_ip on $host. "