From 72ed095ccb331a5ccc67bd2e149bf193360a9250 Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 7 Apr 2010 14:42:03 +0000 Subject: [PATCH] add tabprune -p support for percentage to delete git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5702 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/tabutils.pm | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 1e6f869cb..04bfb9b85 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -674,7 +674,10 @@ sub tabprune $rc=tabprune_all($table,$cb); } if (defined $NUMBERENTRIES ) { - $rc=tabprune_numberentries($table,$cb,$NUMBERENTRIES); + $rc=tabprune_numberentries($table,$cb,$NUMBERENTRIES,"n"); + } + if (defined $PERCENT) { + $rc=tabprune_numberentries($table,$cb,$PERCENT,"p"); } if (defined $RECID ) { $rc=tabprune_recid($table,$cb,$RECID); @@ -700,12 +703,15 @@ sub tabprune_all { return $rc; } -# prune input number of records for the table TODO +# prune input number of records for the table # if number of entries > number than in the table, then remove all +# this handles the number of records or percentage to delete sub tabprune_numberentries { my $table = shift; my $cb = shift; - my $numberentries = shift; + my $numberentries = shift; # either number of entries or percent to + # remove based on the flag + my $flag = shift; # (n or p flag) my $rc=0; my $tab = xCAT::Table->new($table); unless ($tab) { @@ -738,10 +744,22 @@ sub tabprune_numberentries { $largerid=$rid; } } - #determine recid to delete all entries that come before like the -i flag - my $RECID= $smallrid->{recid} + $numberentries ; + my $RECID; + if ($flag eq "n") { # deleting number of records + #determine recid to delete all entries that come before like the -i flag + $RECID= $smallrid->{recid} + $numberentries ; + } else { # flag must be percentage + #take largest and smallest recid and percentage and determine the recid + # that will remove the requested percentage. If some are missing in the + # middle due to tabedit, we are not worried about it. + + my $totalnumberrids = $largerid->{recid} - $smallrid->{recid} +1; + my $percent = $numberentries / 100; + my $percentage=$totalnumberrids * $percent ; + my $cnt=sprintf( "%d", $percentage ); # round to whole number + $RECID=$smallrid->{recid} + $cnt; # get recid to remove all before + } $rc=tabprune_recid($table,$cb,$RECID); - return $rc; }