From e0fec1a85daaae93fd31fc504c62ee0fbde8c07b Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Thu, 25 Jun 2020 15:46:34 -0400 Subject: [PATCH] imgimport/imgexport better messages and option handling --- .../references/man1/imgexport.1.rst | 10 ++++++-- .../references/man1/imgimport.1.rst | 8 ++++++- xCAT-client/pods/man1/imgexport.1.pod | 8 +++++-- xCAT-client/pods/man1/imgimport.1.pod | 6 ++++- xCAT-server/lib/xcat/plugins/imgport.pm | 24 +++++++++++-------- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/imgexport.1.rst b/docs/source/guides/admin-guides/references/man1/imgexport.1.rst index 3626725f1..3481b300d 100644 --- a/docs/source/guides/admin-guides/references/man1/imgexport.1.rst +++ b/docs/source/guides/admin-guides/references/man1/imgexport.1.rst @@ -21,7 +21,7 @@ SYNOPSIS \ **imgexport [-h| -**\ **-help]**\ -\ **imgexport**\ \ *image_name*\ [\ *destination*\ ] [[\ **-e | -**\ **-extra**\ \ *file:dir*\ ] ... ] [\ **-p | -**\ **-postscripts**\ \ *node_name*\ ] [\ **-v | -**\ **-verbose**\ ] +\ **imgexport**\ \ *image_name*\ [\ *destination*\ ] [\ **-e | -**\ **-extra**\ \ *file:dir*\ ] ... ] [\ **-p | -**\ **-postscripts**\ \ *node_name*\ ] [\ **-R | -**\ **-remotehost**\ \ *user@host*\ ] [\ **-v | -**\ **-verbose**\ ] *********** @@ -90,6 +90,12 @@ OPTIONS +\ **-R|-**\ **-remotehost**\ \ *user@host*\ + + Export the image to remote host. Passwordless ssh must be setup to the remote host. + + + \ **-v|-**\ **-verbose**\ Verbose output. @@ -132,7 +138,7 @@ EXAMPLES imgexport foo -foo.tgz will be built in the current working directory. Make sure that you have enough space in the directory that you are in to run imgexport if you have a big image to tar up. +foo.tgz will be built in the current working directory. Make sure that you have enough space in the directory that you are in to run imgexport, if you have a big image to tar up. 2. To include extra files with your image: diff --git a/docs/source/guides/admin-guides/references/man1/imgimport.1.rst b/docs/source/guides/admin-guides/references/man1/imgimport.1.rst index e813f3377..84decf7fa 100644 --- a/docs/source/guides/admin-guides/references/man1/imgimport.1.rst +++ b/docs/source/guides/admin-guides/references/man1/imgimport.1.rst @@ -21,7 +21,7 @@ SYNOPSIS \ **imgimport [-h|-**\ **-help]**\ -\ **imgimport**\ \ *bundle_file_name*\ [\ **-p | -**\ **-postscripts**\ \ *nodelist*\ ] [\ **-f | -**\ **-profile**\ \ *new_profile*\ ] [\ **-v | -**\ **-verbose**\ ] +\ **imgimport**\ \ *bundle_file_name*\ [\ **-p | -**\ **-postscripts**\ \ *nodelist*\ ] [\ **-f | -**\ **-profile**\ \ *new_profile*\ ] [\ **-R | -**\ **-remotehost**\ \ *user@host*\ ] [\ **-v | -**\ **-verbose**\ ] *********** @@ -109,6 +109,12 @@ OPTIONS +\ **-R|-**\ **-remotehost**\ \ *user@host*\ + + Import the image from remote host. Passwordless ssh must be setup to the remote host. + + + \ **-v|-**\ **-verbose**\ Verbose output. diff --git a/xCAT-client/pods/man1/imgexport.1.pod b/xCAT-client/pods/man1/imgexport.1.pod index 46c165a1a..affd64d1e 100644 --- a/xCAT-client/pods/man1/imgexport.1.pod +++ b/xCAT-client/pods/man1/imgexport.1.pod @@ -6,7 +6,7 @@ B - Exports an xCAT image. B -B I [I] [[B<-e>|B<--extra> I] ... ] [B<-p>|B<--postscripts> I] [B<-v>|B<--verbose>] +B I [I] [B<-e>|B<--extra> I] ... ] [B<-p>|B<--postscripts> I] [B<-R>|B<--remotehost> I] [B<-v>|B<--verbose>] =head1 DESCRIPTION @@ -65,6 +65,10 @@ Display usage message. Get the names of the postscripts and postbootscripts for the given node and pack them into the image. +=item B<-R|--remotehost> I + +Export the image to remote host. Passwordless ssh must be setup to the remote host. + =item B<-v|--verbose> Verbose output. @@ -92,7 +96,7 @@ The output bundle file name. imgexport foo -foo.tgz will be built in the current working directory. Make sure that you have enough space in the directory that you are in to run imgexport if you have a big image to tar up. +foo.tgz will be built in the current working directory. Make sure that you have enough space in the directory that you are in to run imgexport, if you have a big image to tar up. 2. To include extra files with your image: diff --git a/xCAT-client/pods/man1/imgimport.1.pod b/xCAT-client/pods/man1/imgimport.1.pod index 1c1891485..e49df3ec8 100644 --- a/xCAT-client/pods/man1/imgimport.1.pod +++ b/xCAT-client/pods/man1/imgimport.1.pod @@ -6,7 +6,7 @@ B - Imports an xCAT image or configuration file into the xCAT tables B -B I [B<-p>|B<--postscripts> I] [B<-f>|B<--profile> I] [B<-v>|B<--verbose>] +B I [B<-p>|B<--postscripts> I] [B<-f>|B<--profile> I] [B<-R>|B<--remotehost> I] [B<-v>|B<--verbose>] =head1 DESCRIPTION @@ -82,6 +82,10 @@ Display usage message. Import the postscripts. The postscripts contained in the image will be set in the postscripts table for I. +=item B<-R|--remotehost> I + +Import the image from remote host. Passwordless ssh must be setup to the remote host. + =item B<-v|--verbose> Verbose output. diff --git a/xCAT-server/lib/xcat/plugins/imgport.pm b/xCAT-server/lib/xcat/plugins/imgport.pm index 8a8a9057e..ee1749fba 100644 --- a/xCAT-server/lib/xcat/plugins/imgport.pm +++ b/xCAT-server/lib/xcat/plugins/imgport.pm @@ -123,7 +123,7 @@ sub ximport { 'R|remotehost=s' => \$remoteHost, 'p|postscripts=s' => \$nodes, 'f|profile=s' => \$new_profile, - 'n|nozip' => \$nozip + 'n|nozip' => \$nozip ); if ($help) { @@ -131,8 +131,14 @@ sub ximport { return; } - # first extract the bundle - extract_bundle($request, $callback, $nodes, $new_profile, $remoteHost, $nozip ); + if ($#ARGV == -1) { + # if no arguments left after processing the options, then bundle name is missing + $xusage->(1); + } else { + # first extract the bundle + my $bundle = shift @ARGV; + extract_bundle($request, $callback, $bundle, $nodes, $new_profile, $remoteHost, $nozip ); + } } @@ -1067,10 +1073,10 @@ sub make_bundle { if (defined $remoteHost) { my $remoteFile = $remoteHost . ':' . $remoteDest; - $callback->({ data => ["Moving the image bundle to the remote system location $remoteDest"] }); + $callback->({ data => ["Moving the image bundle to the remote system location $remoteFile"] }); $rc = system("/usr/bin/scp -B $dest $remoteFile"); if ($rc) { - $callback->({ error => ["Unable to copy the image bundle $bundleName to the remote host"], errorcode => [1] }); + $callback->({ error => ["Unable to copy the image bundle $bundleName to the remote host (Maybe passwordless ssh was not setup?)"], errorcode => [1] }); } } } @@ -1114,20 +1120,18 @@ sub extract_bundle { #print Dumper($request); my $callback = shift; + my $bundle = shift; my $nodes = shift; my $new_profile = shift; my $remoteHost = shift; my $nozip = shift; - @ARGV = @{ $request->{arg} }; my $xml; my $data; my $datas; my $error = 0; my $bundleCopy; - my $bundle = shift @ARGV; - # Determine the current working directory. my $dir = $request->{cwd}; #getcwd; $dir = $dir->[0]; @@ -1152,10 +1156,10 @@ sub extract_bundle { my $remoteFile = "$remoteHost:$bundle"; $bundleCopy = `/bin/mktemp $workDir/imgimport.$$.XXXXXX`; chomp($bundleCopy); - $callback->({ data => ["Obtaining the image bundle from the remote system"] }); + $callback->({ data => ["Obtaining the image bundle from the remote system $remoteFile"] }); my $rc = system("/usr/bin/scp -v -B $remoteFile $bundleCopy"); if ($rc != 0) { - $callback->({ error => ["Unable to copy the image bundle $bundle from the remote host"], errorcode => [1] }); + $callback->({ error => ["Unable to copy the image bundle $bundle from the remote host (Maybe passwordless ssh was not setup?)"], errorcode => [1] }); $rc = system("rm -rf $bundleCopy"); if ($rc) { $callback->({ error => ["Failed to remove the local copy of the remote image bundle $bundleCopy"], errorcode => [1] });