From 725823a0a3923fbec9679f30d38a5cd9dbde84b3 Mon Sep 17 00:00:00 2001 From: vallard Date: Tue, 5 Jan 2010 20:46:41 +0000 Subject: [PATCH] updated variable substitution git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4897 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/litetree.pm | 64 ++++++++++++++---------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/litetree.pm b/xCAT-server/lib/xcat/plugins/litetree.pm index e93266608..d75349744 100644 --- a/xCAT-server/lib/xcat/plugins/litetree.pm +++ b/xCAT-server/lib/xcat/plugins/litetree.pm @@ -198,43 +198,53 @@ sub subVar { if($p =~ /\$/){ my $pre; my $suf; + my @fParts; if($p =~ /([^\$]*)([^# ]*)(.*)/){ $pre= $1; $p = $2; $suf = $3; } - # have to sub here: # get rid of the $ sign. - $p =~ s/\$//g; - # check if p is just the node name: - - if($p eq 'node'){ - # it is so, just return the node. - $fdir .= "/$pre$node$suf"; - }else{ - # ask the xCAT DB what the attribute is. - my ($table, $col) = split('\.', $p); - my $tab = xCAT::Table->new($table); - my $ent; - my $val; - if($table eq 'site'){ - $val = $tab->getAttribs( { key => "$col" }, 'value' ); - $val = $val->{'value'}; + foreach my $part (split('\$',$p)){ + if($part eq ''){ next; } + #$callback->({error=>["part is $part"],errorcode=>[1]}); + # check if p is just the node name: + if($part eq 'node'){ + # it is so, just return the node. + #$fdir .= "/$pre$node$suf"; + push @fParts, $node; }else{ - $ent = $tab->getNodeAttribs($node,[$col]); - $val = $ent->{$col}; - } - unless($val){ - # couldn't find the value!! - $val = "UNDEFINED" - } - if($type eq 'dir'){ + # ask the xCAT DB what the attribute is. + my ($table, $col) = split('\.', $part); + unless($col){ $col = 'UNDEFINED' }; + my $tab = xCAT::Table->new($table); + unless($tab){ + $callback->({error=>["$table does not exist"],errorcode=>[1]}); + return; + } + my $ent; + my $val; + if($table eq 'site'){ + $val = $tab->getAttribs( { key => "$col" }, 'value' ); + $val = $val->{'value'}; + }else{ + $ent = $tab->getNodeAttribs($node,[$col]); + $val = $ent->{$col}; + } + unless($val){ + # couldn't find the value!! + $val = "UNDEFINED" + } + push @fParts, $val; + } + } + my $val = join('.', @fParts); + if($type eq 'dir'){ $fdir .= "/$pre$val$suf"; - }else{ + }else{ $fdir .= $pre . $val . $suf; - } - } + } }else{ # no substitution here $fdir .= "/$p";