From 96a259ca81acc1a7678938207a4baccc26193be5 Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 16 Oct 2012 15:01:04 +0000 Subject: [PATCH] break out file sync into its own routine git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14031 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/updatenode.pm | 210 ++++++++++++--------- 1 file changed, 118 insertions(+), 92 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/updatenode.pm b/xCAT-server/lib/xcat/plugins/updatenode.pm index 22c34161b..9f8c746bd 100644 --- a/xCAT-server/lib/xcat/plugins/updatenode.pm +++ b/xCAT-server/lib/xcat/plugins/updatenode.pm @@ -1015,98 +1015,8 @@ sub updatenode # # handle file synchronization # - - if (($request->{FileSyncing} && $request->{FileSyncing}->[0] eq "yes") - || ( - ( $request->{SNFileSyncing} - && $request->{SNFileSyncing}->[0] eq "yes"))) - { - my %syncfile_node = (); - my %syncfile_rootimage = (); - my $node_syncfile = xCAT::SvrUtils->getsynclistfile($nodes); - foreach my $node (@$nodes) - { - my $synclist = $$node_syncfile{$node}; - - if ($synclist) - { - # this can be a comma separated list of multiple - # syncfiles - my @sl = split(',',$synclist); - foreach my $s (@sl){ - push @{$syncfile_node{$s}}, $node; - } - } - } - - # Check the existence of the synclist file - if (%syncfile_node) - { # there are files to sync defined - foreach my $synclist (keys %syncfile_node) - { - if (!(-r $synclist)) - { - my $rsp = {}; - $rsp->{data}->[0] = - "The Synclist file $synclist which specified for certain node does NOT existed."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - } - } - - # Sync files to the target nodes - foreach my $synclist (keys %syncfile_node) - { - if ($::VERBOSE) - { - my $rsp = {}; - if ($request->{FileSyncing}->[0] eq "yes") - { # sync nodes - $rsp->{data}->[0] = - " $localhostname: Internal call command: xdcp -F $synclist"; - } - else - { # sync SN - $rsp->{data}->[0] = - " $localhostname: Internal call command: xdcp -s -F $synclist"; - } - $callback->($rsp); - } - my $args; - my $env; - if ($request->{FileSyncing}->[0] eq "yes") - { # sync nodes - $args = ["-F", "$synclist"]; - $env = ["DSH_RSYNC_FILE=$synclist"]; - } - else - { # sync SN only - $args = ["-s", "-F", "$synclist"]; - $env = ["DSH_RSYNC_FILE=$synclist", "RSYNCSNONLY=1"]; - } - $subreq->( - { - command => ['xdcp'], - node => $syncfile_node{$synclist}, - arg => $args, - env => $env - }, - $callback - ); - } - my $rsp = {}; - $rsp->{data}->[0] = "File synchronization has completed."; - $callback->($rsp); - } - else - { # no syncfiles defined - my $rsp = {}; - $rsp->{data}->[0] = - "There were no syncfiles defined to process. File synchronization has completed."; - $callback->($rsp); - - } - } + &updatenodesyncfiles($request,$subreq,$callback); + if (scalar(@$AIXnodes)) { @@ -1535,6 +1445,122 @@ sub updatenode #} return 0; } + + +#------------------------------------------------------------------------------- + +=head3 updatenodesyncfiles + + Arguments: request + Returns: + 0 - for success. + 1 - for error. + +=cut + +#----------------------------------------------------------------------------- +sub updatenodesyncfiles +{ + my $request = shift; + my $subreq = shift; + my $callback = shift; + my $nodes = $request->{node}; + my $localhostname = hostname(); + if (($request->{FileSyncing} && $request->{FileSyncing}->[0] eq "yes") + || ( + ( $request->{SNFileSyncing} + && $request->{SNFileSyncing}->[0] eq "yes"))) + { + my %syncfile_node = (); + my %syncfile_rootimage = (); + my $node_syncfile = xCAT::SvrUtils->getsynclistfile($nodes); + foreach my $node (@$nodes) + { + my $synclist = $$node_syncfile{$node}; + + if ($synclist) + { + # this can be a comma separated list of multiple + # syncfiles + my @sl = split(',',$synclist); + foreach my $s (@sl){ + push @{$syncfile_node{$s}}, $node; + } + } + } + + # Check the existence of the synclist file + if (%syncfile_node) + { # there are files to sync defined + foreach my $synclist (keys %syncfile_node) + { + if (!(-r $synclist)) + { + my $rsp = {}; + $rsp->{data}->[0] = + "The Synclist file $synclist which specified for certain node does NOT existed."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return 1; + } + } + + # Sync files to the target nodes + foreach my $synclist (keys %syncfile_node) + { + if ($::VERBOSE) + { + my $rsp = {}; + if ($request->{FileSyncing}->[0] eq "yes") + { # sync nodes + $rsp->{data}->[0] = + " $localhostname: Internal call command: xdcp -F $synclist"; + } + else + { # sync SN + $rsp->{data}->[0] = + " $localhostname: Internal call command: xdcp -s -F $synclist"; + } + $callback->($rsp); + } + my $args; + my $env; + if ($request->{FileSyncing}->[0] eq "yes") + { # sync nodes + $args = ["-F", "$synclist"]; + $env = ["DSH_RSYNC_FILE=$synclist"]; + } + else + { # sync SN only + $args = ["-s", "-F", "$synclist"]; + $env = ["DSH_RSYNC_FILE=$synclist", "RSYNCSNONLY=1"]; + } + $subreq->( + { + command => ['xdcp'], + node => $syncfile_node{$synclist}, + arg => $args, + env => $env + }, + $callback + ); + } + my $rsp = {}; + $rsp->{data}->[0] = "File synchronization has completed."; + $callback->($rsp); + } + else + { # no syncfiles defined + my $rsp = {}; + $rsp->{data}->[0] = + "There were no syncfiles defined to process. File synchronization has completed."; + $callback->($rsp); + + } + } + + return; +} + # # Handles the return from running xcatdsklspost #