2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-28 13:22:16 +00:00

refactor(dhcp): return the DHCPv6 host commands from addnode6

addnode6 printed its omshell commands to a file-scope handle, so no test
could read the DHCPv6 host that ISC DHCP is told to create. It now
returns the commands, and makedhcp prints them to the same omshell
session. The commands and their order do not change.

(cherry picked from commit 178de13a677ffe9326ed9cc697a063de39337e42)
(cherry picked from commit d7c8c41a07)
This commit is contained in:
Vinícius Ferrão
2026-10-23 17:01:22 -03:00
committed by Daniel Hilst
parent cfbe2495a5
commit dfe1fa4b0a
+28 -25
View File
@@ -781,7 +781,7 @@ sub delnode
sub addnode6 {
#omshell to add host dynamically
# The omshell commands that add the host, or nothing when the node is skipped.
my $node = shift;
unless ($vpdhash) {
$callback->({ node => [ { name => [$node], warning => ["Skipping DHCPv6 setup due to missing vpd.uuid information."] } ] });
@@ -817,44 +817,46 @@ sub addnode6 {
if ( $ip and $ip =~ /:/ and _reject_dynamic_node_ip( $node, $ip, 'IPv6', $callback ) ) {
return;
}
my $commands = '';
if ($ip and $ip =~ /:/) {
$ip = getipaddr($ip, GetNumber => 1);
$ip = $ip->as_hex;
$ip =~ s/^0x//;
$ip =~ s/(..)/$1:/g;
$ip =~ s/:\z//;
print $omshell6 "set ip-address = $ip\n";
$commands .= "set ip-address = $ip\n";
} else {
$ip = 0;
}
print $omshell6 "new host\n";
print $omshell6 "set name = \"$node\"\n"; #Find and destroy conflict name
print $omshell6 "open\n";
print $omshell6 "remove\n";
print $omshell6 "close\n";
$commands .= "new host\n";
$commands .= "set name = \"$node\"\n"; #Find and destroy conflict name
$commands .= "open\n";
$commands .= "remove\n";
$commands .= "close\n";
if ($ip) {
print $omshell6 "new host\n";
print $omshell6 "set ip-address = $ip\n"; #find and destroy ip conflict
print $omshell6 "open\n";
print $omshell6 "remove\n";
print $omshell6 "close\n";
$commands .= "new host\n";
$commands .= "set ip-address = $ip\n"; #find and destroy ip conflict
$commands .= "open\n";
$commands .= "remove\n";
$commands .= "close\n";
}
print $omshell6 "new host\n";
print $omshell6 "set dhcp-client-identifier = " . $uuid . "\n"; #find and destroy DUID-UUID conflict
print $omshell6 "open\n";
print $omshell6 "remove\n";
print $omshell6 "close\n";
print $omshell6 "new host\n";
print $omshell6 "set name = \"$node\"\n";
print $omshell6 "set dhcp-client-identifier = $uuid\n";
print $omshell6 'set statements = "ddns-hostname \"' . $node . '\";";' . "\n";
$commands .= "new host\n";
$commands .= "set dhcp-client-identifier = " . $uuid . "\n"; #find and destroy DUID-UUID conflict
$commands .= "open\n";
$commands .= "remove\n";
$commands .= "close\n";
$commands .= "new host\n";
$commands .= "set name = \"$node\"\n";
$commands .= "set dhcp-client-identifier = $uuid\n";
$commands .= 'set statements = "ddns-hostname \"' . $node . '\";";' . "\n";
if ($ip) {
print $omshell6 "set ip-address = $ip\n";
$commands .= "set ip-address = $ip\n";
}
print $omshell6 "create\n";
print $omshell6 "close\n";
$commands .= "create\n";
$commands .= "close\n";
return $commands;
}
sub _infiniband_twin_mac
@@ -2684,7 +2686,8 @@ sub process_request
next if $unchanged->{$_};
addnode $_;
if ($usingipv6) {
addnode6 $_;
my $commands = addnode6($_);
print $omshell6 $commands if $commands;
}
}
}