2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 17:23:08 +00:00
Jarrod Johnson 2d024b5aeb Have xcoll take a try at sorting output groups (#4018)
It isn't natural sort, but in many cases it should work.

Natural sort in perl is a pain or a dependency.
2017-09-27 20:36:30 -05:00

82 lines
2.0 KiB
Perl
Executable File

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
use lib "$::XCATROOT/lib/perl";
#use Data::Dumper;
use xCAT::Client;
use Getopt::Long;
use strict;
my %output;
my %outputhdrs;
my $option;
my $printcount;
my $individual;
GetOptions("n" => \$option,
"i" => \$individual,
"c" => \$printcount);
while (<STDIN>) {
my $node;
my $output;
if (/:/) {
($node, $output) = split /:/, $_, 2;
} else {
$node = "UNKNOWN";
$output = $_;
}
$output =~ s/^ //;
$output{$node} .= $output;
}
my %collated;
unless ($individual) {
foreach (keys %output) {
$collated{ $output{$_} }->{$_} = 1;
}
}
my $nodes;
sub fillerup {
my $response = shift;
if ($response->{data}->[0]) {
$nodes = $response->{data}->[0];
}
}
if ($individual) {
foreach my $node (sort { $a <=> $b or $a cmp $b } keys %output) {
print "====================================\n";
print "$node\n";
print "====================================\n";
print $output{$node};
print "\n";
}
exit(0);
}
foreach my $output (keys %collated) {
$nodes = join(',', sort (keys %{ $collated{$output} }));
my $cmdref = {
noderange => [$nodes],
command => ['rnoderange'],
};
unless ($option) {
xCAT::Client::submit_request($cmdref, \&fillerup);
}
$outputhdrs{$nodes} = $output;
}
foreach my $hdr (sort { $a <=> $b or $a cmp $b } keys %outputhdrs) {
$nodes = $hdr;
my $output = $outputhdrs{$hdr};
print "====================================\n";
print "$nodes\n";
print "====================================\n";
if ($printcount) {
print "Node count = " . scalar(keys %{ $collated{$output} }) . " \n";
print "====================================\n";
}
print $output;
print "\n";
}