defect 3605. 1, change ENABLESSHBETWEENNODES= in the template, and add new subroutine TableUtil::enableSSH() 2, change NODESETSTATE= in the mypostscript.tmpl, and invoke the xCAT::SvrUtils->getNodesetStates

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@16739 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jjhua 2013-06-25 09:05:00 +00:00
parent 3dc34ed30d
commit 9e4450bab0
3 changed files with 209 additions and 17 deletions

View File

@ -1498,19 +1498,10 @@ sub enablessh
my ($class, $node) = @_;
my $enablessh=1;
if( %::GLOBAL_SN_HASH ) {
if ($::GLOBAL_SN_HASH{$node} == 1) {
if( xCAT::Utils->isSN($node) ) {
$enablessh=1; # service nodes always enabled
}
} else {
if (xCAT::Utils->isSN($node))
{
$enablessh=1; # service nodes always enabled
}
else
{
# if not a service node we need to check, before enabling
my $values;
my @vals = xCAT::TableUtils->get_site_attribute("sshbetweennodes");
@ -1554,12 +1545,93 @@ sub enablessh
$enablessh=1;
}
}
}
return $enablessh;
}
#-------------------------------------------------------------------------------
=head3 enableSSH
Description:
The function is same as enablessh() above. Before using this function,
the $sn_hash for noderange, and $groups_hash for site.sshbetweennodes should be
got. This is performance improvement.
Arguments:
$node -- node name
$sn_hash -- if the node is one sn, key is the node name, and value is 1.
if the node is not a sn, the key isn't in this hash
$groups_hash -- there are two keys:
1. Each group in the value of site.sshbetweennodes could be the key
2. Each node in the groups from the value of site.sshbetweennodes , if the
value isn't ALLGROUPS or NOGROUPS.
Returns:
1 = enable ssh
0 = do not enable ssh
Globals:
none
Error:
none
Example:
my $enable = xCAT::TableUtils->enableSSH($node);
Comments:
=cut
#-----------------------------------------------------------------------------
sub enableSSH
{
my ($class, $node, $sn_hash, $groups_hash) = @_;
my $enablessh=1;
if( defined($sn_hash) && defined($sn_hash->{node}) && $sn_hash->{$node} == 1 ) {
$enablessh=1; # service nodes always enabled
} else {
# if not a service node we need to check, before enabling
if (defined($groups_hash)) {
if ($groups_hash->{ALLGROUPS} == 1)
{
$enablessh=1;
}
else
{
if ($groups_hash->{NOGROUPS} == 1)
{
$enablessh=0;
}
else
{ # check to see if the node is a member of a group
my $ismember = 0;
$ismember = $groups_hash->{$node};
if ($ismember == 1)
{
$enablessh=1;
}
else
{
$enablessh=0;
}
}
}
}
else
{ # does not exist, set default
$enablessh=1;
}
}
return $enablessh;
}
#-----------------------------------------------------------------------------

View File

@ -329,6 +329,12 @@ sub makescript {
my $monhash=getMonItems($nodes);
#print "getMonItems get called " . Dumper($monhash) . "\n";
# it will get the site.sshbetweennodes, and then parse the noderange if needed.
my $groups_hash = getsshbetweennodes();
# get all the nodes' setstate
my $nodes_setstate_hash = getNodesSetState($nodes);
foreach my $n (@$nodes ) {
$node = $n;
$inc = $t_inc;
@ -401,7 +407,7 @@ sub makescript {
#print "nodesetstate:$nodesetstate\n";
## OSPKGDIR export
# for #OSIMAGE_VARS_EXPORT#
if (!$nodesetstate) { $nodesetstate = getnodesetstate($node); }
if (!$nodesetstate) { $nodesetstate = $nodes_setstate_hash->{$node}; }
#print "nodesetstate:$nodesetstate\n";
#my $et = $typehash->{$node};
@ -439,7 +445,7 @@ sub makescript {
my $postbootscripts;
$postbootscripts = getPostbootScripts($node, $osimgname, $script_hash);
my $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash);
#ok, now do everything else..
@ -457,8 +463,13 @@ sub makescript {
$inc =~ s/#INCLUDE_POSTSCRIPTS_LIST#/$postscripts/eg;
$inc =~ s/#INCLUDE_POSTBOOTSCRIPTS_LIST#/$postbootscripts/eg;
$inc =~ s/\$ENABLESSHBETWEENNODES/$enablesshbetweennodes/eg;
$inc =~ s/\$NSETSTATE/$nodesetstate/eg;
#$inc =~ s/#COMMAND:([^#]+)#/command($1)/eg;
$inc =~ s/\$NTYPE/$nodetype/eg;
# This line only is used to compatible with the old code
$inc =~ s/#Subroutine:([^:]+)::([^:]+)::([^:]+):([^#]+)#/runsubroutine($1,$2,$3,$4)/eg;
# we will create a file in /tftboot/mypostscript/mypostscript_<nodename>
@ -615,6 +626,90 @@ sub getNodeType
return $result;
}
#
# It will get the value of site.sshbetweennodes, and then put the groups and groups' nodes in one hash
#
sub getsshbetweennodes
{
my %groups;
my $values;
my @vals = xCAT::TableUtils->get_site_attribute("sshbetweennodes");
$values = $vals[0];
if ($values) {
my @gs = split(/,/, $values);
%groups = map { $_ => 1 } @gs;
if( $groups{ALLGROUPS} !=1 || $groups{NOGROUPS} !=1 ) {
my @m;
foreach my $group (@gs) {
my @ns=xCAT::Utils->list_nodes_in_nodegroups($group);
my %nodes = map { $_ => 1 } @ns;
%groups = (%groups, %nodes);
}
}
}
return \%groups;
}
#-------------------------------------------------------------------------------
=head3 enableSSHbetweennodes
Description:
The function is same as Template::enablesshbetweennodes() above.
The performance of template::enablesshbetweennodes() is bad is scaling environment.
We plan to use ""ENABLESSHBETWEENNODES=$""ENABLESSHBETWEENNODES" instead of the
syntax "ENABLESSHBETWEENNODES=#Subroutine:xCAT::Template::enablesshbetweennodes:$NODE# " in mypostscript.tmpl.
To compatible to the old mypostscript.tmpl, so the Template::enablesshbetweennodes() is left there.
Arguments:
$node -- node name
$sn_hash -- if the node is one sn, key is the node name, and value is 1.
if the node is not a sn, the key isn't in this hash
$groups_hash -- there are two keys:
1. Each group in the value of site.sshbetweennodes could be the key
2. Each node in the groups from the value of site.sshbetweennodes , if the
value isn't ALLGROUPS or NOGROUPS.
Returns:
1 = enable ssh
0 = do not enable ssh
Globals:
none
Error:
none
Example:
my $enable = xCAT::TableUtils->enableSSH($node);
Comments:
=cut
#-----------------------------------------------------------------------------
sub enableSSHbetweennodes
{
my $node = shift;
my $sn_hash = shift;
my $groups_hash = shift;
my $result;
my $enablessh=xCAT::TableUtils->enableSSH($node, $sn_hash, $groups_hash);
if ($enablessh == 1) {
$result = "'YES'";
} else {
$result = "'NO'";
}
return $result;
}
sub getAIXPasswdVars
{
my $result;
@ -1309,7 +1404,7 @@ sub includefile
=head3 getnodesetstate
Determine the nodeset stat.
Determine the nodeset stat. This is used to be compatible to the old mypostscript.tmpl
=cut
#-----------------------------------------------------------------------------
@ -1319,6 +1414,31 @@ sub getnodesetstate
return xCAT::SvrUtils->get_nodeset_state($node,prefetchcache=>1, "global_tab_hash"=>\%::GLOBAL_TAB_HASH);
}
#----------------------------------------------------------------------------
=head3 getNodesSetState
Determine the nodeset stat for noderange.
=cut
#-----------------------------------------------------------------------------
sub getNodesSetState
{
my $nodes = shift;
my $nsh={};
my %res;
my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates($nodes, $nsh);
foreach my $state (keys %$nsh) {
my $ns = $nsh->{$state};
%res = map {$_ => $state} @$ns;
}
return \%res;
}
sub net_parms
{
my $ip = shift;

View File

@ -6,7 +6,7 @@
## end of all attributes from the site table
ENABLESSHBETWEENNODES=#Subroutine:xCAT::Template::enablesshbetweennodes:$NODE#
ENABLESSHBETWEENNODES=$ENABLESSHBETWEENNODES
export ENABLESSHBETWEENNODES
## tabdump(<TABLENAME>) is used to get all the information
@ -65,7 +65,7 @@ export PATH
## There may be no information.
#AIX_ROOT_PW_VARS_EXPORT#
NODESETSTATE=#Subroutine:xCAT::Postage::getnodesetstate:$NODE#
NODESETSTATE=$NSETSTATE
export NODESETSTATE
UPDATENODE=0