From 96d351c8ffe2a46c9ab8d0415a8f8eff9002927f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:25:14 -0300 Subject: [PATCH] refactor(template): share the install device resolution The order that names the install device is noderes.installnic, then noderes.primarynic, then mac.mac. gen_net_boot_params owns that order for the netboot kernel parameters. Only the Ubuntu template reused it. Every other install template reads mac.mac on its own. Move the reuse into install_device_params so that any install template can share it. subiquity_install_netcfg keeps its own name and its own return value, because netplan needs the pair of a name and an address. Behaviour does not change. --- xCAT-server/lib/perl/xCAT/Template.pm | 35 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index d02048c88..e2d077e4c 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -1664,19 +1664,47 @@ sub crydb_or_locked #-------------------------------------------------------------------------------- -=head3 subiquity_install_netcfg +=head3 install_device_params Resolve the interface the INSTALLED system must bring up, in xCAT's own order: noderes.installnic, else noderes.primarynic, else match on mac.mac. Either attribute may name an interface OR carry a MAC address. xCAT::NetworkUtils::gen_net_boot_params already owns that order for the netboot kernel parameters, so it is reused here rather than re-derived -- and in - particular the install template never re-derives any part of it in shell. + particular an install template never re-derives any part of it in shell. + + Every install template that has to name the install device shares this resolution, so the + device an installer configures cannot disagree with the device the netboot kernel parameters + name. The resolution carries no boot loader dependency of any kind. Arguments: $installnic - noderes.installnic (may be undef or empty) $primarynic - noderes.primarynic (may be undef or empty) $macentry - the raw mac.mac entry (may hold |-separated, !hostname-suffixed entries) $nodename - the node the entry is resolved for + Returns: + the hash reference from gen_net_boot_params. Of interest to install templates: + nicname - the interface name, set only when installnic/primarynic names an interface + mac - the address, set whenever one is known + +=cut + +#-------------------------------------------------------------------------------- +sub install_device_params { + my ($installnic, $primarynic, $macentry, $nodename) = @_; + + my $macmac = xCAT::Utils->parseMacTabEntry(defined($macentry) ? $macentry : '', $nodename); + return xCAT::NetworkUtils->gen_net_boot_params($installnic, $primarynic, $macmac); +} + +#-------------------------------------------------------------------------------- + +=head3 subiquity_install_netcfg + + Shape install_device_params for netplan, which matches a device by MAC and optionally renames + it. + + Arguments: + as install_device_params Returns: ($setname, $macaddress) $setname - the name netplan must rename the matched device to, empty when the device is @@ -1689,8 +1717,7 @@ sub crydb_or_locked sub subiquity_install_netcfg { my ($installnic, $primarynic, $macentry, $nodename) = @_; - my $macmac = xCAT::Utils->parseMacTabEntry(defined($macentry) ? $macentry : '', $nodename); - my $params = xCAT::NetworkUtils->gen_net_boot_params($installnic, $primarynic, $macmac); + my $params = install_device_params($installnic, $primarynic, $macentry, $nodename); my $setname = defined($params->{nicname}) ? $params->{nicname} : ''; my $macaddress = defined($params->{mac}) ? lc($params->{mac}) : '';