From 6126529d5a7db1cc40124a501f143c01267679d8 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Fri, 2 Apr 2010 09:19:02 +0000 Subject: [PATCH] Added hierarchy support for statelite; It works for both redhat and sles. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5652 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/anaconda.pm | 89 +++++++++++++++++++++++ xCAT-server/lib/xcat/plugins/sles.pm | 90 ++++++++++++++++++++++++ 2 files changed, 179 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 74b2a82ad..a7aa1fd58 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -19,6 +19,9 @@ Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; + +use Socket; + #use strict; my @cpiopid; @@ -463,6 +466,19 @@ sub mknetboot } $kcmdline .= "XCAT=$xcatmaster:$xcatdport "; + # BEGIN service node + my $res = xCAT::Utils->runcmd("hostname", 0); + my $sip = inet_ntoa(inet_aton($res)); # this is the IP of service node + if(($xcatmaster eq $sip) or ($xcatmaster eq $res)) { + # if the NFS directory in litetree is on the service node, + # and it is not exported, then it will be mounted automatically + setupNFSTree($node, $sip, $callback); + # then, export the statemnt directory if it is on the service node + if($stateHash->{$node}->[0]->{statemnt}) { + setupStatemnt($sip, $stateHash->{$node}->[0]->{statemnt}, $callback); + } + } + # END service node } else { @@ -1208,5 +1224,78 @@ sub subVars() return $fdir; } +sub setupNFSTree { + my $node = shift; + my $sip = shift; + my $callback = shift; + + my $cmd = "litetree $node"; + my @uris = xCAT::Utils->runcmd($cmd, 0); + + foreach my $uri (@uris) { + # parse the result + # the result looks like "nodename: nfsserver:directory"; + $uri =~ m/\Q$node\E:\s+(.+):(.+)$/; + my $nfsserver = $1; + my $nfsdirectory = $2; + + if($nfsserver eq $sip) { # on the service node + if (-d $nfsdirectory) { + # nothing to do + } else { + if (-e $nfsdirectory) { + unlink $nfsdirectory; + } + mkpath $nfsdirectory; + } + + + $cmd = "showmount -e $nfsserver"; + my @entries = xCAT::Utils->runcmd($cmd, 0); + shift @entries; + if(grep /\Q$nfsdirectory\E/, @entries) { + $callback->({data=>["$nfsdirectory has been exported already!"]}); + } else { + $cmd = "/usr/sbin/exportfs :$nfsdirectory"; + xCAT::Utils->runcmd($cmd, 0); + # exportfs can export this directory immediately + $callback->({data=>["now $nfsdirectory is exported!"]}); + } + } + } +} + +sub setupStatemnt { + my $sip = shift; + my $statemnt = shift; + my $callback = shift; + + $statemnt =~ m/^(.+):(.+)$/; + my $nfsserver = $1; + my $nfsdirectory = $2; + + if($sip eq inet_ntoa(inet_aton($nfsserver))) { + if (-d $nfsdirectory) { + # nothing to do + } else { + if (-e $nfsdirectory) { + unlink $nfsdirectory; + } + mkpath $nfsdirectory; + } + + my $cmd = "showmount -e $nfsserver"; + my @entries = xCAT::Utils->runcmd($cmd, 0); + shift @entries; + if(grep /\Q$nfsdirectory\E/, @entries) { + $callback->({data=>["$nfsdirectory has been exported already!"]}); + } else { + $cmd = "/usr/sbin/exportfs :$nfsdirectory -o rw,no_root_squash,sync,no_subtree_check"; + xCAT::Utils->runcmd($cmd, 0); + $callback->({data=>["now $nfsdirectory is exported!"]}); + } + } +} + 1; diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 218f84d76..bd5d1c5b3 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -18,6 +18,9 @@ Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; + +use Socket; + #use strict; my @cpiopid; @@ -331,6 +334,20 @@ sub mknetboot $kcmdline .= "XCAT=$xcatmaster:$xcatdport "; + + #BEGIN service node + my $res = xCAT::Utils->runcmd("hostname", 0); + my $sip = inet_ntoa(inet_aton($res)); # this is the IP of service node + if(($xcatmaster eq $sip) or ($xcatmaster eq $res)) { + # if the NFS directory in litetree is on the service node, + # and it is not exported, then it will be mounted automatically + setupNFSTree($node, $sip, $callback); + # then, export the statemnt directory if it is on the service node + if($stateHash->{$node}->[0]->{statemnt}) { + setupStatemnt($sip, $stateHash->{$node}->[0]->{statemnt}, $callback); + } + } + #END sevice node } else { @@ -1130,5 +1147,78 @@ sub subVars() return $fdir; } +sub setupNFSTree { + my $node = shift; + my $sip = shift; + my $callback = shift; + + my $cmd = "litetree $node"; + my @uris = xCAT::Utils->runcmd($cmd, 0); + + foreach my $uri (@uris) { + # parse the result + # the result looks like "nodename: nfsserver:directory"; + $uri =~ m/\Q$node\E:\s+(.+):(.+)$/; + my $nfsserver = $1; + my $nfsdirectory = $2; + + if($nfsserver eq $sip) { # on the service node + + if (-d $nfsdirectory) { + #nothing to do + } else { + if (-e $nfsdirectory) { + unlink $nfsdirectory; + } + mkpath $nfsdirectory; + } + + $cmd = "showmount -e $nfsserver"; + my @entries = xCAT::Utils->runcmd($cmd, 0); + shift @entries; + if(grep /\Q$nfsdirectory\E/, @entries) { + $callback->({data=>["$nfsdirectory has been exported already!"]}); + # nothing to do + }else { + $cmd = "/usr/sbin/exportfs :$nfsdirectory"; + xCAT::Utils->runcmd($cmd, 0); + # exportfs can export this directory immediately + $callback->({data=>["now $nfsdirectory is exported!"]}); + } + } + } +} + +sub setupStatemnt { + my $sip = shift; + my $statemnt = shift; + my $callback = shift; + + $statemnt =~ m/^(.+):(.+)$/; + my $nfsserver = $1; + my $nfsdirectory = $2; + if($sip eq inet_ntoa(inet_aton($nfsserver))) { + if (-d $nfsdirectory) { + # nothing to do + } else { + if (-e $nfsdirectory) { + unlink $nfsdirectory; + } + mkpath $nfsdirectory; + } + + my $cmd = "showmount -e $nfsserver"; + my @entries = xCAT::Utils->runcmd($cmd, 0); + shift @entries; + if(grep /\Q$nfsdirectory\E/, @entries) { + $callback->({data=>["$nfsdirectory has been exported already!"]}); + } else { + $cmd = "/usr/sbin/exportfs :$nfsdirectory -o rw,no_root_squash,sync,no_subtree_check"; + xCAT::Utils->runcmd($cmd, 0); + $callback->({data=>["now $nfsdirectory is exported!"]}); + } + } + +} 1;