Merge branch '2.8' of ssh://git.code.sf.net/p/xcat/xcat-core into 2.8

This commit is contained in:
ligc 2013-08-02 09:47:13 +08:00
commit 3847fe71c0
6 changed files with 211 additions and 51 deletions

View File

@ -10,6 +10,8 @@ B<tabdump> [I<table>]
B<tabdump> [I<-f> I<filename>] [I<table>]
B<tabdump> [I<-n> I<# of records>] [I<auditlog | eventlog>]
B<tabdump> [I<-w> I<attr>==I<val>] [B<-w> I<attr>=~I<val>] ...] [I<table>]
B<tabdump> [I<-w> I<attr>==I<val>] [B<-w> I<attr>=~I<val>] ...] [I<-f> I<filename>] [I<table>]
@ -38,6 +40,15 @@ Display usage message.
Show descriptions of the tables, instead of the contents of the tables. If a table name is also specified, descriptions of the columns (attributes) of the table will be displayed. Otherwise, a summary of each table will be displayed.
=item B<-n>
Shows the most recent number of entries as supplied on the -n flag from the auditlog or eventlog table.
=item B<-f>
File name or path to file in which to dump the table. Without this the table is dumped
to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory.
=item B<-w> I<'attr==val'> B<-w> I<'attr=~val'> ...
Use one or multiple -w flags to specify the selection string that can be used to select particular rows of the table. See examples.
@ -54,11 +65,6 @@ Operator descriptions:
!~ Select nodes where the attribute value matches the SQL NOT LIKE value.
=item B<-f>
File name or path to file in which to dump the table. Without this the table is dumped
to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory.
=back
=head1 RETURN VALUE
@ -111,6 +117,12 @@ tabdump -w 'audittime>2011-04-18 11:30:00' auditlog
=item *
To display the 10 most recent entries in the auditlog:
tabdump -n 10 auditlog
=item *
To see what tables exist in the xCAT database:
B<tabdump>

View File

@ -2512,19 +2512,26 @@ sub insert_dd {
} elsif ( grep (/LZMA compressed data/, @format)) {
$initrdfmt = "lzma";
} else {
my $rsp;
push @{$rsp->{data}}, "Could not handle the format of the initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return ();
# check whether it can be handled by xz
$cmd = "xz -t $img";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) {
my $rsp;
push @{$rsp->{data}}, "Could not handle the format of the initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return ();
} else {
$initrdfmt = "lzma";
}
}
if ($initrdfmt eq "gzip") {
$cmd = "gunzip -c $img > $dd_dir/initrd";
} elsif ($initrdfmt eq "lzma") {
if (! -x "/usr/bin/lzma") {
if (! -x "/usr/bin/xz") {
my $rsp;
push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not lzma command.";
push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not xz command.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return ();
}
@ -2698,7 +2705,7 @@ sub insert_dd {
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the depdency for the drivers in the initrd.";
push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the drivers depdency for $kernelver in the initrd.";
xCAT::MsgUtils->message("I", $rsp, $callback);
}
}
@ -3004,7 +3011,7 @@ sub insert_dd {
if ($initrdfmt eq "gzip") {
$cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|gzip -9 -c - > $dd_dir/initrd.img";
} elsif ($initrdfmt eq "lzma") {
$cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|lzma -C crc32 -9 > $dd_dir/initrd.img";
$cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|xz --format=lzma -C crc32 -9 > $dd_dir/initrd.img";
}
xCAT::Utils->runcmd($cmd, -1);
@ -3072,13 +3079,23 @@ sub insert_dd {
my $rsp;
if (@dd_list) {
push @{$rsp->{data}}, "Inserted the driver update disk:".join(',',@inserted_dd).".";
push @{$rsp->{data}}, "The driver update disk:".join(',',@inserted_dd)." have been injected to initrd.";
}
if (@driver_list) {
push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages.";
} elsif (@rpm_list && ($Injectalldriver || @driver_list)) {
push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list)).".";
# remove the duplicated names
my %dnhash;
foreach (@rpm_drivers) {
$dnhash{$_} = 1;
}
@rpm_drivers = keys %dnhash;
if (@rpm_list) {
if (@driver_list) {
push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd.";
} elsif ($Injectalldriver) {
push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd.";
}
}
xCAT::MsgUtils->message("I", $rsp, $callback);
return @inserted_dd;

View File

@ -7,6 +7,7 @@ BEGIN
use strict;
use lib "$::XCATROOT/lib/perl";
use File::Path;
use File::Copy;
use xCAT::MsgUtils;
use xCAT::TableUtils;
@ -127,6 +128,9 @@ sub geninitrd {
$tftpdir = $t_entry;
}
my $tftppath = "$tftpdir/xcat/osimage/$osimage";
unless (-d $tftppath) {
mkpath $tftppath;
}
if ($arch =~ /x86/) {
if ($osvers =~ /(^ol[0-9].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)/) {
$kernelpath = "$tftppath/vmlinuz";

View File

@ -254,6 +254,12 @@ sub add_hosts_content {
{
addnode $callback, $nodename, $ip, $ref->{hostnames}, $domain;
}
else
{
my $rsp;
push @{$rsp->{data}}, "Invalid IP Addr \'$_->{ip}\' for node \'$_->{node}\'.";
xCAT::MsgUtils->message("E", $rsp, $callback);
}
if (defined($ref->{otherinterfaces}))
{
addotherinterfaces $callback, $nodename, $ref->{otherinterfaces}, $domain;

View File

@ -1802,9 +1802,9 @@ sub insert_dd () {
}
# get the new kernel if it exists in the update distro
my @new_kernels = <$dd_dir/rpm/boot/vmlinuz*>;
my @new_kernels = <$dd_dir/rpm/boot/vmlinu*>;
foreach my $new_kernel (@new_kernels) {
if (-r $new_kernel && $new_kernel =~ /\/vmlinuz-(.*(x86_64|ppc64))$/) {
if (-r $new_kernel && $new_kernel =~ /\/vmlinu[zx]-(.*(x86_64|ppc64|default))$/) {
$new_kernel_ver = $1;
$cmd = "/bin/mv -f $new_kernel $dd_dir/rpm/newkernel";
xCAT::Utils->runcmd($cmd, -1);
@ -1928,34 +1928,32 @@ sub insert_dd () {
}
}
} # end of loading drivers from rpm packages
}
# Create the dir for driver update disk
mkpath("$dd_dir/initrd_img/cus_driverdisk");
# Create the dir for driver update disk
mkpath("$dd_dir/initrd_img/cus_driverdisk");
# insert the driver update disk into the cus_driverdisk dir
foreach my $dd (@dd_list) {
copy($dd, "$dd_dir/initrd_img/cus_driverdisk");
}
# insert the driver update disk into the cus_driverdisk dir
foreach my $dd (@dd_list) {
copy($dd, "$dd_dir/initrd_img/cus_driverdisk");
}
# Repack the initrd
# In order to avoid the runcmd add the '2>&1' at end of the cpio
# cmd, the echo cmd is added at the end
$cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return ();
}
# Repack the initrd
# In order to avoid the runcmd add the '2>&1' at end of the cpio
# cmd, the echo cmd is added at the end
$cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return ();
}
# zip the initrd
#move ("$dd_dir/initrd.new", "$dd_dir/initrd");
$cmd = "gzip -f $dd_dir/initrd";
xCAT::Utils->runcmd($cmd, -1);
# zip the initrd
#move ("$dd_dir/initrd.new", "$dd_dir/initrd");
$cmd = "gzip -f $dd_dir/initrd";
xCAT::Utils->runcmd($cmd, -1);
if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) {
if ($arch =~/ppc/) {
if (-r "$dd_dir/rpm/newkernel") {
# if there's new kernel from update distro, then use it
@ -1999,12 +1997,21 @@ sub insert_dd () {
my $rsp;
if (@dd_list) {
push @{$rsp->{data}}, "Inserted the driver update disk:".join(',', sort(@dd_list)).".";
push @{$rsp->{data}}, "The driver update disk:".join(',',@dd_list)." have been injected to initrd.";
}
if (@driver_list) {
push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages.";
} elsif (@rpm_list && ($Injectalldriver || @driver_list)) {
push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list)).".";
# remove the duplicated names
my %dnhash;
foreach (@rpm_drivers) {
$dnhash{$_} = 1;
}
@rpm_drivers = keys %dnhash;
if (@rpm_list) {
if (@driver_list) {
push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd.";
} elsif ($Injectalldriver) {
push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd.";
}
}
xCAT::MsgUtils->message("I", $rsp, $callback);

View File

@ -558,6 +558,7 @@ sub tabdump
my $OPTW;
my $VERSION;
my $FILENAME;
my $NUMBERENTRIES;
my $tabdump_usage = sub {
my $exitcode = shift @_;
@ -565,6 +566,7 @@ sub tabdump
push @{$rsp{data}}, "Usage: tabdump [-d] [table]";
push @{$rsp{data}}, " tabdump [table]";
push @{$rsp{data}}, " tabdump [-f <filename>] [table]";
push @{$rsp{data}}, " tabdump [-n <# of records>] [auditlog | eventlog]";
push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [table]";
push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [-f <filename>] [table]";
push @{$rsp{data}}, " tabdump [-?|-h|--help]";
@ -578,10 +580,14 @@ sub tabdump
if ($args) {
@ARGV = @{$args};
}
Getopt::Long::Configure("posix_default");
Getopt::Long::Configure("no_gnu_compat");
Getopt::Long::Configure("bundling");
if (!GetOptions(
'h|?|help' => \$HELP,
'v|version' => \$VERSION,
'n|lines=i' => \$NUMBERENTRIES,
'd' => \$DESC,
'f=s' => \$FILENAME,
'w=s@' => \$OPTW,
@ -601,8 +607,23 @@ sub tabdump
if ($HELP) { $tabdump_usage->(0); return; }
if (($NUMBERENTRIES) && ($DESC)) {
$cb->({error => "You cannot use the -n and -d flag together. ",errorcode=>1});
return 1;
}
if (($NUMBERENTRIES) && ($OPTW)) {
$cb->({error => "You cannot use the -n and -w flag together. ",errorcode=>1});
return 1;
}
if (($NUMBERENTRIES) && ($FILENAME)) {
$cb->({error => "You cannot use the -n and -f flag together. ",errorcode=>1});
return 1;
}
if (scalar(@ARGV)>1) { $tabdump_usage->(1); return; }
my %rsp;
# If no arguments given, we display a list of the tables
if (!scalar(@ARGV)) {
@ -626,9 +647,18 @@ sub tabdump
}
# get the table name
$table = $ARGV[0];
# if -n can only be the auditlog or eventlog
if ($NUMBERENTRIES) {
if (!( $table =~ /^auditlog/ ) && (!($table =~ /^eventlog/))){
$cb->({error => "$table table is not supported in tabdump -n. You may only use this option on the auditlog or the eventlog.",errorcode=>1});
return 1;
}
}
# do not allow teal tables
if ( $table =~ /^x_teal/ ) {
$cb->({error => "$table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1});
$cb->({error => "$table table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1});
return 1;
}
if ($DESC) { # only show the attribute descriptions, not the values
@ -665,6 +695,15 @@ sub tabdump
$cb->({error => "No such table: $table",errorcode=>1});
return 1;
}
#
# if tabdump -n <number of recs> auditlog|eventlog
#
if (defined $NUMBERENTRIES ) {
my $rc=tabdump_numberentries($table,$cb,$NUMBERENTRIES);
return $rc;
}
my $recs;
my @ents;
my @attrarray;
@ -717,6 +756,81 @@ sub tabdump
}
}
}
#
# display input number of records for the table requested tabdump -n
#
sub tabdump_numberentries {
my $table = shift;
my $cb = shift;
my $numberentries = shift; # either number of records to display
my $attrrecid="recid";
my $VERBOSE = shift;
my $rc=0;
my $tab = xCAT::Table->new($table);
unless ($tab) {
$cb->({error => "Unable to open $table",errorcode=>4});
return 1;
}
my $DBname = xCAT::Utils->get_DBName;
my @attribs = ($attrrecid);
my @ents=$tab->getAllAttribs(@attribs);
if (@ents) { # anything to process
# find smallest and largest recid, note table is not ordered by recid after
# a while
my $smallrid;
my $largerid;
foreach my $rid (@ents) {
if (!(defined $smallrid)) {
$smallrid=$rid;
}
if (!(defined $largerid)) {
$largerid=$rid;
}
if ($rid->{$attrrecid} < $smallrid->{$attrrecid}) {
$smallrid=$rid;
}
if ($rid->{$attrrecid} > $largerid->{$attrrecid}) {
$largerid=$rid;
}
}
my $RECID;
#determine recid to show all records after
$RECID= $largerid->{$attrrecid} - $numberentries ;
$rc=tabdump_recid($table,$cb,$RECID, $attrrecid);
} else {
my %rsp;
push @{$rsp{data}}, "Nothing to display from $table.";
$rsp{errorcode} = $rc;
$cb->(\%rsp);
}
return $rc;
}
# Display requested recored
# if rec id does not exist error
sub tabdump_recid {
my $table = shift;
my $cb = shift;
my $recid = shift;
my $rc=0;
# check which database so can build the correct Where clause
my $tab = xCAT::Table->new($table);
unless ($tab) {
$cb->({error => "Unable to open $table",errorcode=>4});
return 1;
}
my $DBname = xCAT::Utils->get_DBName;
my @recs;
my $attrrecid="recid";
# display the output
if ($DBname =~ /^DB2/) {
@recs=$tab->getAllAttribsWhere("\"$attrrecid\">$recid", 'ALL');
} else {
@recs=$tab->getAllAttribsWhere("$attrrecid>$recid", 'ALL');
}
output_table($table,$cb,$tab,\@recs);
return $rc;
}
# Display information from the daemon.
#
sub lsxcatd
@ -853,7 +967,7 @@ sub tabprune
push @{$rsp{data}}, " tabprune <tablename> [-V] -d <# of days>";
push @{$rsp{data}}, " tabprune [-h|--help]";
push @{$rsp{data}}, " tabprune [-v|--version]";
push @{$rsp{data}}, " tables supported:eventlog,auditlog,isnm_perf,isnm_perf_sum";
push @{$rsp{data}}, " tables supported:eventlog,auditlog";
push @{$rsp{data}}, " -d option only supported for eventlog,auditlog";
if ($exitcode) { $rsp{errorcode} = $exitcode; }
$cb->(\%rsp);
@ -952,7 +1066,7 @@ sub tabprune
if (($table eq "eventlog") || ($table eq "auditlog")) {
$attrrecid="recid";
} else {
if ($table eq "isnm_perf") { # if ISNM
if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later
$attrrecid="perfid";
} else {
$attrrecid="period"; # isnm_perf_sum table