mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-22 03:32:04 +00:00
Merge pull request #9 from chuckbrazie/ZVM_XCAT_DEV_merge_xCAT-client
merge of xCAT_Client plus add one new file missed in xCAT
This commit is contained in:
commit
651cdaaaa1
286
xCAT-client/bin/mkdummyimage
Normal file
286
xCAT-client/bin/mkdummyimage
Normal file
@ -0,0 +1,286 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
# IBM(c) 2015 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
###############################################################################
|
||||
# COMPONENT: mkdummyimage
|
||||
#
|
||||
# This script creates a dummy image.
|
||||
###############################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use File::Spec;
|
||||
use File::Temp;
|
||||
use Getopt::Long;
|
||||
use MIME::Base64;
|
||||
use Sys::Hostname;
|
||||
use Socket;
|
||||
|
||||
my $version = "1.0";
|
||||
|
||||
my $defaultName = 'dummy.img'; # Default image file name
|
||||
my $dest = ''; # Target destination (filespec)
|
||||
my $displayHelp = 0; # Display help information
|
||||
my $eckdImage = 0; # ECKD image is wanted
|
||||
my $fbaImage = 0; # FBA image is wanted
|
||||
my $remoteHost = ''; # Remote host transfer information
|
||||
my $remoteUser = ''; # Remote user transfer information
|
||||
my $verbose = 0; # Verbose flag - 0: quiet, 1: verbose
|
||||
my $versionOpt = 0; # Show version information flag
|
||||
|
||||
# set the usage message
|
||||
my $usage_string = "Usage:\n
|
||||
$0 [ --eckd | --fba ] [ -V | --verbose ]
|
||||
[ -d | --destination <dest> ] [-R | --remotehost <host> ]\n
|
||||
or\n
|
||||
$0 -v | --version\n
|
||||
or\n
|
||||
$0 -h | --help\n
|
||||
The following options are supported:\n
|
||||
-d | --destination <dest>
|
||||
File specification of the image file to be created.
|
||||
Either the filename only or a fully qualified name.
|
||||
If the destination is within the xCAT MN then
|
||||
it must be within the directory specified by
|
||||
the installdir property in the xCAT site table.
|
||||
The default file name is $defaultName.\n
|
||||
--eckd Create an empty ECKD disk image. This is the
|
||||
default image type if neither --eckd or --fba
|
||||
is specifed.\n
|
||||
--fba Create an empty FBA disk image\n
|
||||
-h | --help Display help information\n
|
||||
-R | --remotehost <host>
|
||||
Indicates that the destination specified on the
|
||||
command invocation is the file specification on a
|
||||
host other than the management node.
|
||||
The 'host' operand is the IP address or DNS host
|
||||
name of the target server. A user may be specified
|
||||
in a similar way as it is specified with the SCP
|
||||
command using the format 'user\@host' where 'user'
|
||||
is the name of the user on the remote system and
|
||||
'host' operand is as previously stated. The image
|
||||
is created in the directory specified by the
|
||||
tmpdir property in the site table and then moved
|
||||
to the remote host using SCP. After moving the
|
||||
image off the xCAT MN, the image is removed
|
||||
from the xCAT MN. Prior to specifying the command,
|
||||
the keystore on the remote host must be set up with
|
||||
the public key of the xCAT MN.\n
|
||||
-v | --version Display the version of this script.\n
|
||||
-V | --verbose Display verbose processing messages.\n";
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 createImage
|
||||
|
||||
Description : Create the dummy image file.
|
||||
Arguments : None
|
||||
Returns : 0 - No error
|
||||
non-zero - Error detected.
|
||||
Example : $rc = createImage();
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub createImage{
|
||||
my $rc = 0;
|
||||
my $buildDir = '';
|
||||
my $header;
|
||||
|
||||
# Create a temporary directory in which to create the image.
|
||||
my $tmpDir = `/opt/xcat/sbin/tabdump site| grep '^"tmpdir",' | sed s/'^"tmpdir","'//g| sed s/'".*'//g`;
|
||||
chomp $tmpDir;
|
||||
if ( $tmpDir eq '' ) {
|
||||
print "Error: The 'tmpdir' value is missing from the site table.\n";
|
||||
$rc = 11;
|
||||
goto FINISH_createImage;
|
||||
}
|
||||
$buildDir = mkdtemp( "$tmpDir/image.$$.XXXXXX" );
|
||||
|
||||
# Create the image
|
||||
my $imageFile = $defaultName;
|
||||
open( my $fh, '>', "$buildDir/$imageFile" ) or die "Could not open file '$buildDir/$imageFile'";
|
||||
if ( $verbose ) {
|
||||
print "Creating the image in $buildDir as $imageFile.\n";
|
||||
}
|
||||
|
||||
if ( $eckdImage ) {
|
||||
$header = "xCAT CKD Disk Image:";
|
||||
$header = "$header 0 CYL";
|
||||
}
|
||||
elsif ( $fbaImage ) {
|
||||
$header = "xCAT FBA Disk Image:";
|
||||
$header = "$header 0 BLK";
|
||||
}
|
||||
$header = "$header HLen: 0055"; # Header size increased by x from 0055
|
||||
$header = "$header GZIP: 0";
|
||||
printf $fh "%-512s", "$header";
|
||||
close( $fh );
|
||||
|
||||
# Move the image to the target location.
|
||||
if ( $remoteHost ne '' ) {
|
||||
# Do a remote transfer
|
||||
my $remoteTarget = $remoteHost . ':' . $dest;
|
||||
if ( $remoteUser ne '' ) {
|
||||
$remoteTarget = "$remoteUser\@$remoteTarget";
|
||||
}
|
||||
my $scpVerbose = '';
|
||||
if ( $verbose ) {
|
||||
print "Moving the image $imageFile to the remote system $remoteHost as $dest.\n";
|
||||
$scpVerbose = '-v'
|
||||
}
|
||||
$rc = system( "/usr/bin/scp $scpVerbose -B $buildDir/$imageFile $remoteTarget" );
|
||||
if ( $rc ) {
|
||||
$rc = $rc >> 8;
|
||||
print "Error: Unable to copy the image $buildDir/$imageFile to the remote host: $remoteHost, rc: $rc\n";
|
||||
$rc = 30;
|
||||
goto FINISH_createImage;
|
||||
}
|
||||
} else {
|
||||
# Move the file to a local directory
|
||||
$rc = system( "cp $buildDir/$imageFile $dest" );
|
||||
if ( $rc ) {
|
||||
$rc = $rc >> 8;
|
||||
print "Error: Unable to copy the image $buildDir/$imageFile to the destination: $dest, rc: $rc\n";
|
||||
$rc = 40;
|
||||
goto FINISH_createImage;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $remoteHost ne '' ) {
|
||||
print "Image created on $remoteHost: $dest\n";
|
||||
} else {
|
||||
print "Image created: $dest\n";
|
||||
}
|
||||
|
||||
FINISH_createImage:
|
||||
if ( -d $buildDir ) {
|
||||
rmtree $buildDir;
|
||||
}
|
||||
return $rc;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 showHelp
|
||||
|
||||
Description : Show the help inforamtion.
|
||||
Arguments : None.
|
||||
Returns : None.
|
||||
Example : showHelp();
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub showHelp{
|
||||
print "$0 prepares a special image file that contains no disk\ncontents.\n\n";
|
||||
print $usage_string;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#*****************************************************************************
|
||||
# Main routine
|
||||
#*****************************************************************************
|
||||
my $rc = 0;
|
||||
my $out;
|
||||
|
||||
# Parse the arguments
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
if (!GetOptions(
|
||||
'eckd' => \$eckdImage,
|
||||
'd|destination=s' => \$dest,
|
||||
'fba' => \$fbaImage,
|
||||
'h|help' => \$displayHelp,
|
||||
'R|remotehost=s' => \$remoteHost,
|
||||
'v|version' => \$versionOpt,
|
||||
'V|verbose' => \$verbose )) {
|
||||
print $usage_string;
|
||||
goto FINISH_main;
|
||||
}
|
||||
|
||||
if ( $versionOpt ) {
|
||||
print "Version: $version\n";
|
||||
}
|
||||
|
||||
if ( $displayHelp ) {
|
||||
showHelp();
|
||||
}
|
||||
|
||||
if ( $displayHelp or $versionOpt ) {
|
||||
goto FINISH_main;
|
||||
}
|
||||
|
||||
if ( !$eckdImage and !$fbaImage ) {
|
||||
$eckdImage = 1;
|
||||
}
|
||||
|
||||
if ( $remoteHost ne '' ) {
|
||||
$remoteHost =~ s/^\s+|\s+$//g; # trim blanks from both ends of the value
|
||||
my $spaceCnt = scalar( () = $remoteHost =~ /\s+/g );
|
||||
if ( $spaceCnt != 0 ) {
|
||||
print "Error: Remote host value is not a single word.\n";
|
||||
$rc = 1;
|
||||
goto FINISH_main;
|
||||
}
|
||||
if ( $remoteHost =~ /@/ ) {
|
||||
my @parts = split( /@/, $remoteHost );
|
||||
if ( substr( $remoteHost, -1) eq '@' or
|
||||
@parts > 2 or
|
||||
!defined $parts[0] or $parts[0] eq '' or
|
||||
!defined $parts[1] or $parts[1] eq '' ) {
|
||||
print "Error: Remote host value is not valid.\n" .
|
||||
" It should be in the form of 'hostname' or 'user\@hostname'.\n";
|
||||
$rc = 2;
|
||||
goto FINISH_main;
|
||||
}
|
||||
$remoteUser = $parts[0];
|
||||
$remoteHost = $parts[1];
|
||||
} else {
|
||||
$remoteUser = 'root';
|
||||
}
|
||||
}
|
||||
|
||||
# Determine the destination and make certain it is valid.
|
||||
my $installDir = `/opt/xcat/sbin/tabdump site| grep '^"installdir",' | sed s/'^"installdir","'//g| sed s/'".*'//g`;
|
||||
chomp $installDir;
|
||||
if ( $installDir eq '' ) {
|
||||
print "Error: The 'installDir' value is missing from the site table.\n";
|
||||
$rc = 10;
|
||||
goto FINISH_main;
|
||||
}
|
||||
|
||||
if ( $dest eq '' ){
|
||||
# Set default destination for either a local or remote location.
|
||||
if ( $remoteHost eq '' ) {
|
||||
$dest = "$installDir/$defaultName";
|
||||
} else {
|
||||
$dest = "$defaultName";
|
||||
}
|
||||
} else {
|
||||
# Can only verify local destination here. SCP will verify the remote destination.
|
||||
if ( $remoteHost eq '' ) {
|
||||
if ( $dest !~ /\// ) {
|
||||
$dest = "$installDir/$dest";
|
||||
} else {
|
||||
if ( $dest !~ /^$installDir/ ) {
|
||||
print "Error: The destination is not within the install directory specified in the site table.\n";
|
||||
$rc = 20;
|
||||
goto FINISH_main;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create the image file.
|
||||
createImage();
|
||||
|
||||
FINISH_main:
|
||||
exit $rc;
|
||||
|
2862
xCAT-client/bin/verifynode
Normal file
2862
xCAT-client/bin/verifynode
Normal file
File diff suppressed because it is too large
Load Diff
113
xCAT-client/bin/zvmMsg
Normal file
113
xCAT-client/bin/zvmMsg
Normal file
@ -0,0 +1,113 @@
|
||||
#!/usr/bin/perl
|
||||
# IBM(c) 2016 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head1
|
||||
|
||||
Provides more information related to an xCAT message
|
||||
for z/VM. These are messages which are similar to the
|
||||
following:
|
||||
Warning (ZXCATIVP:VN01) Network VSW3 was not found as a network.
|
||||
These message were originally added for the z/VM IVP and
|
||||
are in the form:
|
||||
<message type> (group:msgId) <msgText>
|
||||
|
||||
The information provided consists of:
|
||||
Explanation of the message,
|
||||
System Action, and
|
||||
User Action.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
package xCAT::zvmMsgs;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
|
||||
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
||||
|
||||
use Getopt::Long;
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use Text::Wrap;
|
||||
use xCAT::zvmMsgs;
|
||||
use strict;
|
||||
use warnings;
|
||||
1;
|
||||
|
||||
# set the usage message
|
||||
my $usage_string = "Usage:\n
|
||||
$0 -h
|
||||
$0 --help
|
||||
$0 --group <group id> --id <msg id>\n
|
||||
Use this script to display extra information for messages related
|
||||
to z/VM that have the format:
|
||||
<msgType> (<group>:<msgId>) <msgText>
|
||||
for example:
|
||||
Warning (ZXCATIVP:VN01) Network VSW3 was not found.\n
|
||||
The following options are supported:
|
||||
--group <group id>
|
||||
specified the identifier of the group to which the message belongs.
|
||||
The group id is the first part of the identifer, e.g.
|
||||
'Warning (ZXCATIVP:VDS01)' belongs to the 'ZXCATIVP' group.
|
||||
The group id is case sensitive. This operand should be specified
|
||||
along with the --id operand.
|
||||
-h | --help
|
||||
Displays usage information.
|
||||
--id <msg id>
|
||||
specifies the message identifier. The message id is the second part
|
||||
of the identifier, e.g. 'Warning (ZXCATIVP:VDS01)' where 'VDS01'
|
||||
is the message id. The message identifier is case sensitive. This
|
||||
operand should be specified along with the --group operand to fully
|
||||
identify the message.\n";
|
||||
|
||||
#*****************************************************************************
|
||||
# Main routine
|
||||
#*****************************************************************************
|
||||
# Parse the arguments
|
||||
my $displayHelp = 0;
|
||||
my $group = '';
|
||||
my $msgId = '';
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( 'bundling' );
|
||||
|
||||
if ( !GetOptions(
|
||||
'h|help' => \$displayHelp,
|
||||
'group=s' => \$group,
|
||||
'id=s' => \$msgId,
|
||||
)) {
|
||||
print $usage_string;
|
||||
goto FINISH;
|
||||
}
|
||||
|
||||
if ( $displayHelp ) {
|
||||
print $usage_string;
|
||||
goto FINISH;
|
||||
}
|
||||
|
||||
if ( $group eq '' ) {
|
||||
print "--group operand was not specified.\n";
|
||||
print $usage_string;
|
||||
} elsif ( $msgId eq '' ) {
|
||||
print "--id operand was not specified.\n";
|
||||
print $usage_string;
|
||||
} else {
|
||||
my $extraInfo;
|
||||
my $msg;
|
||||
my $recAction;
|
||||
my $sev;
|
||||
( $recAction, $sev, $msg, $extraInfo ) = xCAT::zvmMsgs->buildMsg( $group, $msgId );
|
||||
if ( $msg =~ ': Message was not found!' ) {
|
||||
# Oops, we could not find the message.
|
||||
print "$msg\n";
|
||||
} else {
|
||||
if ( $extraInfo ne '' ) {
|
||||
print "Additional information for message $msgId in group $group:\n";
|
||||
print "$extraInfo\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FINISH:
|
||||
exit;
|
353
xCAT-client/bin/zxcatCopyCloneList.pl
Normal file
353
xCAT-client/bin/zxcatCopyCloneList.pl
Normal file
@ -0,0 +1,353 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
# IBM (C) Copyright 2015, 2016 Eclipse Public License
|
||||
# http://www.eclipse.org/org/documents/epl-v10.html
|
||||
###############################################################################
|
||||
# COMPONENT: zxcatCopyCloneList.pl
|
||||
#
|
||||
# This is a program to copy the "DOCLONE COPY" file from the 193 disk to
|
||||
# /opt/xcat/doclone.txt
|
||||
###############################################################################
|
||||
|
||||
use strict;
|
||||
#use warnings;
|
||||
use Capture::Tiny ':all';
|
||||
use Getopt::Long;
|
||||
|
||||
my $file_location = '/var/opt/xcat/';
|
||||
my $source_file = 'DOCLONE.COPY';
|
||||
my $file_name = 'doclone.txt';
|
||||
my $tempPattern = 'doclone.XXXXXXXX';
|
||||
my $source_vdev = '193';
|
||||
my $version = "1.0";
|
||||
my $out;
|
||||
my $err;
|
||||
my $returnvalue;
|
||||
my $displayHelp = 0; # Display help information
|
||||
my $versionOpt = 0; # Show version information flag
|
||||
|
||||
my $usage_string = "This script copies the DOCLONE COPY from the MAINT 193
|
||||
to the $file_location$file_name\n\n
|
||||
Usage:\n
|
||||
$0 [ -v ]
|
||||
$0 [ -h | --help ]\n
|
||||
The following options are supported:\n
|
||||
-h | --help Display help information\n
|
||||
-v Display the version of this script.\n";
|
||||
|
||||
# Copied this routine from sspmodload.pl
|
||||
# This will get the Linux address of the vdev
|
||||
sub get_disk($)
|
||||
{
|
||||
my ($id_user) = @_;
|
||||
my $id = hex $id_user;
|
||||
my $hex_id = sprintf '%x', $id;
|
||||
my $completed = 1;
|
||||
my $dev_path = sprintf '/sys/bus/ccw/drivers/dasd-eckd/0.0.%04x', $id;
|
||||
if (!-d $dev_path) {
|
||||
$dev_path = sprintf '/sys/bus/ccw/drivers/dasd-fba/0.0.%04x', $id;
|
||||
}
|
||||
if (!-d $dev_path) {
|
||||
print "(Error) Unable to find a path to the $source_vdev in /sys/bus/ccw/drivers/\n";
|
||||
}
|
||||
-d $dev_path or return undef;
|
||||
|
||||
#offline the disk so that a new online will pick up the current file
|
||||
my @sleepTimes = ( 1, 2, 3, 5, 8, 15, 22, 34, 60);
|
||||
system("echo 0 > $dev_path/online");
|
||||
|
||||
my $dev_block = "$dev_path/block";
|
||||
|
||||
#wait if the disk directory is still there
|
||||
if (-d $dev_block) {
|
||||
$completed = 0;
|
||||
foreach (@sleepTimes) {
|
||||
system("echo 0 > $dev_path/online");
|
||||
sleep $_;
|
||||
if (!-d $dev_block) {
|
||||
$completed = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$completed) {
|
||||
print "(Error) The 193 disk failed to complete the offline!\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
system("echo 1 > $dev_path/online");
|
||||
# Bring the device online if offline
|
||||
if (!-d $dev_block) {
|
||||
$completed = 0;
|
||||
foreach (@sleepTimes) {
|
||||
system("echo 1 > $dev_path/online");
|
||||
sleep $_;
|
||||
if (-d $dev_block) {
|
||||
$completed = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (!$completed) {
|
||||
print "(Error) The 193 disk failed to come online!\n";
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
if (opendir(my $dir, $dev_block)) {
|
||||
my $dev;
|
||||
while ($dev = readdir $dir) {
|
||||
last if (!( $dev eq '.' || $dev eq '..' ) );
|
||||
}
|
||||
closedir $dir;
|
||||
if (!defined $dev) {
|
||||
print "(Error) undefined $dev\n";
|
||||
}
|
||||
defined $dev ? "/dev/$dev" : undef;
|
||||
} else {
|
||||
print "(Error) Unable to opendir $dev_block\n";
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
|
||||
# ***********************************************************
|
||||
# Mainline. Parse any arguments, usually no arguments
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
|
||||
GetOptions(
|
||||
'h|help' => \$displayHelp,
|
||||
'v' => \$versionOpt );
|
||||
|
||||
if ( $versionOpt ) {
|
||||
print "Version: $version\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ( $displayHelp ) {
|
||||
print $usage_string;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $tempFileName = '';
|
||||
my $rc = 0;
|
||||
my $oldFileExists = 0;
|
||||
my $dev = get_disk($source_vdev);
|
||||
if (defined($dev)) {
|
||||
# make sure directory exists
|
||||
if (!-d $file_location) {
|
||||
$returnvalue = mkdir "$file_location", 0755;
|
||||
if (!$returnvalue) {
|
||||
print "(Error) mkdir $file_location failed with errno:$!";
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
|
||||
}
|
||||
}
|
||||
my $oldFiletime;
|
||||
# Create a temp file name to use while validating
|
||||
$tempFileName = `/bin/mktemp -p $file_location $tempPattern`;
|
||||
chomp($tempFileName);
|
||||
# if we are overwriting an existing file, save time stamp
|
||||
if (-e "$file_location$file_name") {
|
||||
# stat will return results in $returnvalue
|
||||
( $out, $err, $returnvalue ) = eval { capture { `stat \'-c%y\' $file_location$file_name` } };
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
print "(Error) Cannot stat the $file_location$file_name\n$err\n";
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
}
|
||||
$oldFileExists = 1;
|
||||
$oldFiletime = $returnvalue;
|
||||
}
|
||||
|
||||
( $out, $err, $returnvalue ) = eval { capture { `/sbin/cmsfscp -d $dev -a $source_file $tempFileName` } };
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
# skip any blksize message for other blksize
|
||||
if ($err =~ 'does not match device blksize') {
|
||||
} else {
|
||||
print "(Error) Cannot copy $source_file\n$err\n";
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
if ($oldFileExists == 1) {
|
||||
( $out, $err, $returnvalue ) = eval { capture { `stat \'-c%y\' $tempFileName` } };
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
print "(Error) Cannot stat the $tempFileName\n$err\n";
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
}
|
||||
if ($oldFiletime eq $returnvalue) {
|
||||
print "The $source_file copied to temporary file $tempFileName is the same time stamp as original.\n";
|
||||
} else {
|
||||
print "$source_file copied to temporary file $tempFileName successfully\n";
|
||||
}
|
||||
} else {
|
||||
print "$source_file copied to temporary file $tempFileName successfully\n";
|
||||
}
|
||||
|
||||
print "Validating $tempFileName contents for proper syntax...\n";
|
||||
if (-f "$tempFileName") {
|
||||
$out = `cat $tempFileName`;
|
||||
} else {
|
||||
print "(Error) Missing temporary file: $tempFileName\n";
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
}
|
||||
my @lines = split('\n',$out);
|
||||
my %hash = ();
|
||||
my %imagenames = ();
|
||||
my $count = @lines;
|
||||
if ($count < 1) {
|
||||
print "(Error) $tempFileName does not have any data.\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { `rm $tempFileName` } };
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
print "(Error) Cannot erase temporary file $tempFileName $err\n";
|
||||
}
|
||||
$rc = 1;
|
||||
goto MAIN_EXIT;
|
||||
}
|
||||
|
||||
# loop for any lines found
|
||||
for (my $i=0; $i < $count; $i++) {
|
||||
# skip comment lines, * or /*
|
||||
if ( $lines[$i] =~ '^\s*[\*]') {
|
||||
next;
|
||||
}
|
||||
if ( $lines[$i] =~ '^\s*/[*]') {
|
||||
next;
|
||||
}
|
||||
# is this a blank line? if so skip it
|
||||
if ($lines[$i] =~/^\s*$/) {
|
||||
next;
|
||||
}
|
||||
my $semicolons = $lines[$i] =~ tr/\;//;
|
||||
if ($semicolons < 3) {
|
||||
print "(Error) Semicolons need to end each key=value on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
|
||||
%hash = ('IMAGE_NAME' => 0,'CLONE_FROM' => 0,'ECKD_POOL' => 0, 'FBA_POOL' => 0 );
|
||||
# IMAGE_NAME=imgBoth; CLONE_FROM=testFBA; ECKD_POOL=POOLECKD; FBA_POOL=POOLFBA
|
||||
my @parms = split( ';', $lines[$i]);
|
||||
my $parmcount = @parms;
|
||||
# get the key and value for this item, store in hash
|
||||
for (my $j=0; $j < $parmcount; $j++) {
|
||||
# if this token is all blanks skip it. Could be reading blanks at the end of the line
|
||||
if ($parms[$j] =~ /^\s*$/) {
|
||||
next;
|
||||
}
|
||||
my $parmlength = length($parms[$j]);
|
||||
my @keyvalue = split('=', $parms[$j]);
|
||||
my $key = $keyvalue[0];
|
||||
$key =~ s/^\s+|\s+$//g; # get rid of leading and trailing blanks
|
||||
|
||||
if ( length( $key ) == 0 ) {
|
||||
print "(Error) Missing keyword on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
next;
|
||||
}
|
||||
my $value = $keyvalue[1];
|
||||
$value =~ s/^\s+|\s+$//g;
|
||||
if ( length( $value ) == 0 ) {
|
||||
print "(Error) Missing value for key $key on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
next
|
||||
}
|
||||
#uppercase both key and value;
|
||||
my $UCkey = uc $key;
|
||||
my $UCvalue = uc $value;
|
||||
$hash{$UCkey} = $hash{$UCkey} + 1;
|
||||
if ($UCkey eq "IMAGE_NAME") {
|
||||
if (exists $imagenames{$UCvalue}) {
|
||||
print "(Error) Duplicate IMAGE_NAME found on line ".($i+1)." with value: $value\n";
|
||||
$rc = 1;
|
||||
} else {
|
||||
$imagenames{$UCvalue} = 1;
|
||||
}
|
||||
}
|
||||
if ($UCkey ne "IMAGE_NAME" && $UCkey ne "CLONE_FROM" && $UCkey ne "ECKD_POOL" && $UCkey ne "FBA_POOL") {
|
||||
print "(Error) Unknown keyword $key found on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
}
|
||||
# Check to make sure they have at least an image name, from and one pool
|
||||
if ($hash{IMAGE_NAME} == 1 && $hash{CLONE_FROM} == 1 && ($hash{ECKD_POOL} ==1 || $hash{FBA_POOL} ==1 )) {
|
||||
next;
|
||||
} else {
|
||||
if ($hash{IMAGE_NAME} == 0) {
|
||||
print "(Error) Missing IMAGE_NAME key=value on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{IMAGE_NAME} > 1) {
|
||||
print "(Error) Multiple IMAGE_NAME keys found on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{CLONE_FROM} == 0) {
|
||||
print "(Error) Missing CLONE_FROM key=value on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{CLONE_FROM} > 1) {
|
||||
print "(Error) Multiple CLONE_FROM keys found on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{ECKD_POOL} == 0 && $hash{FBA_POOL} == 0) {
|
||||
print "(Error) Missing ECKD_POOL or FBA_POOL on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{ECKD_POOL} > 1) {
|
||||
print "(Error) Multiple ECKD_POOL keys found on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
if ($hash{FBA_POOL} > 1) {
|
||||
print "(Error) Multiple FBA_POOL keys found on line ".($i+1)."\n";
|
||||
$rc = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "(Error) Unable to access the $source_vdev disk.\n";
|
||||
$rc = 1;
|
||||
}
|
||||
# Main exit for this routine. Handles any necessary clean up.
|
||||
MAIN_EXIT:
|
||||
if (length($tempFileName) > 0 ) {
|
||||
# If a good rc, Copy the temp file to the correct file
|
||||
if ($rc == 0) {
|
||||
( $out, $err, $returnvalue ) = eval { capture { `/bin/cp -f $tempFileName $file_location$file_name` } };
|
||||
print $out;
|
||||
print $err;
|
||||
print $returnvalue;
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
print "(Error) Cannot copy the temporary file $tempFileName to $file_location$file_name \n $err\n";
|
||||
$rc = 1;
|
||||
} else {
|
||||
print "Validation completed. Temporary file copied to $file_location$file_name.\nIt is ready to use\n";
|
||||
}
|
||||
}
|
||||
( $out, $err, $returnvalue ) = eval { capture { `rm $tempFileName` } };
|
||||
chomp($out);
|
||||
chomp($err);
|
||||
chomp($returnvalue);
|
||||
if (length($err) > 0) {
|
||||
print "(Error) Cannot erase temporary file $tempFileName\n$err\n";
|
||||
$rc = 1;
|
||||
}
|
||||
}
|
||||
exit $rc;
|
2607
xCAT-client/bin/zxcatIVP.pl
Normal file
2607
xCAT-client/bin/zxcatIVP.pl
Normal file
File diff suppressed because it is too large
Load Diff
333
xCAT-client/bin/zxcatexport.pl
Normal file
333
xCAT-client/bin/zxcatexport.pl
Normal file
@ -0,0 +1,333 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
# IBM (C) Copyright 2015, 2016 Eclipse Public License
|
||||
# http://www.eclipse.org/org/documents/epl-v10.html
|
||||
###############################################################################
|
||||
# COMPONENT: zxcatExport
|
||||
#
|
||||
# This is a program to save the xCAT tables to the /install/xcatmigrate directory;
|
||||
# then close and export the /install LVM
|
||||
#
|
||||
# The reverse process on the other system can be done if the LVM disks are
|
||||
# writeable and online. The zxcatmigrate script can be used for that.
|
||||
# It will issue pvscan, vgimport, vgchange -ay, mkdir, then mount commands.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Capture::Tiny ':all';
|
||||
use Getopt::Long;
|
||||
use lib '/opt/xcat/lib/perl/';
|
||||
use xCAT::TableUtils;
|
||||
use xCAT::zvmUtils;
|
||||
$| = 1; # turn off STDOUT buffering
|
||||
|
||||
my $lvmPath = "/dev/xcat/repo";
|
||||
my $mountPoint = "/install";
|
||||
my $exportDir = "/install/xcatmigrate";
|
||||
my $exportTablesDir = "/install/xcatmigrate/xcattables";
|
||||
my $exportFcpConfigsDir = "/install/xcatmigrate/fcpconfigs";
|
||||
my $exportFcpOtherFilesDir = "/install/xcatmigrate/fcpotherfiles";
|
||||
my $exportDocloneFilesDir = "/install/xcatmigrate/doclone";
|
||||
my $lvmInfoFile = "lvminformation";
|
||||
my $lsdasdInfoFile = "lsdasdinformation";
|
||||
my $zvmVirtualDasdInfoFile = "zvmvirtualdasdinformation";
|
||||
my $vgName = "xcat";
|
||||
|
||||
# xCAT table information to be filled in
|
||||
my $masterIP;
|
||||
my $xcatNode;
|
||||
my $hcp;
|
||||
my $zhcpNode;
|
||||
|
||||
my $version = "1.1";
|
||||
my $targetIP = ""; # IP address to get data from
|
||||
my $skipInstallFiles = 0; # Skip copying any install files
|
||||
my $skipTables = 0; # Skip copying and installing xcat tables
|
||||
my $displayHelp = 0; # Display help information
|
||||
my $versionOpt = 0; # Show version information flag
|
||||
|
||||
my @entries;
|
||||
my @propNames;
|
||||
my $propVals;
|
||||
|
||||
my $usage_string = "This script saves the xcat tables in /install/xcatmigrate and\n
|
||||
then exports the LVM mounted at /install. This should only be used to migrate\n
|
||||
the /install LVM to a new userid.\n\n
|
||||
Usage:\n
|
||||
$0 [ -v ]\n
|
||||
$0 [ -h | --help ]\n
|
||||
The following options are supported:\n
|
||||
-h | --help Display help information\n
|
||||
-v Display the version of this script.\n";
|
||||
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 chompall
|
||||
|
||||
Description : Issue chomp on all three input parms (pass by reference)
|
||||
Arguments : arg1, arg2, arg3
|
||||
Returns : nothing
|
||||
Example : chompall(\$out, \$err, \$returnvalue);
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub chompall{
|
||||
my ( $arg1, $arg2, $arg3 ) = @_;
|
||||
chomp($$arg1);
|
||||
chomp($$arg2);
|
||||
chomp($$arg3);
|
||||
}
|
||||
|
||||
# ***********************************************************
|
||||
# Mainline. Parse any arguments, usually no arguments
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
|
||||
GetOptions(
|
||||
'h|help' => \$displayHelp,
|
||||
'v' => \$versionOpt );
|
||||
|
||||
if ( $versionOpt ) {
|
||||
print "Version: $version\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $displayHelp ) {
|
||||
print $usage_string;
|
||||
exit;
|
||||
}
|
||||
|
||||
my $out = '';
|
||||
my $err = '';
|
||||
my $returnvalue = 0;
|
||||
|
||||
# This looks in the passwd table for a key = sudoer
|
||||
($::SUDOER, $::SUDO) = xCAT::zvmUtils->getSudoer();
|
||||
|
||||
# Scan the xCAT tables to get the zhcp node name
|
||||
# Print out a message and stop if any errors found
|
||||
@entries = xCAT::TableUtils->get_site_attribute("master");
|
||||
$masterIP = $entries[0];
|
||||
if ( !$masterIP ) {
|
||||
print "xCAT site table is missing a master with ip address\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Get xcat node name from 'hosts' table using IP as key
|
||||
@propNames = ( 'node');
|
||||
$propVals = xCAT::zvmUtils->getTabPropsByKey('hosts', 'ip', $masterIP, @propNames);
|
||||
$xcatNode = $propVals->{'node'};
|
||||
if ( !$xcatNode ) {
|
||||
print "xCAT hosts table is missing a node with ip address of $masterIP\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Get hcp for xcat from the zvm table using xcat node name
|
||||
@propNames = ( 'hcp');
|
||||
$propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $xcatNode, @propNames );
|
||||
$hcp = $propVals->{'hcp'};
|
||||
if ( !$hcp ) {
|
||||
print "xCAT zvm table is missing hcp value for $xcatNode\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Get zhcp node name from 'hosts' table using hostname as key
|
||||
@propNames = ( 'node');
|
||||
$propVals = xCAT::zvmUtils->getTabPropsByKey('hosts', 'hostnames', $hcp, @propNames);
|
||||
$zhcpNode = $propVals->{'node'};
|
||||
if ( !$zhcpNode ) {
|
||||
print "xCAT hosts table is missing a zhcp node with hostname of $hcp\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#Create the migrate directory and the xcat tables directory. This should not get error even if it exists
|
||||
print "Creating directory $exportDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "mkdir -p -m 0755 $exportDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to create $exportDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Creating directory $exportTablesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "mkdir -p -m 0755 $exportTablesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to create $exportTablesDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Creating directory $exportFcpConfigsDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "mkdir -p -m 0755 $exportFcpConfigsDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to create $exportFcpConfigsDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Creating directory $exportFcpOtherFilesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "mkdir -p -m 0755 $exportFcpOtherFilesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to create $exportFcpOtherFilesDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Creating directory $exportDocloneFilesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "mkdir -p -m 0755 $exportDocloneFilesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to create $exportDocloneFilesDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#Save the current LVM information
|
||||
print "Saving current LVM information at $exportDir/$lvmInfoFile \n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "vgdisplay '-v' 2>&1 > $exportDir/$lvmInfoFile"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to display LVM information:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#Save the current Linux DASD list information
|
||||
print "Saving current Linux DASD list information at $exportDir/$lsdasdInfoFile \n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "lsdasd 2>&1 > $exportDir/$lsdasdInfoFile"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to display Linux DASD list information:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#Save the current zVM virtual DASD list information
|
||||
print "Saving current zVM virtual DASD list information at $exportDir/$zvmVirtualDasdInfoFile \n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "vmcp q v dasd 2>&1 > $exportDir/$zvmVirtualDasdInfoFile"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to display zVM virtual DASD list information:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#save the xcat tables
|
||||
print "Dumping xCAT tables to $exportTablesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( ". /etc/profile.d/xcat.sh; /opt/xcat/sbin/dumpxCATdb -p $exportTablesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to dump the xcat tables to $exportTablesDir:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#Check for and save any zhcp FCP configuration files
|
||||
print "Checking zhcp for any FCP configuration files\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "ssh $zhcpNode ls /var/opt/zhcp/zfcp/*.conf"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue == 0) {
|
||||
# Save any *.conf files
|
||||
print "Copying /var/opt/zhcp/zfcp/*.conf files to $exportFcpConfigsDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "scp $::SUDOER\@$zhcpNode:/var/opt/zhcp/zfcp/*.conf $exportFcpConfigsDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to use scp to copy files from $zhcpNode\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
# If file not found, that is an OK error, if others then display error and exit
|
||||
if (index($err, "No such file or directory")== -1) {
|
||||
print "Error rv:$returnvalue trying to use ssh to list files on $zhcpNode\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
# Check for any other zhcp FCP files
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "ssh $zhcpNode ls /opt/zhcp/conf/*"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue == 0) {
|
||||
# Save any files found
|
||||
print "Copying /opt/zhcp/conf/*.conf files to $exportFcpOtherFilesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "scp $::SUDOER\@$zhcpNode:/opt/zhcp/conf/* $exportFcpOtherFilesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to use scp to copy /opt/zhcp/conf/* files from $zhcpNode\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
# If file not found, that is an OK error, if others then display error and exit
|
||||
if (index($err, "No such file or directory")== -1) {
|
||||
print "Error rv:$returnvalue trying to use ssh to list files on $zhcpNode\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
# Check for any doclone.txt file
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "ls /var/opt/xcat/doclone.txt"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue == 0) {
|
||||
# Save any file found
|
||||
print "Copying /var/opt/xcat/doclone.txt file to $exportDocloneFilesDir\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "cp /var/opt/xcat/doclone.txt $exportDocloneFilesDir"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to copy /var/opt/xcat/doclone.txt file\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
# If file not found, that is an OK error, if others then display error and exit
|
||||
if (index($err, "No such file or directory")== -1) {
|
||||
print "Error rv:$returnvalue trying to copy /var/opt/xcat/doclone.txt file\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
#unmount the /install
|
||||
print "Unmounting $lvmPath\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "umount $lvmPath"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to umount $lvmPath:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#mark the lvm inactive
|
||||
print "Making the LVM $vgName inactive\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "vgchange '-an' $vgName"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to inactivate volume group $vgName:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
#export the volume group
|
||||
print "Exporting the volume group $vgName\n";
|
||||
( $out, $err, $returnvalue ) = eval { capture { system( "vgexport $vgName"); } };
|
||||
chompall(\$out, \$err, \$returnvalue);
|
||||
if ($returnvalue) {
|
||||
print "Error rv:$returnvalue trying to export volume group $vgName:\n";
|
||||
print "$err\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "\nVolume group $vgName is exported, you can now signal shutdown xcat and\n";
|
||||
print "have the xcat lvm disks linked RW in the new appliance.";
|
||||
exit 0;
|
||||
|
||||
|
758
xCAT-client/bin/zxcatimport.pl
Normal file
758
xCAT-client/bin/zxcatimport.pl
Normal file
@ -0,0 +1,758 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
# IBM (C) Copyright 2015, 2016 Eclipse Public License
|
||||
# http://www.eclipse.org/org/documents/epl-v10.html
|
||||
###############################################################################
|
||||
# COMPONENT: zxcatimport
|
||||
#
|
||||
# This is a program to copy the xCAT /install files and the xCAT tables from
|
||||
# an old XCAT userid to the new appliance
|
||||
# See usage string below for parameters.
|
||||
# return code = 0 successful; else error.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Capture::Tiny ':all';
|
||||
use Getopt::Long;
|
||||
use lib '/opt/xcat/lib/perl/';
|
||||
use xCAT::TableUtils;
|
||||
use xCAT::Table;
|
||||
use xCAT::zvmUtils;
|
||||
use xCAT::MsgUtils;
|
||||
|
||||
my $lvmPath = "/dev/xcat/repo";
|
||||
my $lvmMountPoint = "/install2";
|
||||
my $lvmImportDir = "/install2/xcatmigrate";
|
||||
my $lvmImportTablesDir = "/install2/xcatmigrate/xcattables";
|
||||
my $lvmImportFcpConfigsDir = "/install2/xcatmigrate/fcpconfigs";
|
||||
my $lvmImportFcpOtherFilesDir = "/install2/xcatmigrate/fcpotherfiles";
|
||||
my $lvmImportDocloneFilesDir = "/install2/xcatmigrate/doclone";
|
||||
my $lvmInfoFile = "lvminformation";
|
||||
my $lsdasdInfoFile = "lsdasdinformation";
|
||||
my $zvmVirtualDasdInfoFile = "zvmvirtualdasdinformation";
|
||||
my $vgName = "xcat";
|
||||
my $persistentMountPoint = "/persistent2";
|
||||
my @defaultTables = ("hosts", "hypervisor", "linuximage", "mac", "networks", "nodelist",
|
||||
"nodetype", "policy", "zvm");
|
||||
|
||||
my $version = "1.0";
|
||||
my $out;
|
||||
my $err;
|
||||
my $returnValue;
|
||||
|
||||
my $copyLvmFiles = 0; # Copy files under old /install to new /install
|
||||
my $replaceAllXcatTables = 0; # Copy one or all xcat tables
|
||||
my $addTableData = '*none*'; # Add node data to one table or default tables
|
||||
my $copyFcpConfigs = 0; # copy old zhcp fcp *.conf files
|
||||
my $copyDoclone = 0; # copy old doclone.txt file
|
||||
my $replaceSshKeys = 0; # replace SSH keys with old xCAT SSH keys
|
||||
my $displayHelp = 0; # Display help information
|
||||
my $versionOpt = 0; # Show version information flag
|
||||
my $rc = 0;
|
||||
|
||||
my $usage_string = "This script will mount or copy the old xcat lvm and old persistent disk\n
|
||||
to this appliance. The old xCAT LVM volumes and the persistent disk on XCAT userid must \n
|
||||
be linked in write mode by this appliance. The LVM will be mounted at '/install2' and \n
|
||||
the persistent disk will be mounted at '/persistent2'.\n
|
||||
\n
|
||||
The default is to just mount the persistent and LVM disks.\n
|
||||
They will be mounted as /install2 and /persistent2\n\n
|
||||
|
||||
Usage:\n
|
||||
$0 [--addtabledata [tablename]] [--installfiles ] [--doclonefile]\n
|
||||
[--fcppoolconfigs] [--replacealltables] [--replaceSSHkeys] \n
|
||||
$0 [ -v ]\n
|
||||
$0 [ -h | --help ]\n
|
||||
The following options are supported:\n
|
||||
--addtabledata [tablename] | ['tablename1 tablename2 ..']\n
|
||||
Add old xCAT data to specific table(s) or\n
|
||||
default to the following xCAT tables:\n
|
||||
hosts, hypervisor, linuximage, mac, networks, nodelist,\n
|
||||
nodetype, policy, zvm/n
|
||||
--installfiles Copy any files from old /install to appliance /install\n
|
||||
--doclonefile Copy any doclone.txt to appliance\n
|
||||
--fcppoolconfigs Copy any zhcp FCP pool configuration files\n
|
||||
--replacealltables Replace all xCAT tables with old xCAT tables\n
|
||||
--replaceSSHkeys Replaces the current xCAT SSH keys with the old xCAT SSH keys\n
|
||||
-h | --help Display help information\n
|
||||
-v Display the version of this script.\n";
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 chompall
|
||||
|
||||
Description : Issue chomp on all three input parms (pass by reference)
|
||||
Arguments : arg1, arg2, arg3
|
||||
Returns : nothing
|
||||
Example : chompall(\$out, \$err, \$returnValue);
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub chompall{
|
||||
my ( $arg1, $arg2, $arg3 ) = @_;
|
||||
chomp($$arg1);
|
||||
chomp($$arg2);
|
||||
chomp($$arg3);
|
||||
}
|
||||
|
||||
# =======unit test/debugging routine ==========
|
||||
# print the return data from tiny capture return
|
||||
# data for: out, err, return value
|
||||
sub printreturndata{
|
||||
my ( $arg1, $arg2, $arg3 ) = @_;
|
||||
print "=============================\n";
|
||||
print "Return value ($$arg3)\n";
|
||||
print "out ($$arg1)\n";
|
||||
print "err ($$arg2)\n\n";
|
||||
}
|
||||
|
||||
## ---------------------------------------------- ##
|
||||
## Subroutine to find device name from address
|
||||
|
||||
sub get_disk($)
|
||||
{
|
||||
my ($id_user) = @_;
|
||||
my $id = hex $id_user;
|
||||
my $hex_id = sprintf '%x', $id;
|
||||
my $dev_path = sprintf '/sys/bus/ccw/drivers/dasd-eckd/0.0.%04x', $id;
|
||||
unless (-d $dev_path) {
|
||||
$dev_path = sprintf '/sys/bus/ccw/drivers/dasd-fba/0.0.%04x', $id;
|
||||
}
|
||||
-d $dev_path or return undef;
|
||||
my $dev_block = "$dev_path/block";
|
||||
unless (-d $dev_block) {
|
||||
# Try bringing the device online
|
||||
for (1..5) {
|
||||
system("echo 1 > $dev_path/online");
|
||||
last if -d $dev_block;
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
opendir(my $dir, $dev_block) or return undef;
|
||||
my $dev;
|
||||
while ($dev = readdir $dir) {
|
||||
last unless $dev eq '.' || $dev eq '..';
|
||||
}
|
||||
closedir $dir;
|
||||
defined $dev ? "/dev/$dev" : undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 mountOldLVM
|
||||
|
||||
Description : This routine will import the old LVM and mount
|
||||
it at /install2
|
||||
Arguments : none
|
||||
Returns : 0 - LVM mounted or already mounted
|
||||
non-zero - Error detected.
|
||||
Example : $rc = mountOldLVM;
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub mountOldLVM{
|
||||
|
||||
my $saveMsg;
|
||||
my $saveErr;
|
||||
my $saveReturnValue;
|
||||
|
||||
#Check for /install2 If already mounted should get a return value(8192) and $err output
|
||||
#Check $err for "is already mounted on", if found we are done.
|
||||
print "Checking for $lvmMountPoint.\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mount $lvmMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if (index($err, "already mounted on $lvmMountPoint") > -1) {
|
||||
print "Old xCAT LVM is already mounted at $lvmMountPoint\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
print "Importing $vgName\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "/sbin/vgimport $vgName"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
# There could be a case where the LVM has been imported already
|
||||
# Save this error information and do the next step (vgchange)
|
||||
$saveMsg = "Error rv:$returnValue trying to vgimport $vgName";
|
||||
$saveErr = "$err";
|
||||
$saveReturnValue = $returnValue;
|
||||
}
|
||||
|
||||
print "Activating LVM $vgName\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "/sbin/vgchange -a y $vgName"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
# If the import failed previously, put out that message instead.
|
||||
if (!defined $saveMsg) {
|
||||
print "$saveMsg\n";
|
||||
print "$saveErr\n";
|
||||
return $saveReturnValue;
|
||||
} else {
|
||||
print "Error rv:$returnValue trying to vgchange -a y $vgName\n";
|
||||
print "$err\n";
|
||||
retun $returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
print "Making $lvmMountPoint directory\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mkdir -p $lvmMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to mkdir -p $lvmMountPoint\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
print "Mounting LVM $lvmPath at $lvmMountPoint\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mount -t ext3 $lvmPath $lvmMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to mkdir -p $lvmMountPoint\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
print "Old xCAT LVM is now mounted at $lvmMountPoint\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 mountOldPersistent
|
||||
|
||||
Description : This routine will look for the old persistent disk and mount
|
||||
it at /persistent2
|
||||
Arguments : none
|
||||
Returns : 0 - /persistent2 mounted or already mounted
|
||||
non-zero - Error detected.
|
||||
Example : $rc = mountOldPersistent;
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub mountOldPersistent{
|
||||
|
||||
#Check for /persistent2 If already mounted should get a return value(8192) and $err output
|
||||
#Check $err for "is already mounted on", if found we are done.
|
||||
print "Checking for $persistentMountPoint.\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mount $persistentMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if (index($err, "already mounted on $persistentMountPoint") > -1) {
|
||||
print "The old xCAT /persistent disk already mounted at $persistentMountPoint\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
# search the exported Linux lsdasd file to get the vdev for vdev 100 (dasda)
|
||||
# should look like: 0.0.0100 active dasda 94:0 ECKD 4096 2341MB 599400
|
||||
my $dasda = `cat "$lvmImportDir/$lsdasdInfoFile" | egrep -i "dasda"`;
|
||||
if (length($dasda) <= 50) {
|
||||
print "Unable to find dasda information in $lvmImportDir/$lsdasdInfoFile\n";
|
||||
return 1;
|
||||
}
|
||||
my @tokens = split(/\s+/, $dasda);
|
||||
my @vdevparts = split (/\./, $tokens[0]);
|
||||
my $vdev = $vdevparts[2];
|
||||
if (!(length($vdev))) {
|
||||
print "Unable to find a vdev value for dasda\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
# search the exported zVM virtual dasd list to get the volume id of the disk
|
||||
# should look like: DASD 0100 3390 QVCD69 R/W 3330 CYL ON DASD CD69 SUBCHANNEL = 000B
|
||||
my $voliddata = `cat "$lvmImportDir/$zvmVirtualDasdInfoFile" | egrep -i "DASD $vdev"`;
|
||||
if (length($voliddata) <= 50) {
|
||||
print "Unable to find volid information for $vdev in $lvmImportDir/$zvmVirtualDasdInfoFile\n";
|
||||
return 1;
|
||||
}
|
||||
@tokens = split(/\s+/, $voliddata);
|
||||
my $volid = $tokens[3];
|
||||
if (!(length($volid))) {
|
||||
print "Unable to find a volume id for vdev $vdev\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Now display the current zVM query v dasd to see if they have the volid listed
|
||||
# and what vdev it is mounted on
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "vmcp q v dasd 2>&1"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to vmcp q v dasd\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
# get the current VDEV the old volid is now using
|
||||
# If not they they did not update the directory to link to the old classic disk
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "echo \"$out\" | egrep -i $volid"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to echo $out\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
if (!(length($out))) {
|
||||
print "Unable to find a current vdev value for volume id $volid\n";
|
||||
return 1;
|
||||
}
|
||||
@tokens = split(/\s+/, $out);
|
||||
my $currentvdev = $tokens[1];
|
||||
if (!(length($currentvdev))) {
|
||||
print "Unable to find a current vdev value for volume id $volid\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Now get the Linux disk name that is being used for this vdev (/dev/dasdx)
|
||||
my $devname = get_disk($currentvdev);
|
||||
#print "Devname found: $devname\n";
|
||||
if (!(defined $devname)) {
|
||||
print "Unable to find a Linux disk for address $currentvdev volume id $volid\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Create the directory for the mount of old persistent disk
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mkdir -p -m 0755 $persistentMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to create $persistentMountPoint:\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
# Mount the old persistent disk, must be partition 1
|
||||
my $partition = 1;
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mount -t ext3 $devname$partition $persistentMountPoint"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to mount -t ext3 $devname$partition $persistentMountPoint\n";
|
||||
print "$err\n";
|
||||
return $returnValue;
|
||||
}
|
||||
print "The old xCAT /persistent disk is mounted at $persistentMountPoint\n";
|
||||
return 0;
|
||||
}
|
||||
# ***********************************************************
|
||||
# Mainline. Parse any arguments
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
|
||||
GetOptions(
|
||||
'installfiles' => \$copyLvmFiles,
|
||||
'replacealltables' => \$replaceAllXcatTables,
|
||||
'addtabledata:s' => \$addTableData,
|
||||
'fcppoolconfigs' => \$copyFcpConfigs,
|
||||
'doclonefile' => \$copyDoclone,
|
||||
'replaceSSHkeys' => \$replaceSshKeys,
|
||||
'h|help' => \$displayHelp,
|
||||
'v' => \$versionOpt );
|
||||
|
||||
if ( $versionOpt ) {
|
||||
print "Version: $version\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ( $displayHelp ) {
|
||||
print $usage_string;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# Use sudo or not
|
||||
# This looks in the passwd table for a key = sudoer
|
||||
($::SUDOER, $::SUDO) = xCAT::zvmUtils->getSudoer();
|
||||
|
||||
$rc = mountOldLVM();
|
||||
if ($rc != 0) {
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$rc = mountOldPersistent();
|
||||
if ($rc != 0) {
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Copy the LVM files from old xCAT LVM to current LVM
|
||||
if ( $copyLvmFiles ) {
|
||||
$rc = chdir("$lvmMountPoint");
|
||||
if (!$rc) {
|
||||
print "Error rv:$rc trying to chdir $lvmMountPoint\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$out = `cp -a * /install 2>&1`;
|
||||
if ($?) {
|
||||
print "Error rv:$? trying to copy from $lvmMountPoint to /install. $out\n";
|
||||
exit $?;
|
||||
}
|
||||
print "Old LVM Files copied from $lvmMountPoint to /install\n" ;
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Replace all the current xCAT tables with the old xCAT tables
|
||||
if ( $replaceAllXcatTables ) {
|
||||
print "Restoring old xCAT tables from $lvmImportTablesDir\n";
|
||||
# restorexCATdb - restores the xCAT db tables from the directory -p path
|
||||
( $out, $err, $returnValue ) = eval { capture { system( ". /etc/profile.d/xcat.sh; /opt/xcat/sbin/restorexCATdb -p $lvmImportTablesDir"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to restore the xcat tables from $lvmImportTablesDir:\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
# There is a chance the return value is 0, and the $out says "Restore of Database Complete.";
|
||||
# Yet some of the tables had failures. That information is in $err
|
||||
if (length($err)) {
|
||||
print "Some tables did not restore. Error output:\n$err\n ";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Copy the zhcp FCP config files
|
||||
if ($copyFcpConfigs) {
|
||||
# Check if there are any FCP config files to copy
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "ls $lvmImportFcpConfigsDir/*.conf"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue == 0) {
|
||||
# Save any *.conf files
|
||||
print "Copying $lvmImportFcpConfigsDir/*.conf files to /var/opt/zhcp/zfcp\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mkdir -p /var/opt/zhcp/zfcp && cp -R $lvmImportFcpConfigsDir/*.conf /var/opt/zhcp/zfcp/"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy files from $lvmImportFcpConfigsDir\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
} else {
|
||||
print "There were not any zhcp FCP *.conf files to copy\n";
|
||||
}
|
||||
# Check if there are any other FCP files to copy
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "ls $lvmImportFcpOtherFilesDir/*"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue == 0) {
|
||||
# Save any files
|
||||
print "Copying $lvmImportFcpOtherFilesDir/* files to /opt/zhcp/conf\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "mkdir -p /opt/zhcp/conf && cp -R $lvmImportFcpOtherFilesDir/* /opt/zhcp/conf/"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy files from $lvmImportFcpOtherFilesDir\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
} else {
|
||||
print "There were not any zhcp files from /opt/zhcp/conf to copy\n";
|
||||
}
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Copy the doclone.txt file if it exists
|
||||
if ($copyDoclone) {
|
||||
# Check if there is a doclone.txt to copy
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "ls $lvmImportDocloneFilesDir/doclone.txt"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue == 0) {
|
||||
# Save this file in correct location
|
||||
print "Copying $lvmImportDocloneFilesDir/doclone.txt file to /var/opt/xcat/doclone.txt\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp -R $lvmImportDocloneFilesDir/doclone.txt /var/opt/xcat/"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy doclone.txt file from $lvmImportDocloneFilesDir\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
} else {
|
||||
print "There was not any doclone.txt file to copy\n";
|
||||
}
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Add old xCAT table data to a table
|
||||
my $test = length($addTableData);
|
||||
# Add old xCAT data to an existing table. Admin may need to delete out duplicates using the GUI
|
||||
if ((length($addTableData)==0) || $addTableData ne "*none*") {
|
||||
#defaultTables = ("hosts", "hypervisor", "linuximage", "mac", "networks", "nodelist",
|
||||
# "nodetype", "policy", "zvm");
|
||||
my @tables = @defaultTables;
|
||||
if (length($addTableData)>1 ) {
|
||||
# use the table specified
|
||||
@tables = ();
|
||||
@tables = split(' ',$addTableData);
|
||||
}
|
||||
foreach my $atable (@tables) {
|
||||
print "Adding data to table $atable\n";
|
||||
# the current xCAT code we have does not support the -a option
|
||||
# use xCAT::Table functions
|
||||
|
||||
my $tabledata = `cat "$lvmImportTablesDir\/$atable\.csv"`;
|
||||
if (length($tabledata) <= 10) {
|
||||
print "Unable to find table information for $atable in $lvmImportTablesDir\n";
|
||||
return 1;
|
||||
}
|
||||
# remove the hash tag from front
|
||||
$tabledata =~ s/\#//;
|
||||
my @rows = split('\n', $tabledata);
|
||||
my @keys;
|
||||
my @values;
|
||||
my $tab;
|
||||
# loop through all the csv rows, first are the header keys, rest is data
|
||||
foreach my $i (0 .. $#rows) {
|
||||
my %record;
|
||||
#print "row $i data($rows[$i])\n";
|
||||
if ($i == 0) {
|
||||
@keys = split(',', $rows[0]);
|
||||
#print "Keys found:(@keys)\n";
|
||||
} else {
|
||||
# now that we know we have data, lets create table
|
||||
if (!defined $tab) {
|
||||
$tab = xCAT::Table->new($atable, -create => 1, -autocommit => 0);
|
||||
}
|
||||
# put the data into the new table.
|
||||
@values = split(',', $rows[$i]);
|
||||
foreach my $v (0 .. $#values) {
|
||||
# Strip off any leading and trailing double quotes
|
||||
$values[$v] =~ s/"(.*?)"\z/$1/s;
|
||||
$record{$keys[$v]} = $values[$v];
|
||||
#print "Row $i matches key $keys[$v] Value found:($values[$v])\n";
|
||||
}
|
||||
}
|
||||
# write out the row if any keys added to the hash
|
||||
if (%record) {
|
||||
my @dbrc = $tab->setAttribs(\%record, \%record);
|
||||
if (!defined($dbrc[0])) {
|
||||
print "Error ($dbrc[1]) setting database for table $atable";
|
||||
$tab->rollback();
|
||||
$tab->close;
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
# if we made it here and $tab is defined, commit it.
|
||||
if (defined $tab) {
|
||||
$tab->commit;
|
||||
print "Data successfully added and committed to $atable.\n*****! Remember to check the table and remove any rows not needed\n";
|
||||
}
|
||||
}#end for each table
|
||||
}
|
||||
|
||||
# *****************************************************************************
|
||||
# **** Replace the xCAT SSH key with the old xCAT SSH key
|
||||
|
||||
# First copy the current keys and copy the old xCAT keys into unique file names
|
||||
if ($replaceSshKeys) {
|
||||
# Make temp file names to hold the current and old ssh public and private key
|
||||
my $copySshKey= `/bin/mktemp -p /root/.ssh/ id_rsa.pub_XXXXXXXX`;
|
||||
chomp($copySshKey);
|
||||
my $copySshPrivateKey= `/bin/mktemp -p /root/.ssh/ id_rsa_XXXXXXXX`;
|
||||
chomp($copySshPrivateKey);
|
||||
|
||||
# Make temp files for the RSA backup keys in appliance
|
||||
my $copyHostSshKey= `/bin/mktemp -p /etc/ssh/ ssh_host_rsa_key.pub_XXXXXXXX`;
|
||||
chomp($copyHostSshKey);
|
||||
my $copyHostSshPrivateKey= `/bin/mktemp -p /etc/ssh/ ssh_host_rsa_key_XXXXXXXX`;
|
||||
chomp($copyHostSshPrivateKey);
|
||||
|
||||
# Save old keys in unique names
|
||||
my $oldSshKey= `/bin/mktemp -p /root/.ssh/ id_rsa.pub_OldMachineXXXXXXXX`;
|
||||
chomp($oldSshKey);
|
||||
my $oldSshPrivateKey= `/bin/mktemp -p /root/.ssh/ id_rsa_OldMachineXXXXXXXX`;
|
||||
chomp($oldSshPrivateKey);
|
||||
|
||||
print "Making backup copies of current xCAT SSH keys\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-p /root/.ssh/id_rsa.pub $copySshKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /root/.ssh/id_rsa.pub to $copySshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-p /root/.ssh/id_rsa $copySshPrivateKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /root/.ssh/id_rsa to $copySshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Save appliance backup keys
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-p /etc/ssh/ssh_host_rsa_key.pub $copyHostSshKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /etc/ssh/ssh_host_rsa_key.pub to $copyHostSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-p /etc/ssh/ssh_host_rsa_key $copyHostSshPrivateKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /etc/ssh/ssh_host_rsa_key to $copyHostSshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Copy the old public key and make sure the permissions are 644
|
||||
print "Copying old xCAT SSH keys (renamed) from /persistent2 to /root/.ssh\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp /persistent2/root/.ssh/id_rsa.pub $oldSshKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /persistent2/root/.ssh/id_rsa.pub to $oldSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "chmod 644 $oldSshKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to chmod 644 $oldSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Copy the private key and make sure the permissions are 600
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp /persistent2/root/.ssh/id_rsa $oldSshPrivateKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use cp to copy /persistent2/root/.ssh/id_rsa to $oldSshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "chmod 600 $oldSshPrivateKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to chmod 600 $oldSshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Now compare the IP of xCAT to zHCP .
|
||||
# If they are the same, then only the private and public key in xCAT needs to be changed.
|
||||
# If zhcp is on a different machine, then the first thing to be done is add the old xCAT key
|
||||
# to the zhcp authorized_keys files, then do the switch on xcat of public and private keys
|
||||
|
||||
my $xcatIp;
|
||||
my $zhcpIp;
|
||||
my $zhcpHostName;
|
||||
my $zhcpNode;
|
||||
my $xcatNodeName;
|
||||
my @propNames;
|
||||
my $propVals;
|
||||
my @entries;
|
||||
my $rc = 0;
|
||||
|
||||
# Scan the xCAT tables to get the zhcp node name
|
||||
# Print out a message and stop if any errors found
|
||||
@entries = xCAT::TableUtils->get_site_attribute("master");
|
||||
$xcatIp = $entries[0];
|
||||
if ( !$xcatIp ) {
|
||||
print "xCAT site table is missing a master with ip address\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Get xcat node name from 'hosts' table using IP as key
|
||||
@propNames = ( 'node');
|
||||
$propVals = xCAT::zvmUtils->getTabPropsByKey('hosts', 'ip', $xcatIp, @propNames);
|
||||
$xcatNodeName = $propVals->{'node'};
|
||||
if ( !$xcatNodeName ) {
|
||||
print "xCAT hosts table is missing a node with ip address of $xcatIp\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Get hcp hostname for xcat from the zvm table using xcat node name
|
||||
@propNames = ( 'hcp');
|
||||
$propVals = xCAT::zvmUtils->getNodeProps( 'zvm', $xcatNodeName, @propNames );
|
||||
$zhcpHostName = $propVals->{'hcp'};
|
||||
if ( !$zhcpHostName ) {
|
||||
print "xCAT zvm table is missing hcp value for $xcatNodeName\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Get zhcp IP and node from 'hosts' table using hostname as key
|
||||
@propNames = ( 'ip', 'node');
|
||||
$propVals = xCAT::zvmUtils->getTabPropsByKey('hosts', 'hostnames', $zhcpHostName, @propNames);
|
||||
$zhcpIp = $propVals->{'ip'};
|
||||
if ( !$zhcpIp ) {
|
||||
print "xCAT hosts table is missing a zhcp node IP with hostname of $zhcpHostName\n";
|
||||
exit 1;
|
||||
}
|
||||
$zhcpNode = $propVals->{'node'};
|
||||
if ( !$zhcpNode ) {
|
||||
print "xCAT hosts table is missing a zhcp node with hostname of $zhcpHostName\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($zhcpIp eq $xcatIp) {
|
||||
print "xCAt and zhcp are on same IP, only need to update public and private keys\n";
|
||||
} else {
|
||||
# Need to append the old SSH key to zhcp authorized_keys file
|
||||
my $target = "$::SUDOER\@$zhcpHostName";
|
||||
print "Copying old SSH key to zhcp\n";
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "scp $oldSshKey $target:$oldSshKey"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to use scp to copy $oldSshKey to zhcp $oldSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
# Adding the old SSH key to the authorized_keys file
|
||||
# Make a copy of the old authorized_users file
|
||||
my $suffix = '_' . substr($oldSshKey, -8);
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "ssh $target cp \"/root/.ssh/authorized_keys /root/.ssh/authorized_keys$suffix\""); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to make a copy of the /root/.ssh/authorized_keys file\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
# Add the key to zhcp authorized_keys file
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "ssh $target cat \"$oldSshKey >> /root/.ssh/authorized_keys\""); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to append zhcp $oldSshKey to /root/.ssh/authorized_keys\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
# We need to replace the xCAT public and private key with the old keys
|
||||
# and add the old key to the authorized_keys on xCAT
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cat $oldSshKey >> /root/.ssh/authorized_keys"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to append xcat $oldSshKey to /root/.ssh/authorized_keys\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-f $oldSshKey /root/.ssh/id_rsa.pub"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to replace the /root/.ssh/id_rsa.pub with the $oldSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-f $oldSshPrivateKey /root/.ssh/id_rsa"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
#printreturndata(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to replace the /root/.ssh/id_rsa with the $oldSshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
# Copy old keys into appliance saved key locations
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-f $oldSshKey /etc/ssh/ssh_host_rsa_key.pub"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to replace the /etc/ssh/ssh_host_rsa_key.pub with the $oldSshKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
( $out, $err, $returnValue ) = eval { capture { system( "cp \-f $oldSshPrivateKey /etc/ssh/ssh_host_rsa_key"); } };
|
||||
chompall(\$out, \$err, \$returnValue);
|
||||
if ($returnValue) {
|
||||
print "Error rv:$returnValue trying to replace the /etc/ssh/ssh_host_rsa_key with the $oldSshPrivateKey\n";
|
||||
print "$err\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
print "Old xCAT SSH keys have replaced current SSH keys. Previous key data saved in unique names.\n";
|
||||
}
|
||||
|
||||
exit 0;
|
9
xCAT-client/openstack.versions
Normal file
9
xCAT-client/openstack.versions
Normal file
@ -0,0 +1,9 @@
|
||||
# This file maps the OpenStack version numbers to their OpenStack release name.
|
||||
15. OCATA
|
||||
14. NEWTON
|
||||
13. MIKATA
|
||||
12. LIBERTY
|
||||
2015. KILO
|
||||
2014.2. JUNO
|
||||
2014.1. ICEHOUSE
|
||||
2013.2. HAVANA
|
@ -16,6 +16,9 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root
|
||||
%define pcm %(if [ "$pcm" = "1" ];then echo 1; else echo 0; fi)
|
||||
%define notpcm %(if [ "$pcm" = "1" ];then echo 0; else echo 1; fi)
|
||||
|
||||
%define s390x %(if [ "$s390x" = "1" ];then echo 1; else echo 0; fi)
|
||||
%define nots390x %(if [ "$s390x" = "1" ];then echo 0; else echo 1; fi)
|
||||
|
||||
# AIX will build with an arch of "ppc"
|
||||
%ifos linux
|
||||
BuildArch: noarch
|
||||
@ -69,6 +72,10 @@ cp share/xcat/rvid/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/rvid/
|
||||
chmod 755 $RPM_BUILD_ROOT/%{prefix}/share/xcat/rvid/*
|
||||
%endif
|
||||
|
||||
%if %s390x
|
||||
cp openstack.versions $RPM_BUILD_ROOT/%{prefix}
|
||||
chmod 644 $RPM_BUILD_ROOT/%{prefix}/openstack.versions
|
||||
%endif
|
||||
cp bin/* $RPM_BUILD_ROOT/%{prefix}/bin
|
||||
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
|
||||
cp sbin/* $RPM_BUILD_ROOT/%{prefix}/sbin
|
||||
|
29
xCAT/xcat.conf.apach22
Normal file
29
xCAT/xcat.conf.apach22
Normal file
@ -0,0 +1,29 @@
|
||||
#
|
||||
# This configuration file allows a diskfull install to access the install images
|
||||
# via http. It also allows the xCAT documentation to be accessed via
|
||||
# http://localhost/xcat-doc/
|
||||
# Updates to xCAT/xcat.conf should also be made to xCATsn/xcat.conf
|
||||
#
|
||||
AliasMatch ^/install/(.*)$ "/install/$1"
|
||||
AliasMatch ^/tftpboot/(.*)$ "/tftpboot/$1"
|
||||
|
||||
<Directory "/tftpboot">
|
||||
Options Indexes +FollowSymLinks +Includes MultiViews
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
</Directory>
|
||||
<Directory "/install">
|
||||
Options Indexes +FollowSymLinks +Includes MultiViews
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
</Directory>
|
||||
|
||||
Alias /xcat-doc "/opt/xcat/share/doc"
|
||||
<Directory "/opt/xcat/share/doc">
|
||||
Options Indexes
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
</Directory>
|
Loading…
x
Reference in New Issue
Block a user