diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 3c7d6814d..7a67440fe 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -1723,6 +1723,29 @@ sub getAttribs { unless ($data->{$attrib} =~ /^$/ || !defined($data->{$attrib})) { #To undef fields in rows that may still be returned + + my $wrkstr = $data->{$attrib}; + while ($wrkstr =~ /(\{.*?\})/g) { + #-- this have to be thoroughly tested... + #-- special constructions in tables + #-- for example allows to have the same database for two xCAT master servers + #-- hence helping xCAT high availability + my $exp = $1; + my $expfound = 0; + + $exp =~ /^{hostname}$/ && do { $out = qx/hostname/; chomp $out; $expfound = 1; }; + $exp =~ /^{xcatmaster}$/ && do { + my $ostab = xCAT::Table->new('site'); + $out = $ostab->getAttribs({key=>"master"},'value'); + if ($out and $out->{value}) { + $out = $out->{'value'}; $expfound = 1; + } + }; + $wrkstr =~ s/$exp/$out/ if $expfound; + + } + $data->{$attrib} = $wrkstr; + $rethash{$attrib} = $data->{$attrib}; } } diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index d5e855f69..e057bb702 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -296,6 +296,23 @@ sub mknetboot } } } + + # Has to be tested... + # + # Try to insert special idiom {xcatmaster} to bootparams table if the above + # value resolves to the same value as {xcatmaster}. + # This allows avoiding xcatmaster hostname where possible, thus allowing + # to keep database very clean and minimize needed changes in db + # when moving xcat to another node. + #-- test whether special construction '{xcatmater}' is supported in Table.pm + $sitetab->setAttribs( {'key' => 'testkey'}, {'value' => '{xcatmaster}'} ); + my $testvalue = $sitetab->getAttribs({key => "testkey"}, 'value'); + #-- now "testkey" will _NOT_ contain '{xcatmaster}' if special substitutions are supported + if ( $testvalue->{"value"} eq $imgsrv ) { #-- xCAT supports interpolation of '{xcatmaster}' + $imgsrv = '{xcatmaster}'; + } + $sitetab->delEntries( {'key' => 'testkey'} ); #-- clean up + unless ($imgsrv) { $callback->( diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 29ee72077..cb41aff1b 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -167,6 +167,24 @@ sub mknetboot } } } + + # Has to be tested... + # + # Try to insert special idiom {xcatmaster} to bootparams table if the above + # value resolves to the same value as {xcatmaster}. + # This allows avoiding xcatmaster hostname where possible, thus allowing + # to keep database very clean and minimize needed changes in db + # when moving xcat to another node. + + #-- test whether special construction '{xcatmater}' is supported in Table.pm + $sitetab->setAttribs( {'key' => 'testkey'}, {'value' => '{xcatmaster}'} ); + my $testvalue = $sitetab->getAttribs({key => "testkey"}, 'value'); + #-- now "testkey" will _NOT_ contain '{xcatmaster}' if special substitutions are supported + if ( $testvalue->{"value"} eq $imgsrv ) { #-- xCAT supports interpolation of '{xcatmaster}' + $imgsrv = '{xcatmaster}'; + } + $sitetab->delEntries( {'key' => 'testkey'} ); #-- clean up + unless ($imgsrv) { $callback->(