2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-05 04:27:55 +00:00

feat(confluent): export the switch and port of each node

makeconfluentcfg gives confluent the console settings, the credentials of the
hardware manager, the location and the enclosure of each node. It does not
give the switch and the port that the node is cabled to, which confluent uses
to find a node by the port it answers on.

Read the switch table and give confluent net.switch and net.switchport.

A node has one row in that table for each of its interfaces, thus keep every
row and not the first one. A row that names an interface gives
net.<interface>.switch and net.<interface>.switchport, so a node with more
than one interface keeps the port of each. A row that names no interface
gives the names without an interface.

Read the table with the node list when the command receives a node range and
read the whole table when it does not, as the command already does for the
other tables.

A cluster whose switch table is empty receives the configuration that it
receives today.

Recovered from the lenovobuild branch, where this arrived as one commit and
two repairs of it: the first keeps one row for each node, which loses every
interface but one, and reads the switch columns from the nodepos table in the
branch that takes no node range, where that table has no such columns and the
feature does nothing.
This commit is contained in:
Vinícius Ferrão
2026-08-27 12:34:10 -03:00
parent b2ad18137b
commit 16c88d8966
+50 -2
View File
@@ -235,15 +235,18 @@ sub makeconfluentcfg {
my $hmtab = xCAT::Table->new('nodehm');
my $nodepostab = xCAT::Table->new('nodepos');
my $mptab = xCAT::Table->new('mp');
my $switchtab = xCAT::Table->new('switch');
my @cfgents1; # = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver','termserver','termport']);
my @cfgents2;
my @cfgents3;
my @cfgents4;
my $explicitnodes = 0;
if (($nodes and @$nodes > 0) or $req->{noderange}->[0]) {
$explicitnodes = 1;
@cfgents1 = $hmtab->getNodesAttribs($nodes, [ 'node', 'cons', 'mgt', 'conserver', 'termserver', 'termport', 'consoleondemand' ]);
@cfgents2 = $nodepostab->getNodesAttribs($nodes, [ 'node', 'rack', 'u', 'chassis', 'slot', 'room' ]);
@cfgents3 = $mptab->getNodesAttribs($nodes, [ 'node', 'mpa', 'id' ]);
@cfgents4 = $switchtab->getNodesAttribs($nodes, [ 'node', 'switch', 'port', 'interface' ]);
# Adjust the data structure to make the result consistent with the getAllNodeAttribs() call we make if a noderange was not specified
my @tmpcfgents1;
@@ -279,16 +282,32 @@ sub makeconfluentcfg {
}
}
@cfgents3 = @tmpcfgents1;
@tmpcfgents1 = ();
foreach my $ent (@cfgents4)
{
foreach my $nodeent (keys %$ent)
{
foreach my $row (@{ $ent->{$nodeent} })
{
next unless ($row);
$row->{node} = $nodeent unless (defined($row->{node}));
push @tmpcfgents1, $row;
}
}
}
@cfgents4 = @tmpcfgents1;
} else {
@cfgents1 = $hmtab->getAllNodeAttribs([ 'cons', 'serialport', 'mgt', 'conserver', 'termserver', 'termport', 'consoleondemand' ]);
@cfgents2 = $nodepostab->getAllNodeAttribs([ 'rack', 'u', 'chassis', 'slot', 'room' ]);
@cfgents3 = $nodepostab->getAllNodeAttribs([ 'mpa', 'id' ]);
@cfgents4 = $switchtab->getAllNodeAttribs([ 'node', 'switch', 'port', 'interface' ]);
}
#cfgents1 should now have all the nodes, so we can fill in the cfgents array and cfgenthash one at a time.
# skip the nodes that do not have 'cons' defined, unless a serialport setting suggests otherwise
my %cfgenthash;
my %cfgnichash;
foreach (@cfgents1) {
if ($_->{cons} or defined($_->{'serialport'})) {
unless ($_->{cons}) { $_->{cons} = $_->{mgt}; } #populate with fallback
@@ -307,6 +326,19 @@ sub makeconfluentcfg {
$cfgenthash{ $nent->{node} }->{$_} = $nent->{$_};
}
}
foreach my $nent (@cfgents4) {
next unless (defined $nent->{node});
if (defined $nent->{interface} and length $nent->{interface}) {
foreach (keys %$nent) {
$cfgnichash{ $nent->{node} }->{ $nent->{interface} }->{$_} = $nent->{$_};
}
$cfgenthash{ $nent->{node} }->{node} = $nent->{node};
} else {
foreach (keys %$nent) {
$cfgenthash{ $nent->{node} }->{$_} = $nent->{$_};
}
}
}
my @cfgents = ();
foreach (values %cfgenthash) {
push @cfgents, $_;
@@ -325,7 +357,7 @@ sub makeconfluentcfg {
#if (($req->{_allnodes}) && ($req->{_allnodes}->[0]==1)) {} #TODO: identify nodes that will be removed
# call donodeent to add all node entries into the file. It will return the 1st node in error.
my $node;
if ($node = donodeent(\%cfgenthash, $confluent, $delmode, $cb)) {
if ($node = donodeent(\%cfgenthash, $confluent, $delmode, $cb, \%cfgnichash)) {
#$cb->({node=>[{name=>$node,error=>"Bad configuration, check attributes under the nodehm category",errorcode=>1}]});
xCAT::SvrUtils::sendmsg([ 1, "Bad configuration, check attributes under the nodehm category" ], $cb, $node);
@@ -366,7 +398,7 @@ sub makeconfluentcfg {
# Now add into the file all the node entries that we kept
my $node;
if ($node = donodeent(\%cfgenthash, $confluent, undef, $cb)) {
if ($node = donodeent(\%cfgenthash, $confluent, undef, $cb, \%cfgnichash)) {
# donodeent will return the 1st node in error
#$cb->({node=>[{name=>$node,error=>"Bad configuration, check attributes under the nodehm category",errorcode=>1}]});
@@ -384,6 +416,7 @@ sub donodeent {
my $confluent = shift;
my $delmode = shift;
my $cb = shift;
my $cfgnichash = shift || {};
my $idx = 0;
my $toidx = -1;
my $skip = 0;
@@ -510,6 +543,21 @@ sub donodeent {
} elsif (defined $cfgent->{id}) {
$parameters{'enclosure.bay'} = $cfgent->{id};
}
if (defined $cfgent->{switch}) {
$parameters{'net.switch'} = $cfgent->{switch};
}
if (defined $cfgent->{port}) {
$parameters{'net.switchport'} = $cfgent->{port};
}
foreach my $nic (keys %{ $cfgnichash->{$node} || {} }) {
my $nicent = $cfgnichash->{$node}->{$nic};
if (defined $nicent->{switch}) {
$parameters{"net.$nic.switch"} = $nicent->{switch};
}
if (defined $nicent->{port}) {
$parameters{"net.$nic.switchport"} = $nicent->{port};
}
}
$parameters{'groups'} = [ grep { defined && length } split /,/, $groupdata->{$node}->[0]->{'groups'} ];
if (exists $currnodes{$node}) {
$confluent->update('/nodes/' . $node . '/attributes/current', parameters => \%parameters);