From 55a90fc1b9fd934833cbaf531d77a307c91c096e Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 26 Feb 2014 08:12:11 -0500 Subject: [PATCH] fix ENABLESSHBETWEENNODES setting in mypostscript file when zones --- perl-xCAT/xCAT/Zone.pm | 82 +++++++++++++++++++++++++++- xCAT-server/lib/perl/xCAT/Postage.pm | 67 +++++++++++++++++++++-- 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/Zone.pm b/perl-xCAT/xCAT/Zone.pm index 64fa1d5c3..f666f5979 100644 --- a/perl-xCAT/xCAT/Zone.pm +++ b/perl-xCAT/xCAT/Zone.pm @@ -192,9 +192,85 @@ sub iszonedefined my ($class,$zonename) = @_; # checks the zone table to see if input zonename already in the table my $tab = xCAT::Table->new("zone"); - my $zone = $tab->getAttribs({zonename => $zonename},'sshkeydir'); $tab->close(); - if (defined($zone)) { + my $zonehash = $tab->getAttribs({zonename => $zonename},'sshkeydir'); + if ( keys %$zonehash) { + return 1; + }else{ + return 0; + } +} +#-------------------------------------------------------------------------------- + +=head3 enableSSHbetweennodes + Arguments: + zonename + Returns: + 1 if the sshbetweennodes attribute is yes/1 or undefined + 0 if the sshbetweennodes attribute is no/0 + Example: + xCAT::Zone->enableSSHbetweennodes($zonename); +=cut + +#-------------------------------------------------------------------------------- +sub enableSSHbetweennodes +{ + my ($class,$node,$callback) = @_; + # finds the zone of the node + my $enablessh = 1; # default + my @node; + push @node,$node; + my $nodelisttab = xCAT::Table->new("nodelist"); + my $nodehash = $nodelisttab->getNodesAttribs(\@node, ['zonename']); + $nodelisttab->close(); + my $zonename; + $zonename=$nodehash->{$node}->[0]->{zonename}; + # reads the zone table + my $tab = xCAT::Table->new("zone"); + $tab->close(); + # read both keys, want to know zone is in the zone table. If sshkeydir is not there + # it is either missing or invalid anyway + my $zonehash = $tab->getAttribs({zonename => $zonename},'sshbetweennodes','sshkeydir'); + if (! ( keys %$zonehash)) { + my $rsp = {}; + $rsp->{error}->[0] = + "$node has a zonename: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone. The generated mypostscript may not reflect the correct setting for ENABLESSHBETWEENNODES"; + xCAT::MsgUtils->message("E", $rsp, $callback); + return $enablessh; + } + my $sshbetweennodes=$zonehash->{sshbetweennodes}; + if (defined ($sshbetweennodes)) { + if (($sshbetweennodes =~ /^no$/i) || ($sshbetweennodes eq "0")) { + $enablessh = 0; + } else { + $enablessh = 1; + } + } else { # not defined default yes + $enablessh = 1 ; # default + } + return $enablessh; +} +#-------------------------------------------------------------------------------- + +=head3 usingzones + Arguments: + none + Returns: + 1 if the zone table is not empty + 0 if empty + Example: + xCAT::Zone->usingzones; +=cut + +#-------------------------------------------------------------------------------- +sub usingzones +{ + my ($class) = @_; + # reads the zonetable + my $tab = xCAT::Table->new("zone"); + my @zone = $tab->getAllAttribs('zonename'); + $tab->close(); + if (@zone) { return 1; }else{ return 0; @@ -275,7 +351,7 @@ sub getzoneinfo unless ( xCAT::Zone->iszonedefined($zonename)) { my $rsp = {}; $rsp->{error}->[0] = - "$node has a zonenane: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone."; + "$node has a zonename: $zonename that is not define in the zone table. Remove the zonename from the node, or create the zone using mkzone."; xCAT::MsgUtils->message("E", $rsp, $callback); $::GETZONEINFO_RC =1; return; diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 49f5fcd1c..6d542a1bf 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -16,6 +16,7 @@ use xCAT::Utils; use xCAT::TableUtils; use xCAT::Template; use xCAT::SvrUtils; +use xCAT::Zone; #use Data::Dumper; use File::Basename; use Socket; @@ -367,6 +368,16 @@ sub makescript { } $cloudinfo_hash = getcloudinfo($cloud_module_name, $cloud_exists); } + + # see if we are using zones. If we are then sshbetweennodes comes from the zone table not + # from the site table + my $usingzones; + if (xCAT::Zone->usingzones) { + $usingzones=1; + } else { + $usingzones=0; + } + foreach my $n (@$nodes ) { $node = $n; @@ -477,9 +488,15 @@ sub makescript { # for #INCLUDE_POSTBOOTSCRIPTS_LIST# my $postbootscripts; $postbootscripts = getPostbootScripts($node, $osimgname, $script_hash); - - my $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); - + + # if using zones then must go to the zone.sshbetweennodes + # else go to site.sshbetweennodes + my $enablesshbetweennodes; + if ($usingzones) { + $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); + } else { + $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); + } my @clients; my $cfgres; my $cloudres; @@ -792,7 +809,7 @@ sub getsshbetweennodes Error: none Example: - my $enable = xCAT::TableUtils->enableSSH($node); + my $enable = xCAT::TableUtils->enableSSHbetweennodes($node,$sn_hash, $groups_hash); Comments: =cut @@ -818,6 +835,48 @@ sub enableSSHbetweennodes } +#------------------------------------------------------------------------------- + +=head3 enableSSHbetweennodeszones + Description: return how to fill in the ENABLESSHBETWEENNODES export in the mypostscript file + based on the setting in the zone table sshbetweennodes attribute + Arguments: + $node + $callback + Returns: + 1 = enable ssh + 0 = do not enable ssh + Globals: + none + Error: + none + Example: + my $enable = xCAT::TableUtils->enableSSHbetweennodeszones($node); + Comments: + +=cut + +#----------------------------------------------------------------------------- + +sub enableSSHbetweennodeszones +{ + + my $node = shift; + my $callback = shift; + my $result; + + my $enablessh=xCAT::Zone->enableSSHbetweennodes($node,$callback); + if ($enablessh == 1) { + $result = "'YES'"; + } else { + $result = "'NO'"; + } + + return $result; +} + + +