fix: replace /iscsi/targetgroup with target.groups[] for CORE compatibility

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 <noreply@anthropic.com>
This commit is contained in:
Kevin Adams 2026-05-23 21:42:19 -04:00
parent c5868dd4f6
commit 132875a5c5
1 changed files with 6 additions and 7 deletions

View File

@ -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. "