From 447b00af5b3b6373ad2904bc30917c1360342f06 Mon Sep 17 00:00:00 2001 From: bybai Date: Thu, 3 Aug 2017 04:52:11 -0400 Subject: [PATCH 1/3] enhance nicips regular expression in mypostscript --- xCAT-server/lib/perl/xCAT/Postage.pm | 65 +++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index d1f56e36b..d636f103f 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -1436,6 +1436,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 +1530,12 @@ 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}; - + #If nicips contains regular expression + if ($tabname =~ /^nics$/ && $attrib =~ /^nicips$/ && + $::GLOBAL_TAB_HASH{nics}{$node}{nicips} =~ /\S*\!\|\S*/) + { + $::GLOBAL_TAB_HASH{nics}{$node}{nicips}=get_nics_nicips($node,$::GLOBAL_TAB_HASH{nics}{$node}{nicips}); + } #for noderes.xcatmaster if ($tabname =~ /^noderes$/ && $attrib =~ /^xcatmaster$/ && (!exists($::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster}) || @@ -1517,7 +1579,6 @@ sub collect_all_attribs_for_tables_in_template 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})) { From c87dd2c763e24956616391286751d2f4591dc5c4 Mon Sep 17 00:00:00 2001 From: bybai Date: Fri, 4 Aug 2017 00:33:54 -0400 Subject: [PATCH 2/3] polished --- xCAT-server/lib/perl/xCAT/Postage.pm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index d636f103f..3e7743aa2 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -18,7 +18,7 @@ use xCAT::Template; use xCAT::SvrUtils; use xCAT::Zone; -#use Data::Dumper; +use Data::Dumper; use File::Basename; use Socket; use strict; @@ -1530,12 +1530,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}; - #If nicips contains regular expression - if ($tabname =~ /^nics$/ && $attrib =~ /^nicips$/ && - $::GLOBAL_TAB_HASH{nics}{$node}{nicips} =~ /\S*\!\|\S*/) - { - $::GLOBAL_TAB_HASH{nics}{$node}{nicips}=get_nics_nicips($node,$::GLOBAL_TAB_HASH{nics}{$node}{nicips}); - } #for noderes.xcatmaster if ($tabname =~ /^noderes$/ && $attrib =~ /^xcatmaster$/ && (!exists($::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster}) || @@ -1572,7 +1566,11 @@ 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}; } From 12923fdd74b43ae8e3c22ecd9401a17f36e55fa5 Mon Sep 17 00:00:00 2001 From: bybai Date: Fri, 4 Aug 2017 01:07:41 -0400 Subject: [PATCH 3/3] polished --- xCAT-server/lib/perl/xCAT/Postage.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 3e7743aa2..ffcc0ba8d 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -18,7 +18,6 @@ use xCAT::Template; use xCAT::SvrUtils; use xCAT::Zone; -use Data::Dumper; use File::Basename; use Socket; use strict;