2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCscan;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
2007-11-20 18:27:05 +00:00
|
|
|
use Socket;
|
2007-11-16 19:47:00 +00:00
|
|
|
use XML::Simple;
|
2009-07-29 16:09:32 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
2007-11-16 19:47:00 +00:00
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
|
|
|
use xCAT::PPCdb;
|
2008-02-14 19:55:23 +00:00
|
|
|
use xCAT::GlobalDef;
|
2008-04-12 14:53:11 +00:00
|
|
|
use xCAT::Usage;
|
2010-05-12 05:36:35 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-11-20 18:27:05 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##############################################
|
|
|
|
# Globals
|
|
|
|
##############################################
|
|
|
|
my @header = (
|
|
|
|
["type", "%-8s" ],
|
|
|
|
["name", "placeholder" ],
|
|
|
|
["id", "%-8s" ],
|
|
|
|
["type-model", "%-12s" ],
|
|
|
|
["serial-number", "%-15s" ],
|
2010-04-28 10:33:57 +00:00
|
|
|
["side", "%-6s\n" ]);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2009-12-28 08:10:42 +00:00
|
|
|
my @attribs = qw(nodetype node id mtm serial side hcp pprofile parent groups mgt cons);
|
2008-02-15 15:24:37 +00:00
|
|
|
my %nodetype = (
|
|
|
|
fsp => $::NODETYPE_FSP,
|
|
|
|
bpa => $::NODETYPE_BPA,
|
|
|
|
lpar =>"$::NODETYPE_LPAR,$::NODETYPE_OSI"
|
|
|
|
);
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my %opt = ();
|
|
|
|
my $cmd = $request->{command};
|
|
|
|
my $args = $request->{arg};
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
2008-04-16 18:03:41 +00:00
|
|
|
my $usage_string = xCAT::Usage->getUsage($cmd);
|
|
|
|
return( [ $_[0], $usage_string] );
|
2007-11-16 19:47:00 +00:00
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Checks case in GetOptions, allows opts
|
|
|
|
# to be grouped (e.g. -vx), and terminates
|
|
|
|
# at the first unrecognized option.
|
|
|
|
#############################################
|
|
|
|
@ARGV = @$args;
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
Getopt::Long::Configure( "bundling" );
|
|
|
|
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|Verbose u w x z) )){
|
2007-11-16 19:47:00 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for an argument
|
|
|
|
####################################
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Check for mutually-exclusive formatting
|
|
|
|
#############################################
|
|
|
|
if (( exists($opt{x}) + exists($opt{z})) > 1 ) {
|
|
|
|
return( usage() );
|
|
|
|
}
|
2009-11-19 09:48:37 +00:00
|
|
|
#############################################
|
|
|
|
# Check for mutually-exclusive flags
|
|
|
|
#############################################
|
|
|
|
if (( exists($opt{u}) + exists($opt{w})) > 1 ) {
|
|
|
|
return(usage( "Flag -u cannot be used with flag -w"));
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
####################################
|
|
|
|
# No operands - add command name
|
|
|
|
####################################
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:27:05 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns short-hostname given an IP
|
|
|
|
##########################################################################
|
|
|
|
sub getshorthost {
|
|
|
|
|
|
|
|
my $ip = shift;
|
|
|
|
|
2010-05-12 05:36:35 +00:00
|
|
|
my $host = xCAT::NetworkUtils->gethostname($ip);
|
2007-11-20 18:27:05 +00:00
|
|
|
if ( $host and !$! ) {
|
|
|
|
##############################
|
|
|
|
# Get short-hostname
|
|
|
|
##############################
|
|
|
|
if ( $host =~ /([^\.]+)\./ ) {
|
|
|
|
return($1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Failed
|
|
|
|
##################################
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
|
|
|
# Returns I/O bus information
|
|
|
|
##########################################################################
|
|
|
|
sub enumerate {
|
|
|
|
|
|
|
|
my $exp = shift;
|
|
|
|
my $hwtype = @$exp[2];
|
|
|
|
my $server = @$exp[3];
|
|
|
|
my @values = ();
|
|
|
|
my %cage = ();
|
2009-12-28 08:10:42 +00:00
|
|
|
my %hwconn = ();
|
2007-11-20 18:27:05 +00:00
|
|
|
my $Rc;
|
|
|
|
my $filter;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Get hardware control point info
|
|
|
|
#########################################
|
2007-11-20 18:27:05 +00:00
|
|
|
{
|
2007-11-16 19:47:00 +00:00
|
|
|
my $hcp = xCAT::PPCcli::lshmc( $exp );
|
2007-11-20 18:27:05 +00:00
|
|
|
$Rc = shift(@$hcp);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Return error
|
|
|
|
#########################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( @$hcp[0] );
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Success
|
|
|
|
#########################################
|
|
|
|
my ($model,$serial) = split /,/, @$hcp[0];
|
2007-11-20 18:27:05 +00:00
|
|
|
my $id = "";
|
|
|
|
my $prof = "";
|
|
|
|
my $ips = "";
|
|
|
|
my $bpa = "";
|
2009-12-28 08:10:42 +00:00
|
|
|
my $side = "";
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
push @values, join( ",",
|
2009-12-28 08:10:42 +00:00
|
|
|
$hwtype,$server,$id,$model,$serial,$side,$server,$prof,$bpa,$ips );
|
|
|
|
}
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Save hardware connections
|
|
|
|
#########################################
|
|
|
|
$filter = "type_model_serial_num,ipaddr,sp,side";
|
|
|
|
my $conns = xCAT::PPCcli::lssysconn( $exp, "alls", $filter );
|
|
|
|
$Rc = shift(@$conns);
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Return error
|
|
|
|
#########################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( @$conns[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $con ( @$conns ) {
|
|
|
|
my ($mtms,$ipaddr,$sp,$side) = split /,/,$con;
|
|
|
|
my $value = undef;
|
|
|
|
|
|
|
|
if ( $sp =~ /^primary$/ or $side =~ /^a$/ ) {
|
|
|
|
$value = "A";
|
|
|
|
} elsif ($sp =~ /^secondary$/ or $side =~ /^b$/ ) {
|
|
|
|
$value = "B";
|
|
|
|
}
|
|
|
|
|
|
|
|
$hwconn{$ipaddr} = "$mtms,$value";
|
2007-11-20 18:27:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
#########################################
|
|
|
|
# Enumerate frames (IVM has no frame)
|
|
|
|
#########################################
|
|
|
|
if ( $hwtype ne "ivm" ) {
|
2007-11-20 18:27:05 +00:00
|
|
|
$filter = "type_model,serial_num,name,frame_num,ipaddr_a,ipaddr_b";
|
2007-11-16 19:47:00 +00:00
|
|
|
my $frames = xCAT::PPCcli::lssyscfg( $exp, "bpas", $filter );
|
2007-11-20 18:27:05 +00:00
|
|
|
$Rc = shift(@$frames);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Expect error
|
|
|
|
#####################################
|
|
|
|
if ( $Rc == EXPECT_ERROR ) {
|
|
|
|
return( @$frames[0] );
|
|
|
|
}
|
|
|
|
#####################################
|
|
|
|
# CLI error
|
|
|
|
#####################################
|
|
|
|
if ( $Rc == RC_ERROR ) {
|
|
|
|
return( @$frames[0] );
|
|
|
|
}
|
|
|
|
#####################################
|
|
|
|
# If frames found, enumerate cages
|
|
|
|
#####################################
|
|
|
|
if ( $Rc != NR_ERROR ) {
|
2007-11-20 18:27:05 +00:00
|
|
|
$filter = "cage_num,type_model_serial_num";
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-11-20 18:27:05 +00:00
|
|
|
foreach my $val ( @$frames ) {
|
|
|
|
my ($model,$serial) = split /,/, $val;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $mtms = "$model*$serial";
|
|
|
|
|
|
|
|
my $cages = xCAT::PPCcli::lssyscfg($exp,"cage",$mtms,$filter);
|
|
|
|
$Rc = shift(@$cages);
|
|
|
|
|
|
|
|
#############################
|
2008-03-05 18:25:36 +00:00
|
|
|
# Skip...
|
|
|
|
# Frame in bad state
|
2007-11-16 19:47:00 +00:00
|
|
|
#############################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-03-05 18:25:36 +00:00
|
|
|
push @values, "# $mtms: ERROR @$cages[0]";
|
|
|
|
next;
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# Success
|
|
|
|
#############################
|
|
|
|
foreach ( @$cages ) {
|
|
|
|
my ($cageid,$mtms) = split /,/;
|
2007-11-20 18:27:05 +00:00
|
|
|
$cage{$mtms} = "$cageid,$val";
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#########################################
|
|
|
|
# Enumerate CECs
|
|
|
|
#########################################
|
2007-11-20 18:27:05 +00:00
|
|
|
$filter = "name,type_model,serial_num,ipaddr";
|
|
|
|
my $cecs = xCAT::PPCcli::lssyscfg( $exp, "fsps", $filter );
|
2007-11-16 19:47:00 +00:00
|
|
|
$Rc = shift(@$cecs);
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Return error
|
|
|
|
#########################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( @$cecs[0] );
|
|
|
|
}
|
|
|
|
foreach ( @$cecs ) {
|
|
|
|
#####################################
|
|
|
|
# Get CEC information
|
|
|
|
#####################################
|
|
|
|
my ($fsp,$model,$serial,$ips) = split /,/;
|
|
|
|
my $mtms = "$model*$serial";
|
2007-11-20 18:27:05 +00:00
|
|
|
my $cageid = "";
|
|
|
|
my $fname = "";
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Get cage CEC is in
|
|
|
|
#####################################
|
|
|
|
my $frame = $cage{$mtms};
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Save frame information
|
|
|
|
#####################################
|
2007-11-20 18:27:05 +00:00
|
|
|
if ( defined($frame) ) {
|
|
|
|
my ($cage,$model,$serial,$name,$id,$ipa,$ipb) = split /,/, $frame;
|
|
|
|
my $prof = "";
|
|
|
|
my $bpa = "";
|
2007-11-16 19:47:00 +00:00
|
|
|
$cageid = $cage;
|
2007-11-20 18:27:05 +00:00
|
|
|
$fname = $name;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Convert IP-A to short-hostname.
|
|
|
|
# If fails, use user-defined FSP name
|
|
|
|
#######################################
|
|
|
|
my $host = getshorthost( $ipa );
|
|
|
|
if ( defined($host) ) {
|
|
|
|
$fname = $host;
|
|
|
|
}
|
2009-12-28 08:10:42 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Save two sides of BPA seperately
|
|
|
|
#######################################
|
2011-01-26 09:11:39 +00:00
|
|
|
#my $bpastr = join( ",","bpa",$fname,$id,$model,$serial,"A",$server,$prof,$bpa,$ipa);
|
|
|
|
#if ( !grep /^\Q$bpastr\E$/, @values)
|
|
|
|
#{
|
|
|
|
# push @values, join( ",",
|
|
|
|
# "bpa",$fname,$id,$model,$serial,"A",$server,$prof,$bpa,$ipa);
|
|
|
|
#}
|
|
|
|
#$bpastr = join( ",","bpa",$fname,$id,$model,$serial,"B",$server,$prof,$bpa,$ipb);
|
|
|
|
#if ( !grep /^\Q$bpastr\E$/, @values)
|
|
|
|
#{
|
|
|
|
# push @values, join( ",",
|
|
|
|
# "bpa",$fname,$id,$model,$serial,"B",$server,$prof,$bpa,$ipb);
|
|
|
|
#}
|
|
|
|
push @values, join( ",",
|
|
|
|
"frame",$fname,$id,$model,$serial,"",$server,$prof,$bpa,"");
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#####################################
|
|
|
|
# Save CEC information
|
|
|
|
#####################################
|
2007-11-20 18:27:05 +00:00
|
|
|
my $prof = "";
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2007-11-20 18:27:05 +00:00
|
|
|
#######################################
|
|
|
|
# Convert IP to short-hostname.
|
|
|
|
# If fails, use user-defined FSP name
|
|
|
|
#######################################
|
|
|
|
my $host = getshorthost( $ips );
|
|
|
|
if ( defined($host) ) {
|
|
|
|
$fsp = $host;
|
|
|
|
}
|
2009-12-28 08:10:42 +00:00
|
|
|
|
|
|
|
my $mtmss = $hwconn{$ips};
|
|
|
|
my ($mtms,$side) = split /,/, $mtmss;
|
2007-11-16 19:47:00 +00:00
|
|
|
push @values, join( ",",
|
2011-01-26 09:11:39 +00:00
|
|
|
"cec",$fsp,$cageid,$model,$serial,"",$server,$prof,$fname,"" );
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Enumerate LPARs
|
|
|
|
#####################################
|
2007-11-20 18:27:05 +00:00
|
|
|
$filter = "name,lpar_id,default_profile,curr_profile";
|
2007-11-16 19:47:00 +00:00
|
|
|
my $lpars = xCAT::PPCcli::lssyscfg( $exp, "lpar", $mtms, $filter );
|
|
|
|
$Rc = shift(@$lpars);
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Expect error
|
|
|
|
####################################
|
|
|
|
if ( $Rc == EXPECT_ERROR ) {
|
|
|
|
return( @$lpars[0] );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Skip...
|
|
|
|
# CEC could be "Incomplete" state
|
|
|
|
####################################
|
|
|
|
if ( $Rc == RC_ERROR ) {
|
2008-03-05 18:25:36 +00:00
|
|
|
push @values, "# $mtms: ERROR @$lpars[0]";
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# No results found
|
|
|
|
####################################
|
|
|
|
if ( $Rc == NR_ERROR ) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
foreach ( @$lpars ) {
|
|
|
|
my ($name,$lparid,$dprof,$curprof) = split /,/;
|
2009-09-17 05:06:30 +00:00
|
|
|
my $prof = (length($curprof) && ($curprof !~ /^none$/)) ? $curprof : $dprof;
|
2007-11-20 18:27:05 +00:00
|
|
|
my $ips = "";
|
2009-12-28 08:10:42 +00:00
|
|
|
my $port = "";
|
2007-11-16 19:47:00 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Save LPAR information
|
|
|
|
#####################################
|
|
|
|
push @values, join( ",",
|
2009-12-28 08:10:42 +00:00
|
|
|
"lpar",$name,$lparid,$model,$serial,$port,$server,$prof,$fsp,$ips );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return( \@values );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Format responses
|
|
|
|
##########################################################################
|
|
|
|
sub format_output {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $values = shift;
|
|
|
|
my $opt = $request->{opt};
|
|
|
|
my %output = ();
|
2008-02-13 20:57:18 +00:00
|
|
|
my $hwtype = @$exp[2];
|
2007-11-16 19:47:00 +00:00
|
|
|
my $max_length = 0;
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# -w flag for write to xCat database
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt->{w} )) {
|
|
|
|
my $server = @$exp[3];
|
|
|
|
my $uid = @$exp[4];
|
|
|
|
my $pw = @$exp[5];
|
|
|
|
|
2008-03-05 18:25:36 +00:00
|
|
|
#######################################
|
|
|
|
# Strip errors for results
|
|
|
|
#######################################
|
|
|
|
my @val = grep( !/^#.*: ERROR /, @$values );
|
|
|
|
xCAT::PPCdb::add_ppc( $hwtype, \@val );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2009-11-19 09:48:37 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# -u flag for write to xCat database
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt->{u} )) {
|
|
|
|
#######################################
|
|
|
|
# Strip errors for results
|
|
|
|
#######################################
|
|
|
|
my @val = grep( !/^#.*: ERROR /, @$values );
|
2011-01-28 14:31:47 +00:00
|
|
|
$values = xCAT::PPCdb::update_ppc( $hwtype, \@val );
|
2009-11-19 09:48:37 +00:00
|
|
|
if ( exists( $opt->{x} ) or exists( $opt->{z} ))
|
|
|
|
{
|
|
|
|
unshift @$values, "hmc";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
###########################################
|
|
|
|
# -x flag for xml format
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt->{x} )) {
|
2009-11-19 09:48:37 +00:00
|
|
|
$result .= format_xml( $hwtype, $values );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2008-01-04 19:06:02 +00:00
|
|
|
# -z flag for stanza format
|
2007-11-16 19:47:00 +00:00
|
|
|
###########################################
|
|
|
|
elsif ( exists( $opt->{z} )) {
|
2009-11-19 09:48:37 +00:00
|
|
|
$result .= format_stanza( $hwtype, $values );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-11-19 09:48:37 +00:00
|
|
|
$result = sprintf( "#Updated following nodes:\n") if ( exists( $opt->{u}));
|
2007-11-16 19:47:00 +00:00
|
|
|
#######################################
|
|
|
|
# Get longest name for formatting
|
|
|
|
#######################################
|
2010-01-29 08:23:22 +00:00
|
|
|
my $nodehash;
|
|
|
|
my @errmsg;
|
2007-11-16 19:47:00 +00:00
|
|
|
foreach ( @$values ) {
|
2010-01-29 08:23:22 +00:00
|
|
|
##############################################
|
|
|
|
# Skip error message after saving it for last
|
|
|
|
##############################################
|
2008-03-05 18:25:36 +00:00
|
|
|
if ( /^#.*: ERROR / ) {
|
2010-01-29 08:23:22 +00:00
|
|
|
push @errmsg, $_;
|
2008-03-05 18:25:36 +00:00
|
|
|
next;
|
|
|
|
}
|
2010-01-29 08:23:22 +00:00
|
|
|
/([^\,]+),([^\,]+),/;
|
|
|
|
$nodehash->{$1.$2} = $_;
|
|
|
|
my $length = length( $2 );
|
2007-11-16 19:47:00 +00:00
|
|
|
$max_length = ($length > $max_length) ? $length : $max_length;
|
|
|
|
}
|
2007-11-20 18:27:05 +00:00
|
|
|
my $format = sprintf( "%%-%ds", ($max_length + 2 ));
|
2007-11-16 19:47:00 +00:00
|
|
|
$header[1][1] = $format;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Add header
|
|
|
|
#######################################
|
|
|
|
foreach ( @header ) {
|
2007-11-20 18:27:05 +00:00
|
|
|
$result .= sprintf( @$_[1], @$_[0] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#######################################
|
|
|
|
# Add node information
|
|
|
|
#######################################
|
2010-01-29 08:23:22 +00:00
|
|
|
foreach ( sort keys %$nodehash ) {
|
|
|
|
my @data = split /,/, $nodehash->{$_};
|
2007-11-16 19:47:00 +00:00
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
foreach ( @header ) {
|
|
|
|
my $d = $data[$i++];
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Use IPs instead of
|
|
|
|
# hardware control address
|
|
|
|
###############################
|
|
|
|
if ( @$_[0] eq "address" ) {
|
2008-04-16 18:03:41 +00:00
|
|
|
if ( $data[0] !~ /^(hmc|ivm)$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
$d = $data[8];
|
|
|
|
}
|
2007-11-20 18:27:05 +00:00
|
|
|
}
|
|
|
|
$result .= sprintf( @$_[1], $d );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 18:25:36 +00:00
|
|
|
#######################################
|
|
|
|
# Add any error messages
|
|
|
|
#######################################
|
|
|
|
foreach ( @errmsg ) {
|
|
|
|
$result.= "\n$_";
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
$output{data} = [$result];
|
|
|
|
return( [\%output] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-01-04 19:06:02 +00:00
|
|
|
# Stanza formatting
|
2007-11-16 19:47:00 +00:00
|
|
|
##########################################################################
|
2008-01-04 19:06:02 +00:00
|
|
|
sub format_stanza {
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-02-13 20:57:18 +00:00
|
|
|
my $hwtype = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $values = shift;
|
2009-11-19 09:48:37 +00:00
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
my $result;
|
2010-01-29 08:23:22 +00:00
|
|
|
my $nodehash;
|
2008-02-13 20:57:18 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Skip hardware control point
|
|
|
|
#####################################
|
|
|
|
shift(@$values);
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2010-01-29 08:23:22 +00:00
|
|
|
foreach ( @$values ) {
|
|
|
|
###################################
|
|
|
|
# Skip error message
|
|
|
|
###################################
|
|
|
|
if ( /^#.*: ERROR / ) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
/[^\,]+,([^\,]+),/;
|
|
|
|
$nodehash->{$1} = $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( sort keys %$nodehash ) {
|
|
|
|
my @data = split /,/, $nodehash->{$_};
|
2008-02-13 20:57:18 +00:00
|
|
|
my $type = $data[0];
|
2007-11-16 19:47:00 +00:00
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Node attributes
|
|
|
|
#################################
|
|
|
|
$result .= "$data[1]:\n\tobjtype=node\n";
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Add each attribute
|
|
|
|
#################################
|
2008-02-13 20:57:18 +00:00
|
|
|
foreach ( @attribs ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my $d = $data[$i++];
|
|
|
|
|
2008-03-06 20:25:22 +00:00
|
|
|
if ( /^node$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
next;
|
2008-02-13 20:57:18 +00:00
|
|
|
} elsif ( /^nodetype$/ ) {
|
|
|
|
$d = $nodetype{$d};
|
|
|
|
} elsif ( /^groups$/ ) {
|
2008-02-27 16:13:08 +00:00
|
|
|
$d = "$type,all";
|
2008-02-13 20:57:18 +00:00
|
|
|
} elsif ( /^mgt$/ ) {
|
|
|
|
$d = $hwtype;
|
2009-03-30 03:12:53 +00:00
|
|
|
} elsif ( /^cons$/ ) {
|
|
|
|
if ( $type eq "lpar" ) {
|
|
|
|
$d = $hwtype;
|
|
|
|
} else {
|
|
|
|
$d = undef;
|
|
|
|
}
|
|
|
|
|
2008-04-16 18:03:41 +00:00
|
|
|
} elsif ( /^(mtm|serial)$/ ) {
|
2008-02-13 20:57:18 +00:00
|
|
|
if ( $type eq "lpar" ) {
|
|
|
|
$d = undef;
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-02-13 20:57:18 +00:00
|
|
|
$result .= "\t$_=$d\n";
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# XML formatting
|
|
|
|
##########################################################################
|
|
|
|
sub format_xml {
|
|
|
|
|
2008-02-15 15:24:37 +00:00
|
|
|
my $hwtype = shift;
|
2007-11-16 19:47:00 +00:00
|
|
|
my $values = shift;
|
|
|
|
my $xml;
|
2010-01-29 08:23:22 +00:00
|
|
|
my $nodehash;
|
2007-11-16 19:47:00 +00:00
|
|
|
|
2008-02-15 15:24:37 +00:00
|
|
|
#####################################
|
|
|
|
# Skip hardware control point
|
|
|
|
#####################################
|
|
|
|
shift(@$values);
|
|
|
|
|
2010-01-29 08:23:22 +00:00
|
|
|
foreach ( @$values ) {
|
|
|
|
###################################
|
|
|
|
# Skip error message
|
|
|
|
###################################
|
|
|
|
if ( /^#.*: ERROR / ) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
/[^\,]+,([^\,]+),/;
|
|
|
|
$nodehash->{$1} = $_;
|
|
|
|
}
|
2007-11-16 19:47:00 +00:00
|
|
|
#####################################
|
|
|
|
# Create XML formatted attributes
|
|
|
|
#####################################
|
2010-01-29 08:23:22 +00:00
|
|
|
foreach ( sort keys %$nodehash ) {
|
|
|
|
my @data = split /,/, $nodehash->{$_};
|
2008-02-15 15:24:37 +00:00
|
|
|
my $type = $data[0];
|
2007-11-16 19:47:00 +00:00
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Initialize hash reference
|
|
|
|
#################################
|
|
|
|
my $href = {
|
|
|
|
Node => { }
|
|
|
|
};
|
|
|
|
#################################
|
|
|
|
# Add each attribute
|
|
|
|
#################################
|
2008-02-15 15:24:37 +00:00
|
|
|
foreach ( @attribs ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
my $d = $data[$i++];
|
|
|
|
|
2008-03-06 20:25:22 +00:00
|
|
|
if ( /^nodetype$/ ) {
|
2008-02-15 15:24:37 +00:00
|
|
|
$d = $nodetype{$d};
|
|
|
|
} elsif ( /^groups$/ ) {
|
2008-02-27 16:13:08 +00:00
|
|
|
$d = "$type,all";
|
2008-02-15 15:24:37 +00:00
|
|
|
} elsif ( /^mgt$/ ) {
|
|
|
|
$d = $hwtype;
|
2009-03-30 03:12:53 +00:00
|
|
|
} elsif ( /^cons$/ ) {
|
|
|
|
if ( $type eq "lpar" ) {
|
|
|
|
$d = $hwtype;
|
|
|
|
} else {
|
|
|
|
$d = undef;
|
|
|
|
}
|
2008-04-16 18:03:41 +00:00
|
|
|
} elsif ( /^(mtm|serial)$/ ) {
|
2008-02-15 15:24:37 +00:00
|
|
|
if ( $type eq "lpar" ) {
|
|
|
|
$d = undef;
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-15 15:24:37 +00:00
|
|
|
$href->{Node}->{$_} = $d;
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# XML encoding
|
|
|
|
#################################
|
|
|
|
$xml.= XMLout($href,
|
|
|
|
NoAttr => 1,
|
|
|
|
KeyAttr => [],
|
|
|
|
RootName => undef );
|
|
|
|
}
|
|
|
|
return( $xml );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Returns I/O bus information
|
|
|
|
##########################################################################
|
|
|
|
sub rscan {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $dummy = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my $server = @$exp[3];
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Enumerate all the hardware
|
|
|
|
###################################
|
|
|
|
my $values = enumerate( $exp );
|
|
|
|
if ( ref($values) ne 'ARRAY' ) {
|
2008-03-05 18:25:36 +00:00
|
|
|
return( [[$server,$values,1]] );
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
|
|
|
###################################
|
|
|
|
# Success
|
|
|
|
###################################
|
|
|
|
my $result = format_output( $request, $exp, $values );
|
2007-12-06 16:30:43 +00:00
|
|
|
unshift @$result, "FORMATDATA6sK4ci";
|
2007-11-16 19:47:00 +00:00
|
|
|
return( $result );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
2007-12-06 16:30:43 +00:00
|
|
|
|
2008-02-13 20:57:18 +00:00
|
|
|
|
2008-02-14 19:55:23 +00:00
|
|
|
|
2008-02-15 15:24:37 +00:00
|
|
|
|
2008-03-05 18:25:36 +00:00
|
|
|
|
2008-03-06 20:25:22 +00:00
|
|
|
|
2008-03-20 18:32:18 +00:00
|
|
|
|