Add the support for sorting the output of the xCAT command which list nodes or VM.

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5080 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
wuzhy 2010-01-29 08:23:22 +00:00
parent fd442e74ae
commit e564e4a8d0
4 changed files with 73 additions and 47 deletions

View File

@ -868,7 +868,8 @@ sub handle_response {
#print "printing node\n";
my $nodes=($rsp->{node});
my $node;
foreach $node (@$nodes) {
my @nodelist = sort {$a cmp $b} @$nodes;
foreach $node (@nodelist) {
my $desc=$node->{name}->[0];
if ($node->{errorcode}) {
if (ref($node->{errorcode}) eq 'ARRAY') { foreach my $ecode (@{$node->{errorcode}}) { $xCAT::Client::EXITCODE |= $ecode; } }

View File

@ -430,15 +430,19 @@ sub format_output {
#######################################
# Get longest name for formatting
#######################################
my $nodehash;
my @errmsg;
foreach ( @$values ) {
###################################
# Skip error message
###################################
##############################################
# Skip error message after saving it for last
##############################################
if ( /^#.*: ERROR / ) {
push @errmsg, $_;
next;
}
/[^\,]+,([^\,]+),/;
my $length = length( $1 );
/([^\,]+),([^\,]+),/;
$nodehash->{$1.$2} = $_;
my $length = length( $2 );
$max_length = ($length > $max_length) ? $length : $max_length;
}
my $format = sprintf( "%%-%ds", ($max_length + 2 ));
@ -453,18 +457,10 @@ sub format_output {
#######################################
# Add node information
#######################################
my @errmsg;
foreach ( @$values ) {
my @data = split /,/;
foreach ( sort keys %$nodehash ) {
my @data = split /,/, $nodehash->{$_};
my $i = 0;
###################################
# Save error messages for last
###################################
if ( /^#.*: ERROR / ) {
push @errmsg, $_;
next;
}
foreach ( @header ) {
my $d = $data[$i++];
@ -502,23 +498,29 @@ sub format_stanza {
my $values = shift;
my $result;
my $nodehash;
#####################################
# Skip hardware control point
#####################################
shift(@$values);
foreach ( sort @$values ) {
my @data = split /,/;
foreach ( @$values ) {
###################################
# Skip error message
###################################
if ( /^#.*: ERROR / ) {
next;
}
/[^\,]+,([^\,]+),/;
$nodehash->{$1} = $_;
}
foreach ( sort keys %$nodehash ) {
my @data = split /,/, $nodehash->{$_};
my $type = $data[0];
my $i = 0;
#################################
# Skip error message
#################################
if ( /^#.*: ERROR / ) {
next;
}
#################################
# Node attributes
#################################
@ -565,26 +567,31 @@ sub format_xml {
my $hwtype = shift;
my $values = shift;
my $xml;
my $nodehash;
#####################################
# Skip hardware control point
#####################################
shift(@$values);
foreach ( @$values ) {
###################################
# Skip error message
###################################
if ( /^#.*: ERROR / ) {
next;
}
/[^\,]+,([^\,]+),/;
$nodehash->{$1} = $_;
}
#####################################
# Create XML formatted attributes
#####################################
foreach ( @$values ) {
my @data = split /,/;
foreach ( sort keys %$nodehash ) {
my @data = split /,/, $nodehash->{$_};
my $type = $data[0];
my $i = 0;
#################################
# Skip error message
#################################
if ( /^#.*: ERROR / ) {
next;
}
#################################
# Initialize hash reference
#################################

View File

@ -606,15 +606,26 @@ sub child_response {
$data .= <$rfh>;
}
my $responses = thaw($data);
foreach ( @$responses ) {
#save the nodes that has errors for node status monitoring
if ((exists($_->{errorcode})) && ($_->{errorcode} != 0)) {
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=-1; }
} else {
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=1; }
}
$callback->( $_ );
}
my @nodes;
foreach ( @$responses ) {
my $node = $_->{node}->[0]->{name}->[0];
push (@nodes, $node);
}
foreach ( sort @nodes ) {
my $nodename = $_;
foreach ( @$responses ) {
if ($nodename eq $_->{node}->[0]->{name}->[0]) {
#save the nodes that has errors for node status monitoring
if ((exists($_->{errorcode})) && ($_->{errorcode} != 0)) {
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=-1; }
} else {
if ($errornodes) { $errornodes->{$_->{node}->[0]->{name}->[0]}=1; }
}
$callback->( $_ );
}
}
}
next;
}
#################################
@ -1434,6 +1445,7 @@ sub preprocess_request {
foreach (@$hcps1) {
push @nodes, @{$hcp_hash{$_}{nodes}};
}
@nodes = sort @nodes;
$reqcopy->{node} = \@nodes;
#print "nodes=@nodes\n";
push @requests, $reqcopy;

View File

@ -1353,17 +1353,23 @@ sub nodels
{
my @attribs = ("node");
my @ents = $nodelisttab->getAllAttribs(@attribs);
foreach (@ents)
{
my @nodes;
foreach (@ents) {
if ($_->{node}) {
push @nodes, $_->{node};
}
}
@nodes = sort {$a cmp $b} @nodes;
foreach (@nodes) {
my $rsp;
if ($_->{node})
{
$rsp->{node}->[0]->{name}->[0] = ($_->{node});
#if ($_)
#{
$rsp->{node}->[0]->{name}->[0] = ($_);
# $rsp->{node}->[0]->{data}->[0]->{contents}->[0]="$_->{node} node contents";
# $rsp->{node}->[0]->{data}->[0]->{desc}->[0]="$_->{node} node desc";
$callback->($rsp);
}
#}
}
}
}