From 00d1d94d722690422d2a722db9cfc21c7dcd9f6c Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 4 Mar 2017 10:50:01 -0500 Subject: [PATCH] Revert "Make nics attribute inhertable" It was broken. This reverts commit 98785fbddf464c9983d294fd38033394554bbfa5. --- perl-xCAT/xCAT/DBobjUtils.pm | 9 +- perl-xCAT/xCAT/Table.pm | 158 ++++++++----------- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 8 +- 3 files changed, 81 insertions(+), 94 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 31bc6c14a..5400fb7c8 100755 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -424,6 +424,7 @@ sub getobjdefs # get the key to look for, for this object type my $objkey = $datatype->{'objkey'}; + # go through the list of valid attrs foreach my $this_attr (@{ $datatype->{'attrs'} }) { my $ent; @@ -486,6 +487,7 @@ sub getobjdefs my $intabhash = 0; my $notsearched = 0; foreach my $lookup_attr (keys %{ $tabentry{'lookup_attrs'} }) { + # Check whether the attribute is already in %tabhash # The %tabhash is for performance considerations if (($lookup_attr eq 'node') && ($objtype eq 'node')) { @@ -511,6 +513,7 @@ sub getobjdefs # Not in tabhash, # Need to lookup the table if ($intabhash == 0 && $notsearched == 1) { + # look up attr values my @rows = xCAT::DBobjUtils->getDBtable($lookup_table); if (@rows) { @@ -2499,7 +2502,6 @@ sub judge_node Arguments: nicsattr value, like niccsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 - node name, like frame10node10 nicnames: only return the value for specific nics, like "eth0,eth1" Returns: expanded format, like: @@ -2522,8 +2524,8 @@ sub expandnicsattr() if (($nicstr) && ($nicstr =~ /xCAT::/)) { $nicstr = shift; } - my $node = shift; my $nicnames = shift; + my $ret; $nicstr =~ /^(.*?)=(.*?)$/; @@ -2545,6 +2547,7 @@ sub expandnicsattr() #$nicval Value: node(d+)|eth0!192.1.1.($1+10) if (($nicval) && ($nicval =~ /\|/)) { my ($str1, $str2) = split('\|', $nicval); + #$nivval Value: eth0!192.1.1.($1+10) $nicval = $str2; } @@ -2573,7 +2576,6 @@ sub expandnicsattr() } } - $nicv[1]= xCAT::Table::transRegexAttrs($node, $nicv[1]); # ignore the line that does not have nicname or value if ($nicv[0] && $nicv[1]) { $ret .= " $nicattr.$nicv[0]=$nicv[1]\n"; @@ -2626,6 +2628,7 @@ sub collapsenicsattr() $nodeattrhash = shift; } my $objname = shift; + my %nicattrs = (); foreach my $nodeattr (keys %{$nodeattrhash}) { diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 5f1714f50..67b1b2b8f 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -2299,91 +2299,6 @@ $evalcpt->permit('require'); #-------------------------------------------------------------------------- -=head3 transRegexAttrs - - Description: Transform the regular expression attribute to the target value - based on the node name. - - Arguments: - Node - Attribute value (may have regular expression) - Returns: - Attribute value - undef - Globals: - - Error: - - Example: - if (defined($retval = transRegexAttrs($node, $datum->{$attrib}))) { - $datum->{$attrib} = $retval; - } else { - delete $datum->{$attrib}; - } - - Comments: - none - -=cut - -#--------------------------------------------------------------------------- -sub transRegexAttrs -{ - my ($node, $attr) = @_; - my $retval = $attr; - if ($attr =~ /^\/[^\/]*\/[^\/]*\/$/) { - my $exp = substr($attr, 1); - chop $exp; - my @parts = split('/', $exp, 2); - $retval = $node; - $retval =~ s/$parts[0]/$parts[1]/; - } elsif ($attr =~ /^\|.*\|$/) { - my $exp = substr($attr, 1); - chop $exp; - my @parts = split('\|', $exp, 2); - my $arraySize = @parts; - if ($arraySize < 2) { # easy regx, generate lhs from node - my $lhs; - my @numbers = $node =~ m/[\D0]*(\d+)/g; - $lhs = '[\D0]*(\d+)' x scalar(@numbers); - $lhs .= '.*$'; - unshift(@parts, $lhs); - } - my ($curr, $next, $prev); - $retval = $parts[1]; - - ($curr, $next, $prev) = - extract_bracketed($retval, '()', qr/[^()]*/); - unless ($curr) { #If there were no paramaters to save, treat this one like a plain regex - undef $@; #extract_bracketed would have set $@ if it didn't return, undef $@ - $retval = $node; - $retval =~ s/$parts[0]/$parts[1]/; - } - while ($curr) - { - my $value = $node; - $value =~ s/$parts[0]/$curr/; - $value = $evalcpt->reval('use integer;' . $value); - $retval = $prev . $value . $next; - ($curr, $next, $prev) = - extract_bracketed($retval, '()', qr/[^()]*/); - } - undef $@; - - #At this point, $retval is the expression after being arithmetically contemplated, a generated regex, and therefore - #must be applied in total - my $answval = $node; - $answval =~ s/$parts[0]/$retval/; - $retval = $answval; - } - if ($retval =~ /^$/) { - $retval = undef; - } - return $retval; -} - -#-------------------------------------------------------------------------- - =head3 getNodeAttribs Description: Retrieves the requested attribute @@ -2477,10 +2392,77 @@ sub getNodeAttribs #skip undefined values, save time next; } - my $retval; - if (defined($retval = transRegexAttrs($node, $datum->{$attrib}))) { + if ($datum->{$attrib} =~ /^\/[^\/]*\/[^\/]*\/$/) + { + my $exp = substr($datum->{$attrib}, 1); + chop $exp; + my @parts = split('/', $exp, 2); + my $retval = $node; + $retval =~ s/$parts[0]/$parts[1]/; $datum->{$attrib} = $retval; - } else { + } + elsif ($datum->{$attrib} =~ /^\|.*\|$/) + { + + #Perform arithmetic and only arithmetic operations in bracketed issues on the right. + #Tricky part: don't allow potentially dangerous code, only eval if + #to-be-evaled expression is only made up of ()\d+-/%$ + #Futher paranoia? use Safe module to make sure I'm good + my $exp = substr($datum->{$attrib}, 1); + chop $exp; + my @parts = split('\|', $exp, 2); + my $arraySize = @parts; + if ($arraySize < 2) { # easy regx, generate lhs from node + my $lhs; + my @numbers = $node =~ m/[\D0]*(\d+)/g; + $lhs = '[\D0]*(\d+)' x scalar(@numbers); + $lhs .= '.*$'; + unshift(@parts, $lhs); + } + my $curr; + my $next; + my $prev; + my $retval = $parts[1]; + ($curr, $next, $prev) = + extract_bracketed($retval, '()', qr/[^()]*/); + + unless ($curr) { #If there were no paramaters to save, treat this one like a plain regex + undef $@; #extract_bracketed would have set $@ if it didn't return, undef $@ + $retval = $node; + $retval =~ s/$parts[0]/$parts[1]/; + $datum->{$attrib} = $retval; + if ($datum->{$attrib} =~ /^$/) { + + #If regex forces a blank, act like a normal blank does + delete $datum->{$attrib}; + } + next; #skip the redundancy that follows otherwise + } + while ($curr) + { + + #my $next = $comps[0]; + my $value = $node; + $value =~ s/$parts[0]/$curr/; + $value = $evalcpt->reval('use integer;' . $value); + $retval = $prev . $value . $next; + ($curr, $next, $prev) = + extract_bracketed($retval, '()', qr/[^()]*/); + } + undef $@; + + #At this point, $retval is the expression after being arithmetically contemplated, a generated regex, and therefore + #must be applied in total + my $answval = $node; + $answval =~ s/$parts[0]/$retval/; + $datum->{$attrib} = $answval; #$retval; + + #print Data::Dumper::Dumper(extract_bracketed($parts[1],'()',qr/[^()]*/)); + #use text::balanced extract_bracketed to parse earch atom, make sure nothing but arith operators, parans, and numbers are in it to guard against code execution + } + if ($datum->{$attrib} =~ /^$/) { + + #If regex forces a blank, act like a normal blank does delete $datum->{$attrib}; } } diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index d91d51c3e..90ddb541f 100755 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -2973,6 +2973,7 @@ sub setFINALattrs } } } + # $tmphash{nicips} = "eth0!1.1.1.1|1.2.1.1,eth1!2.1.1.1|2.2.1.1" foreach my $nicattr (keys %tmphash) { @@ -3188,6 +3189,7 @@ sub defls } } + # if just provided type list then find all objects of these types if (!defined $::opt_template && $::objectsfrom_optt) { @@ -3843,11 +3845,11 @@ sub defls my $nicsstr; if ($nicnames) { - $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval, $obj, $nicnames); + $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval, $nicnames); } else { - $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval, $obj); + $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval); } # Compress mode, format the output @@ -3900,7 +3902,7 @@ sub defls if ($showattr =~ /^nic/) { my $nicval = "$showattr=$attrval"; - my $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval, $obj); + my $nicsstr = xCAT::DBobjUtils->expandnicsattr($nicval); if ($nicsstr) { push(@{ $rsp_info->{data} }, "$nicsstr");