2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 17:46:38 +00:00

Merge pull request #3606 from bybai/postage

fix nicips regular expression in mypostscript
This commit is contained in:
chenglch 2017-08-04 13:47:36 +08:00 committed by GitHub
commit cbec85b60b

View File

@ -18,7 +18,6 @@ use xCAT::Template;
use xCAT::SvrUtils;
use xCAT::Zone;
#use Data::Dumper;
use File::Basename;
use Socket;
use strict;
@ -1436,6 +1435,63 @@ sub getDisklessNet()
return $result;
}
#---------------------------------------------------
=head3 get_nics_nicips
Description: If nicips contain regular expression,
transform the regular expression attribute to the target ip,
then generate new nicips with target ip.
Arguments:
Node
nicips Attribute value (may have regular expression)
Returns:
new nicips Attribute value
Globals:
Error:
Example:
$nicips = transRegexAttrs($node, $nicips_with_regex)
Comments:
none
=cut
#---------------------------------------------------
sub get_nics_nicips
{
my $node = shift;
my $old_nicips = shift;
my $new_nicips;
my $nicname;
my $nicip;
if (defined($old_nicips)) {
my @nicandiplist = split(',', $old_nicips);
foreach (@nicandiplist)
{
#if it contains a "!" then split on "!"
if ($_ =~ /!/) {
($nicname, $nicip) = split('!', $_);
} else {
($nicname, $nicip) = split(':', $_);
}
if (!$nicip) {
next;
}
#If there is one nicip in nicips, and it is regular expression
#for example: eth0!|\D+(\d+)\D+|10.80.1.($1*2+103)|
#Does not support: there is regular expression in multple nicips
if ($nicip =~ /^\|\S*\|$/) {
#transform the regular expression attribute to the target ip
$nicip = xCAT::Table::transRegexAttrs($node, $nicip);
}
#generate new nicips
if (defined($new_nicips)) {
$new_nicips.=",".$nicname."!".$nicip;
} else {
$new_nicips=$nicname."!".$nicip;
}
}
}
return $new_nicips;
}
sub collect_all_attribs_for_tables_in_template
{
@ -1473,7 +1529,6 @@ sub collect_all_attribs_for_tables_in_template
if ($ent->{$node}->[0]) {
foreach my $attrib (@attribs) {
$::GLOBAL_TAB_HASH{$tabname}{$node}{$attrib} = $ent->{$node}->[0]->{$attrib};
#for noderes.xcatmaster
if ($tabname =~ /^noderes$/ && $attrib =~ /^xcatmaster$/ &&
(!exists($::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster}) ||
@ -1510,14 +1565,17 @@ sub collect_all_attribs_for_tables_in_template
!defined($::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster})) {
$::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster} = $::XCATSITEVALS{master};
}
#If nicips contains regular expression
if (exists($::GLOBAL_TAB_HASH{nics}{$node}{nicips}) && $::GLOBAL_TAB_HASH{nics}{$node}{nicips} =~ /\S*\!\|\S*/)
{
$::GLOBAL_TAB_HASH{nics}{$node}{nicips}=get_nics_nicips($node,$ent->{$node}->[0]->{nicips});
}
if (!defined($::GLOBAL_TAB_HASH{noderes}{$node}{nfsserver})) {
$::GLOBAL_TAB_HASH{noderes}{$node}{nfsserver} = $::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster};
}
if (!defined($::GLOBAL_TAB_HASH{noderes}{$node}{tftpserver})) {
$::GLOBAL_TAB_HASH{noderes}{$node}{tftpserver} = $::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster};
}
#if the values are not got, we will set them to '';
foreach my $attrib (@attribs) {
if (!defined($::GLOBAL_TAB_HASH{$tabname}) || !defined($::GLOBAL_TAB_HASH{$tabname}{$node}) || !defined($::GLOBAL_TAB_HASH{$tabname}{$node}{$attrib})) {