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
This commit is contained in:
sikorsky 2008-09-10 21:19:02 +00:00
parent 580ba6bea2
commit 14600652bf
3 changed files with 58 additions and 0 deletions

View File

@ -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};
}
}

View File

@ -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->(

View File

@ -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->(