From 14600652bf5de9c41539bb0251a9a2d19555e668 Mon Sep 17 00:00:00 2001 From: sikorsky Date: Wed, 10 Sep 2008 21:19:02 +0000 Subject: [PATCH] Added special expressions for database table columns. Currently supported are "{hostname}", "{xcatmaster}". Any expression in braces is evaluated and replaced with some interpolated value. If expression is not defined, it's replaces by itself (ie. braces are deleted). This feature helps keep database very clean and allows easier move of xCAT master from one host to another (define xcatmaster hostname on as few places as possible). Also will help HA setup. Backwards compatible if not used. Has to be tested if used with service nodes. In our environment we wanted to make xCAT highly available. Instead of some cluster solution we decided to install two independent xCAT masters. Using this feature we can have exactly the same xCAT database on two dirrefent nodes, so it's possible do backup on on node and restore on other node. Usage example is in HA cookbook (TBD). git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2135 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Table.pm | 23 +++++++++++++++++++++++ xCAT-server/lib/xcat/plugins/anaconda.pm | 17 +++++++++++++++++ xCAT-server/lib/xcat/plugins/sles.pm | 18 ++++++++++++++++++ 3 files changed, 58 insertions(+) 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->(