diff --git a/perl-xCAT/xCAT/TableUtils.pm b/perl-xCAT/xCAT/TableUtils.pm index d1538b454..9f026379c 100644 --- a/perl-xCAT/xCAT/TableUtils.pm +++ b/perl-xCAT/xCAT/TableUtils.pm @@ -1824,8 +1824,8 @@ sub enableSSH } else { # if not a service node we need to check, before enabling - if (defined($groups_hash)) { - if ($groups_hash->{ALLGROUPS} == 1) + if (keys %$groups_hash) { # not empty + if ($groups_hash->{ALLGROUPS} == 1) { $enablessh=1; } diff --git a/perl-xCAT/xCAT/Zone.pm b/perl-xCAT/xCAT/Zone.pm index 64fa1d5c3..e712d2dd1 100644 --- a/perl-xCAT/xCAT/Zone.pm +++ b/perl-xCAT/xCAT/Zone.pm @@ -145,7 +145,7 @@ sub genSSHRootKeys Returns: Name of the current default zone from the zone table Example: - my $defaultzone =xCAT::Zone->getdefaultzone(); + my $defaultzone =xCAT::Zone->getdefaultzone($callback); =cut #-------------------------------------------------------------------------------- @@ -192,9 +192,107 @@ 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 getmyzonename + Arguments: + $node -one nodename + Returns: + $zonename + Example: + my $zonename=xCAT::Zone->getmyzonename($node); +=cut + +#-------------------------------------------------------------------------------- +sub getmyzonename +{ + my ($class,$node,$callback) = @_; + my @node; + push @node,$node; + my $zonename; + my $nodelisttab = xCAT::Table->new("nodelist"); + my $nodehash = $nodelisttab->getNodesAttribs(\@node, ['zonename']); + $nodelisttab->close(); + if ( defined ($nodehash->{$node}->[0]->{zonename})) { # it was defined in the nodelist table + $zonename=$nodehash->{$node}->[0]->{zonename}; + } else { # get the default zone + $zonename =xCAT::Zone->getdefaultzone($callback); + } + return $zonename; +} +#-------------------------------------------------------------------------------- + +=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 $zonename=xCAT::Zone->getmyzonename($node); + # 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 +373,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 14ff1a23c..3d17cd1f9 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; @@ -186,8 +187,8 @@ sub makescript { if($entries[0]) { $installroot = $entries[0]; } + my $tmpl="$installroot/postscripts/mypostscript.tmpl"; #the customized mypostscript template - unless ( -r $tmpl) { $tmpl="$::XCATROOT/share/xcat/mypostscript/mypostscript.tmpl"; #the default xcat mypostscript template } @@ -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,21 @@ 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; + my $zonename="\'\'"; + if ($usingzones) { + $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); + $enablesshbetweennodes = enableSSHbetweennodeszones($node,$callback); + my $tmpzonename = xCAT::Zone->getmyzonename($node,$callback); + $zonename="\'"; + $zonename .= $tmpzonename; + $zonename .="\'"; + } else { + $enablesshbetweennodes = enableSSHbetweennodes($node, \%::GLOBAL_SN_HASH, $groups_hash); + } my @clients; my $cfgres; my $cloudres; @@ -792,7 +815,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 +841,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; +} + + + diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index d86b9b1b8..2b2f930a1 100755 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -390,7 +390,8 @@ sub process_request { # - need domain for this node my $host = $nodehash{$n}{host}; $domain=$nodedomains{$host}; - unless ($domain =~ /^\./) { $domain = '.'.$domain; } + # remove the first . at domain name since it's not accepted by high dns parser + if ($domain =~ /^\./) { $domain =~ s/^\.//;; } ($canonical,$aliasstr) = split /[ \t]+/,$names,2; if ($aliasstr) { @@ -404,13 +405,13 @@ sub process_request { xCAT::SvrUtils::sendmsg(":Handling $node in /etc/hosts.", $callback); unless ($canonical =~ /$domain/) { - $canonical.=$domain; + $canonical.=".".$domain; } # for only the sake of comparison, ensure consistant dot suffix unless ($canonical =~ /\.\z/) { $canonical .= '.' } foreach my $alias (@aliases) { unless ($alias =~ /$domain/) { - $alias .= $domain; + $alias .= ".".$domain; } unless ($alias =~ /\.\z/) { $alias .= '.'; @@ -505,9 +506,11 @@ sub process_request { $ctx->{slaves}=\@slave_ips; } + $ctx->{domain} =~ s/^\.//; # remove . if it's the first char of domain name $ctx->{zonestotouch}->{$ctx->{domain}}=1; foreach (@networks) { if ($_->{domain}) { + $_->{domain} =~ s/^\.//; # remove . if it's the first char of domain name $ctx->{zonestotouch}->{$_->{domain}}=1; } } @@ -796,11 +799,11 @@ sub update_zones { xCAT::SvrUtils::sendmsg("Updating zones.", $callback); - unless ($domain =~ /^\./) { - $domain = '.'.$domain; + if ($domain =~ /^\./) { # remove . if it's the first char of domain name + $domain =~ s/^\.//; } unless ($name =~ /\./) { - $name .= $domain; + $name .= ".".$domain; } unless ($name =~ /\.\z/) { $name .= '.'; @@ -1166,9 +1169,9 @@ sub add_or_delete_records { } my $domain = $nodedomains{$node}; - unless ($domain =~ /^\./) { $domain = '.'.$domain; } + if ($domain =~ /^\./) { $domain =~ s/^\.//; } # remove . if it's the first char of domain name - unless ($name =~ /$domain/) { $name .= $domain } # $name needs to represent fqdn, but must preserve $node as a nodename for cfg lookup + unless ($name =~ /$domain/) { $name .= ".".$domain } # $name needs to represent fqdn, but must preserve $node as a nodename for cfg lookup if ($ctx->{hoststab} and $ctx->{hoststab}->{$node} and $ctx->{hoststab}->{$node}->[0]->{ip}) { @ips = ($ctx->{hoststab}->{$node}->[0]->{ip}); diff --git a/xCAT-server/share/xcat/mypostscript/mypostscript.tmpl b/xCAT-server/share/xcat/mypostscript/mypostscript.tmpl index ff7cd0aad..ca7f44a20 100755 --- a/xCAT-server/share/xcat/mypostscript/mypostscript.tmpl +++ b/xCAT-server/share/xcat/mypostscript/mypostscript.tmpl @@ -9,6 +9,9 @@ ENABLESSHBETWEENNODES=$ENABLESSHBETWEENNODES export ENABLESSHBETWEENNODES +ZONENAME=$ZONENAME +export ZONENAME + ## tabdump() is used to get all the information ## in the table ## The should only be non-"node key" table