2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-22 23:58:13 +00:00

refactor(http): share port suffix formatting across boot callers

This commit is contained in:
Vinícius Ferrão
2026-10-08 16:19:31 -03:00
parent a6bf1a8695
commit 937f6895f0
6 changed files with 36 additions and 16 deletions
+5 -4
View File
@@ -2,6 +2,7 @@ package xCAT::DHCP::BootPolicy;
use strict;
use warnings;
use xCAT::HTTPUtils qw(httpport_suffix);
sub kea_client_classes {
my ( $class, %opts ) = @_;
@@ -166,7 +167,7 @@ sub kea_httpboot_network_classes {
return [] unless $opts{net} && defined( $opts{prefix} ) && $opts{next_server};
my $httpport = $opts{httpport} || '80';
my $portsuffix = ( $httpport eq '80' ) ? '' : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $tftpdir = $opts{tftpdir} || '/tftpboot';
$tftpdir =~ s{/+$}{};
my $http_tftp_root = '/tftpboot';
@@ -233,7 +234,7 @@ sub kea_onie_network_classes {
return [] unless $opts{net} && defined( $opts{prefix} ) && $opts{next_server};
my $httpport = $opts{httpport} || '80';
my $portsuffix = ( $httpport eq '80' ) ? '' : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $name = "xcat-onie-$opts{net}_$opts{prefix}";
$name =~ s{[^A-Za-z0-9_.-]}{_}gxms;
@@ -460,7 +461,7 @@ sub kea_xnba_node_classes {
next unless $node->{next_server};
my $httpport = $node->{httpport} || '80';
my $portsuffix = ( $httpport eq '80' ) ? '' : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $base_url = 'http://' . $node->{next_server} . $portsuffix . "/tftpboot/$loader->{scripts}/nodes/" . $node->{node};
push @classes, {
@@ -713,7 +714,7 @@ sub kea_xnba_network_classes {
my $loader = $class->x86_loader( method => 'ipxe' );
my $uefi_x64_arch_match = uefi_x64_client_architecture_match_expr();
my $httpport = $opts{httpport} || '80';
my $portsuffix = ( $httpport eq '80' ) ? '' : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $network_id = $opts{net} . '_' . $opts{prefix};
my $safe_network = $network_id;
$safe_network =~ s/[^A-Za-z0-9_.-]/_/g;
+16
View File
@@ -0,0 +1,16 @@
# IBM(c) 2026 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::HTTPUtils;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT_OK = qw(httpport_suffix);
# Callers choose the default port before formatting it.
sub httpport_suffix {
my $port = shift // '';
return $port eq '80' ? '' : ":$port";
}
1;
+2 -2
View File
@@ -13,6 +13,7 @@ use File::Path;
use Sys::Syslog;
use xCAT::ADUtils; #to allow setting of one-time machine passwords
use xCAT::Utils;
use xCAT::HTTPUtils ();
use xCAT::TableUtils;
use xCAT::NetworkUtils;
use xCAT::PasswordUtils;
@@ -50,8 +51,7 @@ my %tab_replacement = (
sub httpport_suffix {
my $httpport = shift;
$httpport = "80" unless defined $httpport and length $httpport;
return "" if $httpport eq "80";
return ":$httpport";
return xCAT::HTTPUtils::httpport_suffix($httpport);
}
sub subvars {
+8 -7
View File
@@ -31,6 +31,7 @@ my $candoipv6 = eval {
use Sys::Syslog;
use IPC::Open2;
use xCAT::Utils;
use xCAT::HTTPUtils qw(httpport_suffix);
use xCAT::SvrUtils;
use xCAT::DHCP::BootPolicy;
use xCAT::DHCP::Backend;
@@ -1092,7 +1093,7 @@ sub addnode
if ($hports[0]){
$httpport=$hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
if ($chainents and $chainents->{$node}) {
$chainent = $chainents->{$node}->[0];
@@ -2927,7 +2928,7 @@ sub kea_build_dhcp4_intent
if ($hports[0]) {
$httpport = $hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $nettab = xCAT::Table->new("networks");
return { error => "Unable to open networks table, please run makenetworks" } unless $nettab;
@@ -3515,7 +3516,7 @@ sub kea_command_path
sub kea_subnet4_intent
{
my ( $nettab, $net, $mask, $interface, $remote, $id, $httpport ) = @_;
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my @myipd = xCAT::NetworkUtils->my_ip_facing($net);
my $myip;
@@ -3636,7 +3637,7 @@ sub kea_subnet4_intent
sub kea_opal_client_class
{
my ( $net, $prefix, $tftp, $httpport ) = @_;
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
return unless $net && defined($prefix) && $tftp;
@@ -4381,7 +4382,7 @@ sub kea_boot_for_node
if ($hports[0]) {
$httpport = $hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my %boot = ( 'option-data' => [] );
my $netboot = $nrent ? $nrent->{netboot} : undef;
@@ -4429,7 +4430,7 @@ sub kea_boot_for_node
sub kea_onie_url_for_node
{
my ( $node, $ntent, $nxtsrv, $httpport ) = @_;
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
return unless $nxtsrv;
my $provmethod = $ntent ? $ntent->{provmethod} : undef;
@@ -4830,7 +4831,7 @@ sub addnet
if ($hports[0]){
$httpport=$hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
my $firstoctet = $net;
$firstoctet =~ s/^(\d+)\..*/$1/;
if ($net eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239)) {
+3 -2
View File
@@ -3,6 +3,7 @@ use strict;
use Digest::SHA ();
use File::Temp qw(tempdir tempfile);
use xCAT::Utils;
use xCAT::HTTPUtils qw(httpport_suffix);
use xCAT::TableUtils;
use xCAT::NodeRange;
use File::Path;
@@ -434,7 +435,7 @@ sub process_request {
if ($hports[0]){
$httpport=$hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
@entries = xCAT::TableUtils->get_site_attribute("dhcpinterfaces");
$t_entry = $entries[0];
@@ -1075,7 +1076,7 @@ sub _write_grub2_discovery_config {
# loads it over HTTP like netboot=grub2-http; the TFTP entry is for a management
# node that does not serve the TFTP root over HTTP.
my $httpport = $args{httpport} || '80';
my $httproot = 'http,' . $args{xcatd_address} . ($httpport eq '80' ? '' : ":$httpport");
my $httproot = 'http,' . $args{xcatd_address} . httpport_suffix($httpport);
my $http_tftp_root = '/tftpboot';
my $tftproot = 'tftp,' . $args{xcatd_address};
my $content = "# xCAT Genesis discovery for network $hexnet - generated by mknb, do not edit\n";
+2 -1
View File
@@ -9,6 +9,7 @@ use xCAT::Scope;
use xCAT::MsgUtils;
use Getopt::Long;
use xCAT::Utils;
use xCAT::HTTPUtils qw(httpport_suffix);
require xCAT::BootUtils;
use xCAT::TableUtils;
use xCAT::ServiceNodeUtils;
@@ -164,7 +165,7 @@ sub setstate {
if ($hports[0]){
$httpport=$hports[0];
}
my $portsuffix = ( $httpport eq "80" ) ? "" : ":$httpport";
my $portsuffix = httpport_suffix($httpport);
# get kernel and initrd from boottarget table
my $bttab;