2008-06-03 19:09:21 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT_plugin::lsslp;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
use Socket;
|
2008-11-04 16:55:59 +00:00
|
|
|
use POSIX "WNOHANG";
|
2008-06-03 19:09:21 +00:00
|
|
|
use Storable qw(freeze thaw);
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
use IO::Select;
|
|
|
|
use XML::Simple;
|
2009-07-29 16:20:35 +00:00
|
|
|
$XML::Simple::PREFERRED_PARSER='XML::Parser';
|
2008-06-03 19:09:21 +00:00
|
|
|
use xCAT::PPCdb;
|
|
|
|
|
2009-06-02 09:52:10 +00:00
|
|
|
require xCAT::MacMap;
|
|
|
|
require xCAT_plugin::blade;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Constants
|
|
|
|
#######################################
|
|
|
|
use constant {
|
|
|
|
HARDWARE_SERVICE => "service:management-hardware.IBM",
|
|
|
|
SOFTWARE_SERVICE => "service:management-software.IBM",
|
2008-09-10 15:44:45 +00:00
|
|
|
WILDCARD_SERVICE => "service:management-*",
|
|
|
|
P6_SERVICE => "service:management-hardware.IBM",
|
2008-06-03 19:09:21 +00:00
|
|
|
SERVICE_FSP => "cec-service-processor",
|
|
|
|
SERVICE_BPA => "bulk-power-controller",
|
|
|
|
SERVICE_HMC => "hardware-management-console",
|
|
|
|
SERVICE_IVM => "integrated-virtualization-manager",
|
|
|
|
SERVICE_MM => "management-module",
|
|
|
|
SERVICE_RSA => "remote-supervisor-adapter",
|
2008-09-10 15:44:45 +00:00
|
|
|
SERVICE_RSA2 => "remote-supervisor-adapter-2",
|
|
|
|
SLP_CONF => "/usr/local/etc/slp.conf",
|
|
|
|
SLPTOOL => "/usr/local/bin/slptool",
|
2008-06-03 19:09:21 +00:00
|
|
|
TYPE_MM => "MM",
|
|
|
|
TYPE_RSA => "RSA",
|
|
|
|
TYPE_BPA => "BPA",
|
|
|
|
TYPE_HMC => "HMC",
|
|
|
|
TYPE_IVM => "IVM",
|
2008-11-04 16:55:59 +00:00
|
|
|
TYPE_FSP => "FSP",
|
2008-06-03 19:09:21 +00:00
|
|
|
IP_ADDRESSES => 3,
|
|
|
|
TEXT => 0,
|
|
|
|
FORMAT => 1,
|
|
|
|
SUCCESS => 0,
|
|
|
|
RC_ERROR => 1
|
|
|
|
};
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Globals
|
|
|
|
#######################################
|
|
|
|
my %service_slp = (
|
2008-09-10 15:44:45 +00:00
|
|
|
@{[ SERVICE_FSP ]} => TYPE_FSP,
|
|
|
|
@{[ SERVICE_BPA ]} => TYPE_BPA,
|
|
|
|
@{[ SERVICE_HMC ]} => TYPE_HMC,
|
|
|
|
@{[ SERVICE_IVM ]} => TYPE_IVM,
|
|
|
|
@{[ SERVICE_MM ]} => TYPE_MM,
|
2008-11-04 16:55:59 +00:00
|
|
|
@{[ SERVICE_RSA ]} => TYPE_RSA,
|
|
|
|
@{[ SERVICE_RSA2 ]} => TYPE_RSA
|
2008-06-03 19:09:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#######################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# SLP display header
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
|
|
|
my @header = (
|
|
|
|
["device", "%-8s" ],
|
|
|
|
["type-model", "%-12s"],
|
|
|
|
["serial-number", "%-15s"],
|
|
|
|
["ip-addresses", "placeholder"],
|
|
|
|
["hostname", "%s"]
|
|
|
|
);
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Hardware specific SLP attributes
|
|
|
|
#######################################
|
|
|
|
my %exattr = (
|
|
|
|
@{[ SERVICE_FSP ]} => [
|
|
|
|
"bpc-machinetype-model",
|
|
|
|
"bpc-serial-number",
|
|
|
|
"cage-number"
|
|
|
|
],
|
|
|
|
@{[ SERVICE_BPA ]} => [
|
|
|
|
"frame-number"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Power methods
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
|
|
|
my %mgt = (
|
|
|
|
lc(TYPE_FSP) => "hmc",
|
|
|
|
lc(TYPE_HMC) => "hmc",
|
|
|
|
lc(TYPE_MM) => "blade",
|
|
|
|
lc(TYPE_HMC) => "hmc",
|
|
|
|
lc(TYPE_IVM) => "ivm",
|
2008-11-04 16:55:59 +00:00
|
|
|
lc(TYPE_RSA) => "blade"
|
2008-06-03 19:09:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my @attribs = qw(nodetype model serial groups node mgt mpa id);
|
|
|
|
my $verbose = 0;
|
|
|
|
my %ip_addr = ();
|
|
|
|
my %slp_result = ();
|
|
|
|
my %rsp_result = ();
|
|
|
|
my %opt = ();
|
2008-09-10 15:44:45 +00:00
|
|
|
my $maxtries = 1;
|
|
|
|
my $openSLP = 1;
|
|
|
|
my @converge;
|
2008-06-03 19:09:21 +00:00
|
|
|
my $macmap;
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Command handler method from tables
|
|
|
|
##########################################################################
|
|
|
|
sub handled_commands {
|
|
|
|
|
2009-06-02 09:52:10 +00:00
|
|
|
$macmap = xCAT::MacMap->new();
|
2008-06-03 19:09:21 +00:00
|
|
|
return( {lsslp=>"lsslp"} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Invokes the callback with the specified message
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub send_msg {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $ecode = shift;
|
|
|
|
my %output;
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Called from child process - send to parent
|
|
|
|
#################################################
|
|
|
|
if ( exists( $request->{pipe} )) {
|
|
|
|
my $out = $request->{pipe};
|
|
|
|
|
|
|
|
$output{errorcode} = $ecode;
|
|
|
|
$output{data} = \@_;
|
|
|
|
print $out freeze( [\%output] );
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
}
|
|
|
|
#################################################
|
|
|
|
# Called from parent - invoke callback directly
|
|
|
|
#################################################
|
|
|
|
elsif ( exists( $request->{callback} )) {
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
$output{errorcode} = $ecode;
|
|
|
|
$output{data} = \@_;
|
|
|
|
$callback->( \%output );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Parse the command line options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
2008-06-17 17:18:02 +00:00
|
|
|
my $args = $request->{arg};
|
|
|
|
my $cmd = $request->{command};
|
2008-06-03 19:09:21 +00:00
|
|
|
my %services = (
|
|
|
|
HMC => SOFTWARE_SERVICE.":".SERVICE_HMC.":",
|
|
|
|
IVM => SOFTWARE_SERVICE.":".SERVICE_IVM.":",
|
|
|
|
BPA => HARDWARE_SERVICE.":".SERVICE_BPA,
|
|
|
|
FSP => HARDWARE_SERVICE.":".SERVICE_FSP,
|
|
|
|
RSA => HARDWARE_SERVICE.":".SERVICE_RSA.":",
|
2008-11-04 16:55:59 +00:00
|
|
|
MM => HARDWARE_SERVICE.":".SERVICE_MM.":"
|
2008-06-03 19:09:21 +00:00
|
|
|
);
|
|
|
|
#############################################
|
2008-06-17 17:18:02 +00:00
|
|
|
# Responds with usage statement
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
2008-06-17 17:18:02 +00:00
|
|
|
my $usage_string = xCAT::Usage->getUsage($cmd);
|
|
|
|
return( [$_[0], $usage_string] );
|
2008-06-03 19:09:21 +00:00
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# No command-line arguments - use defaults
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# 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" );
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Process command-line flags
|
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
if (!GetOptions( \%opt,
|
2009-07-20 18:46:13 +00:00
|
|
|
qw(h|help V|Verbose v|version i=s x z w r s=s e=s t=s m c u H))) {
|
2008-06-17 17:18:02 +00:00
|
|
|
return( usage() );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Check for switch "-" with no option
|
|
|
|
#############################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
2008-06-17 17:18:02 +00:00
|
|
|
return(usage( "Missing option: -" ));
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Set convergence
|
2008-09-10 15:44:45 +00:00
|
|
|
#############################################
|
|
|
|
if ( exists( $opt{c} )) {
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
#################################
|
|
|
|
# Use values set in slp.conf
|
|
|
|
#################################
|
|
|
|
if ( !defined( $ARGV[0] )) {
|
2008-11-04 16:55:59 +00:00
|
|
|
@converge = (0);
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
#################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Use new values
|
2008-09-10 15:44:45 +00:00
|
|
|
#################################
|
|
|
|
else {
|
|
|
|
@converge = split /,/,$ARGV[0];
|
|
|
|
if ( scalar( @converge ) > 5 ) {
|
|
|
|
return(usage( "Convergence timeouts limited to 5 maximum" ));
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
foreach ( @converge ) {
|
|
|
|
unless ( /^[1-9]{1}$|^[1-9]{1}[0-9]{1,4}$/) {
|
2008-09-10 15:44:45 +00:00
|
|
|
return(usage( "Invalid convergence timeout: $_" ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
#############################################
|
2008-06-03 19:09:21 +00:00
|
|
|
# Check for an argument
|
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
elsif ( defined( $ARGV[0] )) {
|
2008-06-17 17:18:02 +00:00
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Option -V for verbose output
|
|
|
|
#############################################
|
|
|
|
if ( exists( $opt{V} )) {
|
|
|
|
$verbose = 1;
|
|
|
|
}
|
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Check for mutually-exclusive formatting
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
|
|
|
if ( (exists($opt{r}) + exists($opt{x}) + exists($opt{z})) > 1 ) {
|
2008-06-17 17:18:02 +00:00
|
|
|
return( usage() );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( (exists($opt{u}) + exists($opt{H})) > 1 ) {
|
|
|
|
return( usage("Cannot use flags -u and -H together"));
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Command tries
|
2008-09-10 15:44:45 +00:00
|
|
|
#############################################
|
|
|
|
if ( exists( $opt{t} )) {
|
|
|
|
$maxtries = $opt{t};
|
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( $maxtries !~ /^0?[1-9]$/ ) {
|
|
|
|
return( usage( "Invalid command tries (1-9)" ));
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select SLP command
|
2008-09-10 15:44:45 +00:00
|
|
|
#############################################
|
|
|
|
if ( exists( $opt{e} )) {
|
|
|
|
if ( $opt{e} !~ /slptool/ ) {
|
|
|
|
$openSLP = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Check for unsupported service type
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
|
|
|
if ( exists( $opt{s} )) {
|
|
|
|
if ( !exists( $services{$opt{s}} )) {
|
2008-06-17 17:18:02 +00:00
|
|
|
return(usage( "Invalid service: $opt{s}" ));
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
$request->{service} = $services{$opt{s}};
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Validate comma-seperated list of IPs
|
|
|
|
##########################################################################
|
|
|
|
sub validate_ip {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
|
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# Option -i not specified (no IPs specified)
|
|
|
|
###########################################
|
|
|
|
if ( !exists( $opt{i} )) {
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Determine interfaces
|
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
my $ips = $openSLP ?
|
2008-09-10 15:44:45 +00:00
|
|
|
slptool_ifconfig( $request ) : slpquery_ifconfig( $request );
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Command failed
|
|
|
|
#######################################
|
|
|
|
if ( @$ips[0] ) {
|
|
|
|
return( $ips );
|
|
|
|
}
|
|
|
|
return( [0] );
|
|
|
|
}
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Option -i specified - validate entries
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
foreach ( split /,/, $opt{i} ) {
|
|
|
|
my $ip = $_;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
###################################
|
|
|
|
# Length for IPv4 addresses
|
|
|
|
###################################
|
|
|
|
my (@octets) = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
|
|
if ( scalar(@octets) != 4 ) {
|
|
|
|
return( [1,"Invalid IP address: $ip"] );
|
|
|
|
}
|
|
|
|
foreach my $octet ( @octets ) {
|
|
|
|
if (( $octet < 0 ) or ( $octet > 255 )) {
|
2008-06-03 19:09:21 +00:00
|
|
|
return( [1,"Invalid IP address: $ip"] );
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
$ip_addr{$ip} = 1;
|
|
|
|
}
|
|
|
|
return( [0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Verbose mode (-V)
|
|
|
|
##########################################################################
|
|
|
|
sub trace {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $msg = shift;
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$dst) = localtime(time);
|
|
|
|
my $msg = sprintf "%02d:%02d:%02d %5d %s", $hour,$min,$sec,$$,$msg;
|
|
|
|
send_msg( $request, 0, $msg );
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Determine adapters available - slptool always uses adapter IP
|
2008-09-10 15:44:45 +00:00
|
|
|
##########################################################################
|
|
|
|
sub slptool_ifconfig {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $cmd = "ifconfig -a";
|
|
|
|
my $result = `$cmd`;
|
|
|
|
my $mode = "MULTICAST";
|
|
|
|
|
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Display broadcast IPs, but use adapter IP
|
2008-09-10 15:44:45 +00:00
|
|
|
#############################################
|
|
|
|
if ( !exists( $opt{m} )) {
|
|
|
|
$mode = "BROADCAST";
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Error running command
|
|
|
|
#############################################
|
|
|
|
if ( !$result ) {
|
|
|
|
return( [1, "Error running '$cmd': $!"] );
|
|
|
|
}
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, $cmd );
|
|
|
|
trace( $request, "$mode Interfaces:" );
|
|
|
|
}
|
|
|
|
if (xCAT::Utils->isAIX()) {
|
|
|
|
##############################################################
|
|
|
|
# Should look like this for AIX:
|
|
|
|
# en0: flags=4e080863,80<UP,BROADCAST,NOTRAILERS,RUNNING,
|
|
|
|
# SIMPLEX,MULTICAST,GROUPRT,64BIT,PSEG,CHAIN>
|
|
|
|
# inet 30.0.0.1 netmask 0xffffff00 broadcast 30.0.0.255
|
|
|
|
# inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
|
|
|
|
# en1: ...
|
|
|
|
#
|
|
|
|
##############################################################
|
|
|
|
my @adapter = split /\w+\d+:\s+flags=/, $result;
|
|
|
|
foreach ( @adapter ) {
|
|
|
|
if ( !($_ =~ /LOOPBACK/ ) and
|
|
|
|
$_ =~ /UP(,|>)/ and
|
|
|
|
$_ =~ /$mode/ ) {
|
|
|
|
my @ip = split /\n/;
|
|
|
|
foreach ( @ip ) {
|
|
|
|
if ( $mode eq "BROADCAST" ) {
|
|
|
|
if ( $_ =~ /^\s*inet\s+/ and
|
|
|
|
$_ =~ /broadcast\s+(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "\t\t$1\tUP,$mode" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $_ =~ /^\s*inet\s*(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
$ip_addr{$1} = 1;
|
|
|
|
|
|
|
|
if ( exists( $opt{m} )) {
|
|
|
|
trace( $request, "\t\t$1\tUP,$mode" );
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-09-10 15:44:45 +00:00
|
|
|
##############################################################
|
|
|
|
# Should look like this for Linux:
|
|
|
|
# eth0 Link encap:Ethernet HWaddr 00:02:55:7B:06:30
|
|
|
|
# inet addr:9.114.154.193 Bcast:9.114.154.223
|
|
|
|
# inet6 addr: fe80::202:55ff:fe7b:630/64 Scope:Link
|
|
|
|
# UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
|
|
# RX packets:1280982 errors:0 dropped:0 overruns:0 frame:0
|
|
|
|
# TX packets:3535776 errors:0 dropped:0 overruns:0 carrier:0
|
|
|
|
# collisions:0 txqueuelen:1000
|
|
|
|
# RX bytes:343489371 (327.5 MiB) TX bytes:870969610 (830.6 MiB)
|
|
|
|
# Base address:0x2600 Memory:fbfe0000-fc0000080
|
|
|
|
#
|
|
|
|
# eth1 ...
|
|
|
|
#
|
|
|
|
##############################################################
|
|
|
|
my @adapter= split /\n{2,}/, $result;
|
|
|
|
foreach ( @adapter ) {
|
|
|
|
if ( !($_ =~ /LOOPBACK / ) and
|
|
|
|
$_ =~ /UP / and
|
|
|
|
$_ =~ /$mode / ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
my @ip = split /\n/;
|
|
|
|
foreach ( @ip ) {
|
|
|
|
if ( $mode eq "BROADCAST" ) {
|
|
|
|
if ( $_ =~ /^\s*inet addr:/ and
|
|
|
|
$_ =~ /Bcast:(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "\t\t$1\tUP,$mode" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $_ =~ /^\s*inet addr:\s*(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
$ip_addr{$1} = 1;
|
|
|
|
|
|
|
|
if ( exists( $opt{m} )) {
|
|
|
|
trace( $request, "\t\t$1\tUP,$mode" );
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
if ( (keys %ip_addr) == 0 ) {
|
|
|
|
return( [1,"No adapters configured for $mode"] );
|
|
|
|
}
|
|
|
|
#########################
|
|
|
|
# Log results
|
|
|
|
#########################
|
|
|
|
if ( $verbose ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( (keys %ip_addr) == 0 ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
trace( $request, "$cmd\n$result" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
return([0]);
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Determine adapters available - slp_query always used broadcast IP
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
2008-09-10 15:44:45 +00:00
|
|
|
sub slpquery_ifconfig {
|
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $cmd = "ifconfig -a";
|
|
|
|
my $result = `$cmd`;
|
2008-09-10 15:44:45 +00:00
|
|
|
my $mode = "BROADCAST";
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
######################################
|
|
|
|
# Error running command
|
|
|
|
######################################
|
|
|
|
if ( !$result ) {
|
|
|
|
return( [1, "Error running '$cmd': $!"] );
|
|
|
|
}
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, $cmd );
|
2008-09-10 15:44:45 +00:00
|
|
|
trace( $request, "$mode Interfaces:" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
if (xCAT::Utils->isAIX()) {
|
|
|
|
##############################################################
|
|
|
|
# Should look like this for AIX:
|
|
|
|
# en0: flags=4e080863,80<UP,BROADCAST,NOTRAILERS,RUNNING,
|
|
|
|
# SIMPLEX,MULTICAST,GROUPRT,64BIT,PSEG,CHAIN>
|
|
|
|
# inet 30.0.0.1 netmask 0xffffff00 broadcast 30.0.0.255
|
|
|
|
# inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
|
|
|
|
# en1: ...
|
|
|
|
#
|
|
|
|
##############################################################
|
|
|
|
my @adapter = split /\w+\d+:\s+flags=/, $result;
|
|
|
|
foreach ( @adapter ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( !($_ =~ /LOOPBACK/ ) and
|
|
|
|
$_ =~ /UP(,|>)/ and
|
|
|
|
$_ =~ /$mode/ ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
my @ip = split /\n/;
|
2008-09-10 15:44:45 +00:00
|
|
|
foreach ( @ip ) {
|
|
|
|
if ( $_ =~ /^\s*inet\s+/ and
|
2008-06-03 19:09:21 +00:00
|
|
|
$_ =~ /broadcast\s+(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
$ip_addr{$1} = 1;
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
##############################################################
|
|
|
|
# Should look like this for Linux:
|
|
|
|
# eth0 Link encap:Ethernet HWaddr 00:02:55:7B:06:30
|
|
|
|
# inet addr:9.114.154.193 Bcast:9.114.154.223
|
|
|
|
# inet6 addr: fe80::202:55ff:fe7b:630/64 Scope:Link
|
|
|
|
# UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
|
|
# RX packets:1280982 errors:0 dropped:0 overruns:0 frame:0
|
|
|
|
# TX packets:3535776 errors:0 dropped:0 overruns:0 carrier:0
|
|
|
|
# collisions:0 txqueuelen:1000
|
|
|
|
# RX bytes:343489371 (327.5 MiB) TX bytes:870969610 (830.6 MiB)
|
|
|
|
# Base address:0x2600 Memory:fbfe0000-fc0000080
|
|
|
|
#
|
|
|
|
# eth1 ...
|
|
|
|
#
|
|
|
|
##############################################################
|
|
|
|
my @adapter= split /\n{2,}/, $result;
|
|
|
|
foreach ( @adapter ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( !($_ =~ /LOOPBACK / ) and
|
|
|
|
$_ =~ /UP / and
|
|
|
|
$_ =~ /$mode / ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
my @ip = split /\n/;
|
|
|
|
foreach ( @ip ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( $_ =~ /^\s*inet addr:/ and
|
2008-06-03 19:09:21 +00:00
|
|
|
$_ =~ /Bcast:(\d+\.\d+\.\d+\.\d+)/ ) {
|
|
|
|
$ip_addr{$1} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( (keys %ip_addr) == 0 ) {
|
|
|
|
return( [1,"No adapters configured for $mode"] );
|
|
|
|
}
|
|
|
|
#########################
|
|
|
|
# Log results
|
|
|
|
#########################
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
|
|
|
foreach ( keys %ip_addr ) {
|
|
|
|
trace( $request, "\t\t$_\tUP,BROADCAST" );
|
|
|
|
}
|
|
|
|
if ( (keys %ip_addr) == 0 ) {
|
|
|
|
trace( $request, "$cmd\n$result" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return([0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Forks a process to run the slp command (1 per adapter)
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub fork_cmd {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $ip = shift;
|
|
|
|
my $arg = shift;
|
|
|
|
my $services = shift;
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Pipe childs output back to parent
|
|
|
|
#######################################
|
|
|
|
my $parent;
|
|
|
|
my $child;
|
|
|
|
pipe $parent, $child;
|
|
|
|
my $pid = fork;
|
|
|
|
|
|
|
|
if ( !defined($pid) ) {
|
|
|
|
###################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Fork error
|
2008-06-03 19:09:21 +00:00
|
|
|
###################################
|
|
|
|
send_msg( $request, 1, "Fork error: $!" );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
elsif ( $pid == 0 ) {
|
|
|
|
###################################
|
|
|
|
# Child process
|
|
|
|
###################################
|
|
|
|
close( $parent );
|
|
|
|
$request->{pipe} = $child;
|
|
|
|
|
|
|
|
invoke_cmd( $request, $ip, $arg, $services );
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
###################################
|
|
|
|
# Parent process
|
|
|
|
###################################
|
|
|
|
close( $child );
|
|
|
|
return( $parent );
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Run the forked command and send reply to parent
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub invoke_cmd {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $ip = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $services = shift;
|
|
|
|
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Telnet (rspconfig) command
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
|
|
|
if ( !defined( $services )) {
|
2008-09-30 13:45:36 +00:00
|
|
|
my $target_dev = $args->{$ip};
|
|
|
|
my @cmds;
|
|
|
|
my $result;
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
2008-09-30 13:45:36 +00:00
|
|
|
trace( $request, "Forked: ($ip)->($target_dev->{args})" );
|
|
|
|
}
|
|
|
|
if ($target_dev->{'type'} eq 'MM')
|
|
|
|
{
|
|
|
|
@cmds = (
|
|
|
|
"snmpcfg=enable",
|
|
|
|
"sshcfg=enable",
|
|
|
|
"network_reset=$target_dev->{args}"
|
|
|
|
);
|
|
|
|
$result = xCAT_plugin::blade::telnetcmds(
|
|
|
|
$ip,
|
|
|
|
$target_dev->{username},
|
|
|
|
$target_dev->{password},
|
|
|
|
0,
|
|
|
|
@cmds );
|
|
|
|
}
|
|
|
|
elsif($target_dev->{'type'} eq 'HMC')
|
|
|
|
{
|
|
|
|
@cmds = ("network_reset=$target_dev->{args}");
|
|
|
|
trace( $request, "sshcmds on hmc $ip");
|
|
|
|
$result = xCAT::PPC::sshcmds_on_hmc(
|
|
|
|
$ip,
|
|
|
|
$target_dev->{username},
|
|
|
|
$target_dev->{password},
|
|
|
|
@cmds );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
else #The rest must be fsp or bpa
|
|
|
|
{
|
2009-06-02 09:52:10 +00:00
|
|
|
@cmds = ("network=$ip,$target_dev->{args}");
|
2009-01-19 09:06:39 +00:00
|
|
|
trace( $request, "update config on $target_dev->{'type'} $ip");
|
|
|
|
$result = xCAT::PPC::updconf_in_asm(
|
|
|
|
$ip,
|
|
|
|
$target_dev,
|
|
|
|
@cmds );
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
####################################
|
|
|
|
# Pass result array back to parent
|
|
|
|
####################################
|
|
|
|
my @data = ("RSPCONFIG6sK4ci", $ip, @$result[0], @$result[2]);
|
|
|
|
my $out = $request->{pipe};
|
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
print $out freeze( \@data );
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# SLP command
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
my $result = runslp( $args, $ip, $services, $request );
|
2008-06-17 12:58:26 +00:00
|
|
|
my $unicast = @$result[0];
|
|
|
|
my $values = @$result[1];
|
2009-07-23 20:02:39 +00:00
|
|
|
prt_result( $request, $values);
|
2008-06-17 12:58:26 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# May have to send additional unicasts
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
if ( keys (%$unicast) ) {
|
2008-06-17 12:58:26 +00:00
|
|
|
foreach my $url ( keys %$unicast ) {
|
|
|
|
my ($service,$addr) = split "://", $url;
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
####################################
|
|
|
|
# Strip off trailing ",lifetime"
|
|
|
|
####################################
|
|
|
|
$addr =~ s/,*\d*$//;
|
2008-06-17 12:58:26 +00:00
|
|
|
my $sockaddr = inet_aton( $addr );
|
2008-09-10 15:44:45 +00:00
|
|
|
$url =~ s/,*\d*$//;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2008-06-17 12:58:26 +00:00
|
|
|
####################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Make sure can resolve if hostname
|
2008-06-17 12:58:26 +00:00
|
|
|
####################################
|
|
|
|
if ( !defined( $sockaddr )) {
|
|
|
|
if ( $verbose ) {
|
2008-11-04 16:55:59 +00:00
|
|
|
trace( $request, "Cannot convert '$addr' to dot-notation" );
|
2008-06-17 12:58:26 +00:00
|
|
|
}
|
|
|
|
next;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-06-17 12:58:26 +00:00
|
|
|
$addr = inet_ntoa( $sockaddr );
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
####################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select command format
|
2008-09-10 15:44:45 +00:00
|
|
|
####################################
|
|
|
|
if ( $openSLP ) {
|
|
|
|
$result = runslp( $args, $ip, [$url], $request, 1 );
|
|
|
|
} else {
|
|
|
|
$result = runslp( $args, $addr, [$service], $request, 1 );
|
|
|
|
}
|
|
|
|
my $data = @$result[1];
|
|
|
|
my ($attr) = keys %$data;
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Save results
|
|
|
|
####################################
|
|
|
|
if ( defined($attr) ) {
|
|
|
|
$values->{"URL: $url\n$attr\n"} = 1;
|
2009-07-23 20:02:39 +00:00
|
|
|
prt_result( $values);
|
2008-06-17 12:58:26 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# No valid responses received
|
2008-06-17 12:58:26 +00:00
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
if (( keys (%$values )) == 0 ) {
|
2008-06-17 12:58:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Pass result array back to parent
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
|
|
|
my @results = ("FORMATDATA6sK4ci", $values );
|
|
|
|
my $out = $request->{pipe};
|
|
|
|
|
|
|
|
print $out freeze( \@results );
|
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:02:39 +00:00
|
|
|
#########################################################
|
|
|
|
# print the slp result
|
|
|
|
#########################################################
|
|
|
|
sub prt_result
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $values = shift;
|
|
|
|
my $nets = xCAT::Utils::my_nets();
|
|
|
|
for my $v (keys %$values)
|
|
|
|
{
|
|
|
|
if ( $v =~ /ip-address=([^\)]+)/g)
|
|
|
|
{
|
|
|
|
my $iplist = $1;
|
|
|
|
my $ip = getip_from_iplist( $iplist, $nets, $opt{i});
|
|
|
|
if ( $ip)
|
|
|
|
{
|
|
|
|
# send_msg($request, "Received SLP response from $ip.");
|
|
|
|
#print "Received SLP response from $ip.\n";
|
|
|
|
xCAT::MsgUtils->message("I", "Received SLP response from $ip.", $::callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Run the SLP command, process the response, and send to parent
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub runslp {
|
|
|
|
|
|
|
|
my $slpcmd = shift;
|
|
|
|
my $ip = shift;
|
|
|
|
my $services = shift;
|
|
|
|
my $request = shift;
|
2008-09-10 15:44:45 +00:00
|
|
|
my $attreq = shift;
|
2008-06-03 19:09:21 +00:00
|
|
|
my %result = ();
|
|
|
|
my %unicast = ();
|
2008-09-10 15:44:45 +00:00
|
|
|
my $cmd;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
foreach my $type ( @$services ) {
|
|
|
|
my $try = 0;
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# OpenSLP - slptool command
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
|
|
|
if ( $openSLP ) {
|
2008-11-04 16:55:59 +00:00
|
|
|
$cmd = $attreq ?
|
|
|
|
"$slpcmd findattrsusingiflist $ip $type" :
|
2008-09-10 15:44:45 +00:00
|
|
|
"$slpcmd findsrvsusingiflist $ip $type";
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# IBM SLP - slp_query command
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
|
|
|
else {
|
2008-11-04 16:55:59 +00:00
|
|
|
$cmd = $attreq ?
|
|
|
|
"$slpcmd --address=$ip --type=$type" :
|
|
|
|
"$slpcmd --address=$ip --type=$type --converge=1";
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Run the command
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
|
|
|
while ( $try++ < $maxtries ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, $cmd );
|
2008-09-10 15:44:45 +00:00
|
|
|
trace( $request, "Attempt $try of $maxtries\t( $ip\t$type )" );
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Serialize transmits out each adapter
|
2008-09-10 15:44:45 +00:00
|
|
|
#######################################
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( !open( OUTPUT, "$cmd 2>&1 |")) {
|
|
|
|
send_msg( $request, 1, "Fork error: $!" );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
###############################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Get command output
|
2008-06-03 19:09:21 +00:00
|
|
|
###############################
|
|
|
|
my $rsp;
|
|
|
|
while ( <OUTPUT> ) {
|
|
|
|
$rsp.=$_;
|
|
|
|
}
|
|
|
|
close OUTPUT;
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# No replies
|
|
|
|
###############################
|
|
|
|
if ( !$rsp ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( $verbose ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
trace( $request, ">>>>>> No Response" );
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# For IVM, running AIX 53J (6/07) release,
|
2008-11-04 16:55:59 +00:00
|
|
|
# there is an AIX SLP bug where IVM will
|
|
|
|
# respond to SLP service-requests with its
|
2008-09-10 15:44:45 +00:00
|
|
|
# URL only and not its attributes. An SLP
|
2008-11-04 16:55:59 +00:00
|
|
|
# unicast to the URL address is necessary
|
|
|
|
# to acquire the attributes. This was fixed
|
2008-06-03 19:09:21 +00:00
|
|
|
# in AIX 53L (11/07).
|
|
|
|
#
|
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# OpenSLP response format:
|
|
|
|
# service:management-software.IBM...
|
|
|
|
# (type=hardware-management-cons...
|
|
|
|
# (serial-number=KPHHK24),(name=c76v2h...
|
|
|
|
# 1ab1dd89ca8e0763e),(ip-address=192.1...
|
|
|
|
# 0CR3*KPHHK24),(web-management-interf...
|
|
|
|
# 2.ppd.pok.ibm.com:8443),(cimom-port=...
|
|
|
|
# ...
|
|
|
|
###########################################
|
|
|
|
if ( $openSLP ) {
|
|
|
|
my @data = split /\n/,$rsp;
|
|
|
|
my $length = scalar( @data );
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
while ($i < $length ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
###################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# Service-Request response
|
2008-06-03 19:09:21 +00:00
|
|
|
###################################
|
2008-11-04 16:55:59 +00:00
|
|
|
if ( $data[$i] =~
|
2008-09-10 15:44:45 +00:00
|
|
|
/^service\:management-(software|hardware)\.IBM\:([^\:]+)/) {
|
|
|
|
|
|
|
|
###############################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Invalid service-type
|
2008-09-10 15:44:45 +00:00
|
|
|
###############################
|
|
|
|
if ( !exists( $service_slp{$2} )) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "DISCARDING: $data[$i]" );
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
next;
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
my $url = $data[$i++];
|
|
|
|
my $attr = $data[$i];
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
#Give some intermediate output
|
|
|
|
my ($url_ip) = $url =~ /:\/\/(\d+\.\d+\.\d+\.\d+)/;
|
|
|
|
if ( ! $::DISCOVERED_HOST{$url_ip})
|
|
|
|
{
|
|
|
|
$::DISCOVERED_HOST{$url_ip} = 1;
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, ">>>> SrvRqst Response" );
|
|
|
|
trace( $request, "URL: $url" );
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# No "ATTR" - have to unicast
|
|
|
|
###############################
|
|
|
|
if ( $attr !~ /^(\(type=.*)$/ ) {
|
|
|
|
$unicast{$url} = $url;
|
|
|
|
}
|
|
|
|
###############################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Response has "ATTR" field
|
2008-09-10 15:44:45 +00:00
|
|
|
###############################
|
|
|
|
else {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "ATTR: $attr\n" );
|
|
|
|
}
|
|
|
|
my $val = "URL: $url\nATTR: $attr";
|
|
|
|
$result{$val} = 1;
|
|
|
|
$i++;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# Attribute-Request response
|
2008-06-03 19:09:21 +00:00
|
|
|
###################################
|
2008-09-10 15:44:45 +00:00
|
|
|
elsif ( $data[$i] =~ /(\(type=.*)$/ ) {
|
|
|
|
my $attr = "ATTR: $data[$i++]";
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, ">>>> AttrRqst Response" );
|
|
|
|
trace( $request, $attr );
|
|
|
|
}
|
|
|
|
$result{$attr} = 1;
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###################################
|
|
|
|
# Unrecognized response
|
|
|
|
###################################
|
|
|
|
else {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "DISCARDING: $data[$i]" );
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
|
|
|
# IBM SLP response format:
|
|
|
|
# 0
|
|
|
|
# 1
|
|
|
|
# 75
|
|
|
|
# URL: service:management-software.IBM...
|
|
|
|
# ATTR: (type=hardware-management-cons...
|
|
|
|
# (serial-number=KPHHK24),(name=c76v2h...
|
|
|
|
# 1ab1dd89ca8e0763e),(ip-address=192.1...
|
|
|
|
# 0CR3*KPHHK24),(web-management-interf...
|
|
|
|
# 2.ppd.pok.ibm.com:8443),(cimom-port=...
|
|
|
|
#
|
|
|
|
# 0
|
|
|
|
# 1
|
|
|
|
# 69
|
|
|
|
# URL:...
|
|
|
|
# ATTR:..
|
|
|
|
# ..
|
|
|
|
###########################################
|
|
|
|
else {
|
|
|
|
foreach ( split /\n{2,}/,$rsp ) {
|
|
|
|
if ( $_ =~ s/(\d+)\n(\d+)\n(\d+)\n// ) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "SrvRqst Response ($1)($2)($3)" );
|
|
|
|
trace( $request, "$_\n" );
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# Response has "ATTR" field
|
|
|
|
###############################
|
|
|
|
if ( /ATTR: / ) {
|
|
|
|
$result{$_} = 1;
|
|
|
|
}
|
|
|
|
###############################
|
|
|
|
# No "ATTR" - have to unicast
|
|
|
|
###############################
|
|
|
|
elsif ( /.*URL: (.*)/ ) {
|
|
|
|
$unicast{$1} = $1;
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
elsif ( $verbose ) {
|
|
|
|
trace( $request, "DISCARDING: $_" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( [\%unicast,\%result] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Formats slp responses
|
|
|
|
##########################################################################
|
|
|
|
sub format_output {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $values = shift;
|
|
|
|
my $length = length( $header[IP_ADDRESSES][TEXT] );
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Query switch ports
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
my $rsp_targets = undef;
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( $opt{u} or $opt{H})
|
2009-01-19 09:06:39 +00:00
|
|
|
{
|
|
|
|
$rsp_targets = switch_cmd( $request, $values );
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Parse responses and add to hash
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
my $outhash = parse_responses( $request, $values, $rsp_targets, \$length );
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# No responses
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
if (( keys %$outhash ) == 0 ){
|
|
|
|
send_msg( $request, 0, "No responses" );
|
2008-11-04 16:55:59 +00:00
|
|
|
return;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# -w flag for write to xCat database
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt{w} )) {
|
|
|
|
xCATdB( $outhash );
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# -r flag for raw response format
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt{r} )) {
|
|
|
|
foreach ( keys %$outhash ) {
|
|
|
|
$result .= "@{ $outhash->{$_}}[5]\n";
|
|
|
|
}
|
|
|
|
send_msg( $request, 0, $result );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# -x flag for xml format
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt{x} )) {
|
|
|
|
send_msg( $request, 0, format_xml( $outhash ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# -z flag for stanza format
|
|
|
|
###########################################
|
|
|
|
if ( exists( $opt{z} )) {
|
|
|
|
send_msg( $request, 0, format_stanza( $outhash ));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Get longest IP for formatting purposes
|
|
|
|
###########################################
|
|
|
|
my $format = sprintf "%%-%ds", ( $length + 2 );
|
|
|
|
$header[IP_ADDRESSES][FORMAT] = $format;
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Display header
|
|
|
|
###########################################
|
|
|
|
foreach ( @header ) {
|
|
|
|
$result .= sprintf @$_[1], @$_[0];
|
|
|
|
}
|
|
|
|
$result .= "\n";
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Display response attributes
|
|
|
|
###########################################
|
|
|
|
foreach ( sort keys %$outhash ) {
|
|
|
|
my $data = $outhash->{$_};
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
foreach ( @header ) {
|
|
|
|
$result .= sprintf @$_[1], @$data[$i++];
|
|
|
|
}
|
|
|
|
$result .= "\n";
|
|
|
|
}
|
|
|
|
send_msg( $request, 0, $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Get IP from SLP URL response
|
|
|
|
##########################################################################
|
|
|
|
sub getip_from_url {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $url = shift;
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Extract the IP from the URL. Generally, the URL
|
|
|
|
# should be in the following format (the ":0" port number
|
|
|
|
# may or may not be present):
|
|
|
|
# service:management-hardware.IBM:management-module://9.114.113.78:0
|
|
|
|
# service:management-software.IBM:integrated-virtualization-manager://zd21p1.rchland.ibm.com
|
|
|
|
######################################################################
|
|
|
|
if (($url !~ /service:.*:\/\/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/ )) {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
return( $1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Get hostname from SLP URL response
|
|
|
|
##########################################################################
|
|
|
|
sub gethost_from_url {
|
|
|
|
|
|
|
|
my $request = shift;
|
2009-07-27 16:59:24 +00:00
|
|
|
my $rsp = shift;
|
2009-07-23 20:02:39 +00:00
|
|
|
my $type = shift;
|
|
|
|
my $mtm = shift;
|
|
|
|
my $sn = shift;
|
|
|
|
my $iplist = shift;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Extract IP from URL
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
2009-07-23 20:02:39 +00:00
|
|
|
my $nets = xCAT::Utils::my_nets();
|
|
|
|
my $ip = getip_from_iplist( $iplist, $nets, $opt{i});
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( !defined( $ip )) {
|
|
|
|
return undef;
|
|
|
|
}
|
2009-07-27 15:28:11 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
|
|
|
# Check if valid IP
|
|
|
|
#######################################
|
|
|
|
my $packed = inet_aton( $ip );
|
|
|
|
if ( length( $packed ) != 4 ) {
|
|
|
|
if ( $verbose ) {
|
2008-06-17 12:58:26 +00:00
|
|
|
trace( $request, "Invalid IP address in URL: $ip" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
#######################################
|
2009-07-20 18:46:13 +00:00
|
|
|
# Read host from hosts table
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
2009-07-23 20:02:39 +00:00
|
|
|
if ( ! %::HOST_TAB_CACHE)
|
2009-07-20 18:46:13 +00:00
|
|
|
{
|
|
|
|
my $hosttab = xCAT::Table->new( 'hosts' );
|
|
|
|
my @entries = $hosttab->getAllNodeAttribs(['node','ip']);
|
|
|
|
#Assuming IP is unique in hosts table
|
|
|
|
for my $entry ( @entries)
|
|
|
|
{
|
|
|
|
if ( defined $entry->{ 'ip'})
|
|
|
|
{
|
2009-07-23 20:02:39 +00:00
|
|
|
$::HOST_TAB_CACHE{$entry->{ 'ip'}} = $entry->{ 'node'};
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:02:39 +00:00
|
|
|
if ( exists $::HOST_TAB_CACHE{ $ip})
|
2009-07-20 18:46:13 +00:00
|
|
|
{
|
2009-07-23 20:02:39 +00:00
|
|
|
return $::HOST_TAB_CACHE{ $ip} ."($ip)";
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################
|
|
|
|
# Convert IP to hostname (Accoording to DNS or /etc/hosts
|
|
|
|
###############################################################
|
2008-06-03 19:09:21 +00:00
|
|
|
my $host = gethostbyaddr( $packed, AF_INET );
|
|
|
|
if ( !$host or $! ) {
|
2009-07-20 18:46:13 +00:00
|
|
|
#Tentative solution
|
|
|
|
return undef if ($opt{H});
|
2009-07-27 16:59:24 +00:00
|
|
|
$host = getFactoryHostname($type,$mtm,$sn,$rsp);
|
2009-07-23 20:02:39 +00:00
|
|
|
#return( $ip );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-27 15:28:11 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
|
|
|
# Convert hostname to short-hostname
|
|
|
|
#######################################
|
|
|
|
if ( $host =~ /([^\.]+)\./ ) {
|
|
|
|
$host = $1;
|
|
|
|
}
|
2009-07-23 20:02:39 +00:00
|
|
|
return( "$host($ip)" );
|
|
|
|
|
|
|
|
# ###########################################
|
|
|
|
# # Otherwise, URL is not in IP format
|
|
|
|
# ###########################################
|
|
|
|
# if ( !($url =~ /service:.*:\/\/(.*)/ )) {
|
|
|
|
# if ( $verbose ) {
|
|
|
|
# trace( $request, "Invalid URL: $_[0]" );
|
|
|
|
# }
|
|
|
|
# return undef;
|
|
|
|
# }
|
|
|
|
# return( $1 );
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2009-07-23 20:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getFactoryHostname
|
|
|
|
{
|
|
|
|
my $type = shift;
|
|
|
|
my $mtm = shift;
|
|
|
|
my $sn = shift;
|
2009-07-27 16:59:24 +00:00
|
|
|
my $rsp = shift;
|
|
|
|
my $host = undef;
|
2009-07-23 20:02:39 +00:00
|
|
|
|
2009-07-27 16:59:24 +00:00
|
|
|
if ( $rsp =~ /\(name=([^\)]+)/ ) {
|
|
|
|
$host = $1;
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Convert to short-hostname
|
|
|
|
###################################
|
|
|
|
if ( $host =~ /([^\.]+)\./ ) {
|
|
|
|
$host = $1;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-27 16:59:24 +00:00
|
|
|
|
|
|
|
if ( $type eq SERVICE_FSP or $type eq SERVICE_BPA)
|
2009-07-23 20:02:39 +00:00
|
|
|
{
|
2009-07-27 16:59:24 +00:00
|
|
|
$host = "Server-$mtm-SN$sn";
|
2009-07-23 20:02:39 +00:00
|
|
|
}
|
2009-07-27 16:59:24 +00:00
|
|
|
return $host;
|
2009-07-23 20:02:39 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2009-07-23 20:02:39 +00:00
|
|
|
##########################################################################
|
|
|
|
# Get correct IP from ip list in SLP Attr
|
|
|
|
##########################################################################
|
|
|
|
sub getip_from_iplist
|
|
|
|
{
|
|
|
|
my $iplist = shift;
|
|
|
|
my $nets = shift;
|
|
|
|
my $inc = shift;
|
|
|
|
|
|
|
|
my @ips = split /,/, $iplist;
|
|
|
|
if ( $inc)
|
|
|
|
{
|
|
|
|
for my $net (keys %$nets)
|
|
|
|
{
|
|
|
|
delete $nets->{$net} if ( $nets->{$net} ne $inc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $ip (@ips)
|
|
|
|
{
|
|
|
|
for my $net ( keys %$nets)
|
|
|
|
{
|
|
|
|
my ($n,$m) = split /\//,$net;
|
|
|
|
if ( xCAT::Utils::isInSameSubnet( $n, $ip, $m, 1) and
|
|
|
|
xCAT::Utils::isPingable( $ip))
|
|
|
|
{
|
|
|
|
return $ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undef;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Example OpenSLP slptool "service-request" output. The following
|
2008-09-10 15:44:45 +00:00
|
|
|
# attributes can be returned in any order within an SLP response.
|
|
|
|
#
|
|
|
|
# service:management-hardware.IBM:management-module://192.20.154.19,48659
|
|
|
|
# (type=management-module),(level=3),(serial-number= K10WM39916W),
|
|
|
|
# (fru=73P9297 ),(name=WMN315724834),(ip-address=192.20.154.19),
|
|
|
|
# (enclosure-serial-number=78AG034),(enclosure-fru=59P6609 ),
|
|
|
|
# (enclosure-machinetype-model=86772XX),(status=0),(enclosure-uuid=
|
|
|
|
# \ff\e6\4f\0b\41\de\0d\11\d7\bd\be\b5\3c\ab\f0\46\04),
|
|
|
|
# (web-url=http://192.20.154.19:80),(snmp-port=161),(slim-port=6090),
|
|
|
|
# (ssh-port=22),(secure-slim-port=0),(secure-slim-port-enabled=false),
|
|
|
|
# (firmware-image-info=BRET86P:16:01-29-08,BRBR82A:16:06-01-05),
|
|
|
|
# (telnet-port=23),(slot=1),0
|
|
|
|
# ...
|
|
|
|
#
|
2008-11-04 16:55:59 +00:00
|
|
|
# Example OpenSLP slptool "attribute-request" output. The following
|
2008-09-10 15:44:45 +00:00
|
|
|
# attributes can be returned in any order within an SLP response.
|
|
|
|
#
|
|
|
|
# (type=integrated-virtualization-manager),(level=3),(machinetype-model=911051A),
|
|
|
|
# (serial-number=1075ECF),(name=p510ivm.clusters.com)(ip-address=192.168.1.103),
|
|
|
|
# (web-url=http://p510ivm.clusters.com/),(mtms=911051A*1075ECF),
|
|
|
|
# (web-management-interface=TRUE),(secure-web-url=https://p510ivm.clusters.com/),
|
|
|
|
# (cimom-port=5988),(secure-cimom-port=5989),(lparid=1)
|
|
|
|
# ...
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Example IBM SLP slp_query command "service-request" output. The following
|
2008-06-03 19:09:21 +00:00
|
|
|
# attributes can be returned in any order within an SLP response.
|
|
|
|
# Note: The leading 3 numbers preceeding the URL: and ATTR: fields
|
2008-09-10 15:44:45 +00:00
|
|
|
# represent:
|
|
|
|
# error code,
|
|
|
|
# URL count,
|
2008-06-03 19:09:21 +00:00
|
|
|
# URL length, respectively.
|
|
|
|
# 0
|
|
|
|
# 1
|
|
|
|
# 75
|
|
|
|
# URL: service:management-software.IBM:hardware-management-console://192.168.1.110
|
|
|
|
# ATTR: (type=hardware-management-console),(level=3),(machinetype-model=7310CR3),
|
|
|
|
# (serial-number=KPHHK24),(name=c76v2hmc02.ppd.pok.ibm.com),(uuid=de335adf051eb21
|
|
|
|
# 1ab1dd89ca8e0763e),(ip-address=192.168.1.110,9.114.47.154),(web-url=),(mtms=731
|
|
|
|
# 0CR3*KPHHK24),(web-management-interface=true),(secure-web-url=https://c76v2hmc0
|
|
|
|
# 2.ppd.pok.ibm.com:8443),(cimom-port=),(secure-cimom-port=5989)
|
|
|
|
#
|
|
|
|
# 0
|
|
|
|
# 1
|
|
|
|
# 69
|
|
|
|
# ...
|
|
|
|
#
|
2008-09-10 15:44:45 +00:00
|
|
|
# Example IBM SLP slp_query command "attribute-request" output. The following
|
2008-06-03 19:09:21 +00:00
|
|
|
# attributes can be returned in any order within an SLP response.
|
|
|
|
# Note: The leading 3 numbers preceeding the URL: and ATTR: fields
|
|
|
|
# represent:
|
|
|
|
# error code,
|
|
|
|
# 0, (hardcoded)
|
|
|
|
# ATTR length, respectively.
|
|
|
|
# 0
|
|
|
|
# 0
|
|
|
|
# 354
|
|
|
|
# ATTR: (type=integrated-virtualization-manager),(level=3),(machinetype-model=911051A),
|
|
|
|
# (serial-number=1075ECF),(name=p705ivm.clusters.com),(ip-address=192.168.1.103),
|
|
|
|
# (web-url=http://p705ivm.clusters.com/),(mtms=911051A*1075ECF),(web-management-
|
|
|
|
# interface=TRUE),(secure-web-url=https://p705ivm.clusters.com/),(cimom-port=5988),
|
|
|
|
# (secure-cimom-port=5989),(lparid=1)
|
|
|
|
#
|
|
|
|
#########################################################################
|
|
|
|
sub parse_responses {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $values = shift;
|
|
|
|
my $mm = shift;
|
|
|
|
my $length = shift;
|
|
|
|
|
|
|
|
my %outhash = ();
|
2008-09-10 15:44:45 +00:00
|
|
|
my @attrs = (
|
2008-06-03 19:09:21 +00:00
|
|
|
"type",
|
|
|
|
"machinetype-model",
|
|
|
|
"serial-number",
|
|
|
|
"ip-address" );
|
|
|
|
|
2008-09-10 15:44:45 +00:00
|
|
|
#######################################
|
|
|
|
# RSA/MM Attributes
|
|
|
|
#######################################
|
|
|
|
my @xattrs = (
|
|
|
|
"type",
|
|
|
|
"enclosure-machinetype-model",
|
|
|
|
"enclosure-serial-number",
|
|
|
|
"ip-address" );
|
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach my $rsp ( @$values ) {
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Get service-type from response
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
my @result = ();
|
|
|
|
my $host;
|
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# service-type attribute not found
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( $rsp !~ /\(type=([^\)]+)/ ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "(type) attribute not found: $rsp" );
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Valid service-type attribute
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
my $type = $1;
|
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Unsupported service-type
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
if ( !exists($service_slp{$type} )) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "Discarding unsupported type: $type" );
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# RSA/MM - slightly different attributes
|
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
my $attr = \@attrs;
|
2008-11-04 16:55:59 +00:00
|
|
|
if (( $type eq SERVICE_RSA ) or ( $type eq SERVICE_RSA2 ) or
|
2008-09-10 15:44:45 +00:00
|
|
|
( $type eq SERVICE_MM )) {
|
|
|
|
$attr = \@xattrs;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Extract the attributes
|
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
foreach ( @$attr ) {
|
|
|
|
unless ( $rsp =~ /\($_=([^\)]+)/ ) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "Attribute not found: [$_]->($rsp)" );
|
2009-07-23 20:02:39 +00:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
push @result, $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Get host directly from URL
|
|
|
|
###########################################
|
|
|
|
if ( $type eq SERVICE_HMC or $type eq SERVICE_BPA
|
|
|
|
or $type eq SERVICE_FSP) {
|
2009-07-27 16:59:24 +00:00
|
|
|
$host = gethost_from_url( $request, $rsp, @result);
|
2009-07-23 20:02:39 +00:00
|
|
|
if ( !defined( $host )) {
|
2008-09-10 15:44:45 +00:00
|
|
|
next;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# Seperate ATTR and URL portions:
|
|
|
|
# URL: service:management-software.IBM...
|
|
|
|
# ATTR: (type=hardware-management-cons...
|
|
|
|
# (serial-number=KPHHK24),(name=c76v2h...
|
|
|
|
# 1ab1dd89ca8e0763e),(ip-address=192.1...
|
|
|
|
# 0CR3*KPHHK24),(web-management-interf...
|
|
|
|
# 2.ppd.pok.ibm.com:8443),(cimom-port=...
|
|
|
|
#
|
|
|
|
###########################################
|
|
|
|
$rsp =~ /.*URL: (.*)\nATTR: +(.*)/;
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# If MM, use the discovered host
|
|
|
|
###########################################
|
2009-07-23 20:02:39 +00:00
|
|
|
if (!$host and ( $type eq SERVICE_MM ) and ( defined( $mm ))) {
|
2008-06-03 19:09:21 +00:00
|
|
|
my $ip = getip_from_url( $request, $1 );
|
|
|
|
|
|
|
|
if ( defined( $ip )) {
|
|
|
|
if ( exists( $mm->{$ip}->{args} )) {
|
2008-11-04 16:55:59 +00:00
|
|
|
$mm->{$ip}->{args} =~ /^.*,(.*)$/;
|
2008-06-03 19:09:21 +00:00
|
|
|
$host = $1;
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
|
2009-07-23 20:02:39 +00:00
|
|
|
push @result, $host;
|
2008-09-10 15:44:45 +00:00
|
|
|
###################################
|
|
|
|
# Strip off trailing ",lifetime"
|
|
|
|
###################################
|
|
|
|
my $at = $2;
|
|
|
|
$at =~ s/,\d+$//;
|
|
|
|
push @result, $at;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Strip commas from IP list
|
|
|
|
###########################################
|
|
|
|
$result[3] =~ s/,/ /g;
|
|
|
|
my $ip = $result[3];
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Process any extra attributes
|
|
|
|
###########################################
|
|
|
|
foreach ( @{$exattr{$type}} ) {
|
|
|
|
push @result, ($rsp =~ /\($_=([\w\-\.,]+)\)/) ? $1 : "0";
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# Save longest IP for formatting purposes
|
|
|
|
###########################################
|
|
|
|
if ( length( $ip ) > $$length ) {
|
|
|
|
$$length = length( $ip );
|
|
|
|
}
|
|
|
|
$result[0] = $service_slp{$type};
|
|
|
|
$outhash{$host} = \@result;
|
|
|
|
}
|
2009-07-31 19:45:28 +00:00
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# Correct BPA node name because both side
|
|
|
|
# have the same MTMS and may get the same factory name
|
|
|
|
# If there are same factory name for 2 BPA (should be 2 sides
|
|
|
|
# on one frame), change them to like <bpa>_1 and <bpa>_2
|
|
|
|
##########################################################
|
|
|
|
my %hostname_record;
|
|
|
|
for my $h ( keys %outhash)
|
|
|
|
{
|
|
|
|
my ($name, $ip);
|
|
|
|
if ( $h =~ /^([^\(]+)\(([^\)]+)\)$/)
|
|
|
|
{
|
|
|
|
$name = $1;
|
|
|
|
$ip = $2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists $hostname_record{$name})
|
|
|
|
{
|
|
|
|
#Name is duplicated
|
|
|
|
my ($old_h, $old_ip) = @{$hostname_record{$name}};
|
|
|
|
|
|
|
|
$outhash{$old_h}->[4] = $name . "-1" . "($old_ip)";
|
|
|
|
$outhash{$name . "-1" . "($old_ip)"} = $outhash{$old_h};
|
|
|
|
delete $outhash{$old_h};
|
|
|
|
|
|
|
|
$outhash{$h}->[4] = $name . "-2" . "($ip)";
|
|
|
|
$outhash{$name . "-2" . "($ip)"} = $outhash{$h};
|
|
|
|
delete $outhash{$h};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$hostname_record{$name} = [$h,$ip];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
return( \%outhash );
|
|
|
|
}
|
|
|
|
|
2009-07-23 20:02:39 +00:00
|
|
|
##########################################################################
|
|
|
|
# Update /etc/hosts
|
|
|
|
##########################################################################
|
|
|
|
sub updateEtcHosts
|
|
|
|
{
|
|
|
|
my $host_ip = shift;
|
|
|
|
my $fname = "/etc/hosts";
|
|
|
|
unless ( open( HOSTS,"<$fname" )) {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
my @rawdata = <HOSTS>;
|
|
|
|
close( HOSTS );
|
|
|
|
|
|
|
|
######################################
|
|
|
|
# Remove old entry
|
|
|
|
######################################
|
|
|
|
foreach my $host ( keys %$host_ip) {
|
|
|
|
my $ip = $host_ip->{ $host};
|
|
|
|
foreach ( @rawdata ) {
|
|
|
|
if ( /^#/ or /^\s*\n$/ ) {
|
|
|
|
next;
|
|
|
|
} elsif ( /\s+$host\s+$/ ) {
|
|
|
|
s/$_//;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push @rawdata,"$ip\t$host\n";
|
|
|
|
}
|
|
|
|
######################################
|
|
|
|
# Rewrite file
|
|
|
|
######################################
|
|
|
|
unless ( open( HOSTS,">$fname" )) {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
print HOSTS @rawdata;
|
|
|
|
close( HOSTS );
|
|
|
|
return 1;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Write result to xCat database
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub xCATdB {
|
|
|
|
|
|
|
|
my $outhash = shift;
|
|
|
|
my %keyhash = ();
|
|
|
|
my %updates = ();
|
2009-07-20 18:46:13 +00:00
|
|
|
my %sn_node = ();
|
2009-07-23 20:02:39 +00:00
|
|
|
my %host_ip = ();
|
2009-07-20 18:46:13 +00:00
|
|
|
############################
|
|
|
|
# Cache vpd table
|
|
|
|
############################
|
|
|
|
my $vpdtab = undef;
|
|
|
|
$vpdtab = xCAT::Table->new('vpd');
|
|
|
|
if ($vpdtab)
|
|
|
|
{
|
|
|
|
my @ents=$vpdtab->getAllNodeAttribs(['serial','mtm']);
|
|
|
|
for my $ent ( @ents)
|
|
|
|
{
|
|
|
|
if ( $ent->{mtm} and $ent->{serial})
|
|
|
|
{
|
2009-07-31 19:45:28 +00:00
|
|
|
# if there is no BPA, or there is the second BPA, change it
|
|
|
|
if ( ! exists $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} or
|
|
|
|
$sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} =~ /-2$/
|
|
|
|
)
|
|
|
|
{
|
|
|
|
$sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} = $ent->{node};
|
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach ( keys %$outhash ) {
|
|
|
|
my $data = $outhash->{$_};
|
|
|
|
my $type = @$data[0];
|
2009-07-23 20:02:39 +00:00
|
|
|
my $nameips = @$data[4];
|
|
|
|
my ($name,$ips);
|
|
|
|
if ( $nameips =~ /^([^\(]+)\(([^\)]+)\)$/)
|
|
|
|
{
|
|
|
|
$name = $1;
|
|
|
|
$ips = $2;
|
|
|
|
$host_ip{$name} = $ips;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
if ( $type =~ /^BPA$/ ) {
|
|
|
|
my $model = @$data[1];
|
|
|
|
my $serial = @$data[2];
|
2009-07-23 20:02:39 +00:00
|
|
|
$ips = @$data[3] if ( !$ips);
|
|
|
|
$name = @$data[4] if ( !$name);
|
2008-06-03 19:09:21 +00:00
|
|
|
my $id = @$data[6];
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# N/A Values
|
|
|
|
####################################
|
|
|
|
my $prof = "";
|
|
|
|
my $frame = "";
|
|
|
|
|
|
|
|
my $values = join( ",",
|
|
|
|
lc($type),$name,$id,$model,$serial,$name,$prof,$frame,$ips );
|
2009-01-19 09:06:39 +00:00
|
|
|
xCAT::PPCdb::add_ppc( lc($type), [$values] );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
elsif ( $type =~ /^(HMC|IVM)$/ ) {
|
2009-07-27 19:35:44 +00:00
|
|
|
xCAT::PPCdb::add_ppchcp( lc($type), $name );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
elsif ( $type =~ /^FSP$/ ) {
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# BPA frame this CEC is in
|
2008-06-03 19:09:21 +00:00
|
|
|
########################################
|
|
|
|
my $frame = "";
|
|
|
|
my $model = @$data[1];
|
|
|
|
my $serial = @$data[2];
|
2009-07-23 20:02:39 +00:00
|
|
|
$ips = @$data[3] if ( !$ips);
|
|
|
|
$name = @$data[4] if ( !$name);
|
2008-06-03 19:09:21 +00:00
|
|
|
my $bpc_model = @$data[6];
|
|
|
|
my $bpc_serial = @$data[7];
|
|
|
|
my $cageid = @$data[8];
|
|
|
|
|
|
|
|
########################################
|
|
|
|
# May be no Frame with this FSP
|
|
|
|
########################################
|
|
|
|
if (( $bpc_model ne "0" ) and ( $bpc_serial ne "0" )) {
|
2009-07-31 19:45:28 +00:00
|
|
|
if ( exists $sn_node{"Server-$bpc_model-SN$bpc_serial"})
|
2009-07-20 18:46:13 +00:00
|
|
|
{
|
2009-07-31 19:45:28 +00:00
|
|
|
$frame = $sn_node{"Server-$bpc_model-SN$bpc_serial"};
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-27 15:28:11 +00:00
|
|
|
$frame = "Server-$bpc_model-SN$bpc_serial";
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# "Factory-default" FSP name format:
|
2008-06-03 19:09:21 +00:00
|
|
|
# Server-<type>-<model>-<serialnumber>
|
|
|
|
# ie. Server-9117-MMA-SN10F6F3D
|
|
|
|
#
|
|
|
|
# If the IP address cannot be converted
|
|
|
|
# to a shirt-hostname use the following:
|
|
|
|
#
|
|
|
|
# Note that this may not be the name
|
2008-11-04 16:55:59 +00:00
|
|
|
# that the user (or the HMC) knows this
|
2008-06-03 19:09:21 +00:00
|
|
|
# CEC as. This is the "factory-default"
|
|
|
|
# CEC name. SLP does not return the
|
|
|
|
# user- or system-defined CEC name and
|
|
|
|
# FSPs are assigned dynamic hostnames
|
|
|
|
# by DHCP so there is no point in using
|
|
|
|
# the short-hostname as the name.
|
|
|
|
########################################
|
|
|
|
if ( $name =~ /^[\d]{1}/ ) {
|
|
|
|
$name = "Server-$model-$serial";
|
|
|
|
}
|
|
|
|
########################################
|
|
|
|
# N/A Values
|
|
|
|
########################################
|
|
|
|
my $prof = "";
|
|
|
|
my $server = "";
|
|
|
|
|
|
|
|
my $values = join( ",",
|
2009-07-27 15:28:11 +00:00
|
|
|
lc($type),$name,$cageid,$model,$serial,$name,$prof,$frame,$ips );
|
2008-06-03 19:09:21 +00:00
|
|
|
xCAT::PPCdb::add_ppc( "fsp", [$values] );
|
|
|
|
}
|
|
|
|
elsif ( $type =~ /^(RSA|MM)$/ ) {
|
|
|
|
xCAT::PPCdb::add_systemX( $type, $data );
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 20:02:39 +00:00
|
|
|
updateEtcHosts(\%host_ip);
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Stanza formatting
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub format_stanza {
|
|
|
|
|
|
|
|
my $outhash = shift;
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Write attributes
|
|
|
|
#####################################
|
|
|
|
foreach ( keys %$outhash ) {
|
|
|
|
my @data = @{$outhash->{$_}};
|
|
|
|
my $type = lc($data[0]);
|
|
|
|
my $name = $data[4];
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Node attributes
|
|
|
|
#################################
|
|
|
|
$result .= "$name:\n\tobjtype=node\n";
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Add each attribute
|
|
|
|
#################################
|
|
|
|
foreach ( @attribs ) {
|
|
|
|
my $d = $data[$i++];
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( /^node$/ ) {
|
|
|
|
next;
|
|
|
|
} elsif ( /^nodetype$/ ) {
|
|
|
|
$d = $type;
|
|
|
|
} elsif ( /^groups$/ ) {
|
|
|
|
$d = "$type,all";
|
|
|
|
} elsif ( /^mgt$/ ) {
|
|
|
|
$d = $mgt{$type};
|
|
|
|
} elsif ( /^(id|mpa)$/ ) {
|
|
|
|
if ( $type =~ /^(mm|rsa)$/ ) {
|
|
|
|
$d = (/^id$/) ? "0" : $name;
|
|
|
|
} else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$result .= "\t$_=$d\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# XML formatting
|
|
|
|
##########################################################################
|
|
|
|
sub format_xml {
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
my $outhash = shift;
|
|
|
|
my $xml;
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Create XML formatted attributes
|
|
|
|
#####################################
|
|
|
|
foreach ( keys %$outhash ) {
|
|
|
|
my @data = @{ $outhash->{$_}};
|
|
|
|
my $type = lc($data[0]);
|
|
|
|
my $name = $data[4];
|
|
|
|
my $i = 0;
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Initialize hash reference
|
|
|
|
#################################
|
|
|
|
my $href = {
|
|
|
|
Node => { }
|
|
|
|
};
|
|
|
|
#################################
|
|
|
|
# Add each attribute
|
|
|
|
#################################
|
|
|
|
foreach ( @attribs ) {
|
|
|
|
my $d = $data[$i++];
|
|
|
|
|
|
|
|
if ( /^nodetype$/ ) {
|
|
|
|
$d = $type;
|
|
|
|
} elsif ( /^groups$/ ) {
|
|
|
|
$d = "$type,all";
|
|
|
|
} elsif ( /^mgt$/ ) {
|
|
|
|
$d = $mgt{$type};
|
|
|
|
} elsif ( /^(id|mpa)$/ ) {
|
|
|
|
if ( $type =~ /^(mm|rsa)$/ ) {
|
|
|
|
$d = (/^id$/) ? "0" : $name;
|
|
|
|
} else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$href->{Node}->{$_} = $d;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# XML encoding
|
|
|
|
#################################
|
|
|
|
$xml.= XMLout($href,
|
|
|
|
NoAttr => 1,
|
|
|
|
KeyAttr => [],
|
|
|
|
RootName => undef );
|
|
|
|
}
|
|
|
|
return( $xml );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# OpenSLP running on:
|
|
|
|
# P6 FSP
|
|
|
|
# P6 BPA
|
|
|
|
# IBM SLP running on:
|
|
|
|
# P5 FSP
|
|
|
|
# P5 BPA
|
2008-06-03 19:09:21 +00:00
|
|
|
# HMC
|
|
|
|
# MM
|
|
|
|
# RSA
|
|
|
|
# AIX SLP
|
|
|
|
# IVM
|
|
|
|
#
|
2008-09-10 15:44:45 +00:00
|
|
|
# Notes:
|
|
|
|
# IBM SLP requires trailing ':' (i.e. service:management-hardware.IBM:)
|
|
|
|
# There is one exception to this rule when dealing with FSP
|
|
|
|
# concrete" service types, it will work with/without the trailing ':'
|
|
|
|
# (i.e. "service:management-hardware.IBM:cec-service-processor[:]")
|
|
|
|
#
|
|
|
|
# OpenSLP does not support ':' at the end of services
|
|
|
|
# (i.e. service:management-hardware.IBM:). Unfortunately, IBM SLP
|
|
|
|
# requires it.
|
|
|
|
#
|
|
|
|
# Given the above, to collect all the above service types, it is
|
|
|
|
# necessary to multicast:
|
|
|
|
# (1) "service:management-*" for all IBM SLP hardware
|
|
|
|
# (2) "service:management-hardware.IBM" for OpenSLP hardware (P6 FSP/BPA)
|
|
|
|
# (IBM SLP hardware will not respond to this since there is no trailing ":")
|
2008-06-03 19:09:21 +00:00
|
|
|
#
|
2008-09-10 15:44:45 +00:00
|
|
|
# * One exception to the above rule is when using FSP concrete
|
|
|
|
# service type, it will work with/without the trailing ":"
|
|
|
|
# (i.e. "service:management-hardware.IBM:cec-service-processor[:]"
|
2008-06-03 19:09:21 +00:00
|
|
|
#
|
|
|
|
##########################################################################
|
2008-09-10 15:44:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Run IBM SLP version
|
|
|
|
##########################################################################
|
2008-06-03 19:09:21 +00:00
|
|
|
sub slp_query {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = $request->{callback};
|
2008-09-10 15:44:45 +00:00
|
|
|
my $cmd = $opt{e};
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# slp_query not installed
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
if ( !-x $cmd ) {
|
|
|
|
send_msg( $request, 1, "Command not found: $cmd" );
|
2008-06-03 19:09:21 +00:00
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# slp_query runnable - dependent on libstdc++
|
2008-06-03 19:09:21 +00:00
|
|
|
# Test for usage statement.
|
|
|
|
#############################################
|
2008-09-10 15:44:45 +00:00
|
|
|
my $output = `$cmd 2>&1`;
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $output !~ /slp_query --type=service-type-string/ ) {
|
|
|
|
send_msg( $request, 1, $output );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
my $result = runcmd( $request, $cmd );
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Run OpenSLP version
|
|
|
|
##########################################################################
|
|
|
|
sub slptool {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $cmd = SLPTOOL;
|
|
|
|
my $start;
|
|
|
|
|
|
|
|
#########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# slptool not installed
|
2008-09-10 15:44:45 +00:00
|
|
|
#########################################
|
|
|
|
if ( !-x $cmd ) {
|
|
|
|
send_msg( $request, 1, "Command not found: $cmd" );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
#########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# slptool runnable - test for version
|
2008-09-10 15:44:45 +00:00
|
|
|
#########################################
|
|
|
|
my $output = `$cmd -v 2>&1`;
|
|
|
|
if ( $output !~ /^slptool version = 1.2.1\nlibslp version = 1.2.1/ ) {
|
|
|
|
send_msg( $request, 1, "Incorrect 'slptool' command installed" );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
#########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select broadcast, convergence, etc
|
2008-09-10 15:44:45 +00:00
|
|
|
#########################################
|
|
|
|
my $mode = selectmode( $request );
|
|
|
|
if ( defined($mode) ) {
|
|
|
|
return( $mode );
|
|
|
|
}
|
|
|
|
my $result = runcmd( $request, $cmd );
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select OpenSLP slptool broadcast convergence, etc
|
2008-09-10 15:44:45 +00:00
|
|
|
##########################################################################
|
|
|
|
sub selectmode {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $fname = SLP_CONF;
|
|
|
|
my $mode;
|
|
|
|
my $maxtimeout;
|
|
|
|
my $converge;
|
|
|
|
|
|
|
|
##################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select convergence
|
2008-09-10 15:44:45 +00:00
|
|
|
##################################
|
|
|
|
if ( exists( $opt{c} )) {
|
|
|
|
$converge = join( ',',@converge );
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Maximum timeout
|
|
|
|
##############################
|
|
|
|
foreach ( @converge ) {
|
|
|
|
$maxtimeout += $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Select multicast or broadcast
|
2008-09-10 15:44:45 +00:00
|
|
|
##################################
|
|
|
|
if ( !exists( $opt{m} )) {
|
2008-11-04 16:55:59 +00:00
|
|
|
$mode = "true";
|
2008-09-10 15:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# slp.conf attributes
|
2008-09-10 15:44:45 +00:00
|
|
|
##################################
|
|
|
|
my %attr = (
|
|
|
|
"net.slp.multicastTimeouts" => $converge,
|
|
|
|
"net.slp.isBroadcastOnly" => $mode,
|
2008-11-04 16:55:59 +00:00
|
|
|
"net.slp.multicastMaximumWait" => $maxtimeout
|
2008-09-10 15:44:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
my $msg = !defined($mode) ? "Multicasting SLP...":"Broadcasting SLP...";
|
|
|
|
trace( $request, $msg );
|
|
|
|
}
|
|
|
|
##################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Open/read slp.conf
|
2008-09-10 15:44:45 +00:00
|
|
|
##################################
|
|
|
|
unless ( open( CONF, $fname )) {
|
|
|
|
send_msg( $request, 1, "Error opening: '$fname'" );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
my @raw_data = <CONF>;
|
|
|
|
close( CONF );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Find attribute
|
|
|
|
##################################
|
|
|
|
foreach my $name ( keys %attr ) {
|
|
|
|
my $found = 0;
|
|
|
|
|
|
|
|
foreach ( @raw_data ) {
|
|
|
|
if ( /^;*$name\s*=/ ) {
|
|
|
|
if ( !defined( $attr{$name} )) {
|
|
|
|
s/^;*($name\s*=\s*[\w,]+)/;$1/;
|
|
|
|
} elsif ( $attr{$name} == 0 ) {
|
|
|
|
s/^;*($name\s*=\s*[\w,]+)/$1/;
|
|
|
|
} else {
|
|
|
|
s/^;*$name\s*=\s*[\w,]+/$name = $attr{$name}/;
|
|
|
|
}
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !$found ) {
|
|
|
|
send_msg( $request, 1, "'$name' not found in '$fname'" );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Rewrite file contents
|
2008-09-10 15:44:45 +00:00
|
|
|
##################################
|
|
|
|
unless ( open( CONF, "+>$fname" )) {
|
|
|
|
send_msg( $request, 1, "Error opening: '$fname'" );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
print CONF @raw_data;
|
|
|
|
close( CONF );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Run the SLP command
|
2008-09-10 15:44:45 +00:00
|
|
|
##########################################################################
|
|
|
|
sub runcmd {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $cmd = shift;
|
|
|
|
my $services = shift;
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
my @services = ( WILDCARD_SERVICE, P6_SERVICE );
|
|
|
|
my $start;
|
|
|
|
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Query specific service; otherwise,
|
2008-06-03 19:09:21 +00:00
|
|
|
# query all hardware/software services
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( exists( $opt{s} )) {
|
|
|
|
@services = $request->{service};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
#######################################
|
2008-06-03 19:09:21 +00:00
|
|
|
# Write header for trace
|
2008-09-10 15:44:45 +00:00
|
|
|
#######################################
|
2008-06-03 19:09:21 +00:00
|
|
|
my $tm = localtime( time );
|
|
|
|
my $msg = "\n-------- $tm\nTime PID";
|
|
|
|
trace( $request, $msg );
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
# Get/validate broadcast IPs
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
my $result = validate_ip( $request );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
if ( $Rc ) {
|
|
|
|
send_msg( $request, 1, @$result[0] );
|
|
|
|
return( [RC_ERROR] );
|
|
|
|
}
|
|
|
|
if ( $verbose ) {
|
2008-11-04 16:55:59 +00:00
|
|
|
$start = Time::HiRes::gettimeofday();
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Fork one process per adapter
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
my $children = 0;
|
2009-07-20 18:46:13 +00:00
|
|
|
$SIG{CHLD} = sub {
|
|
|
|
my $rc_bak = $?;
|
|
|
|
while (waitpid(-1, WNOHANG) > 0) { $children--; }
|
|
|
|
$? = $rc_bak;
|
|
|
|
};
|
2008-06-03 19:09:21 +00:00
|
|
|
my $fds = new IO::Select;
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach ( keys %ip_addr ) {
|
2008-09-10 15:44:45 +00:00
|
|
|
my $pipe = fork_cmd( $request, $_, $cmd, \@services );
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $pipe ) {
|
|
|
|
$fds->add( $pipe );
|
|
|
|
$children++;
|
|
|
|
}
|
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Process slp responses from children
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
while ( $children > 0 ) {
|
|
|
|
child_response( $callback, $fds );
|
|
|
|
}
|
|
|
|
while (child_response($callback,$fds)) {}
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
my $elapsed = Time::HiRes::gettimeofday() - $start;
|
|
|
|
my $msg = sprintf( "Total SLP Time: %.3f sec\n", $elapsed );
|
2008-11-04 16:55:59 +00:00
|
|
|
trace( $request, $msg );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Combined responses from all children
|
2008-09-10 15:44:45 +00:00
|
|
|
###########################################
|
2008-06-03 19:09:21 +00:00
|
|
|
my @all_results = keys %slp_result;
|
|
|
|
format_output( $request, \@all_results );
|
|
|
|
return( [SUCCESS,\@all_results] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Collect output from the child processes
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub child_response {
|
|
|
|
|
2008-11-04 16:55:59 +00:00
|
|
|
my $callback = shift;
|
2008-06-03 19:09:21 +00:00
|
|
|
my $fds = shift;
|
|
|
|
my @ready_fds = $fds->can_read(1);
|
|
|
|
|
|
|
|
foreach my $rfh (@ready_fds) {
|
2008-06-17 12:58:26 +00:00
|
|
|
my $data = <$rfh>;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
#################################
|
|
|
|
# Read from child process
|
|
|
|
#################################
|
2008-06-17 12:58:26 +00:00
|
|
|
if ( defined( $data )) {
|
2008-06-03 19:09:21 +00:00
|
|
|
while ($data !~ /ENDOFFREEZE6sK4ci/) {
|
|
|
|
$data .= <$rfh>;
|
|
|
|
}
|
|
|
|
my $responses = thaw($data);
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# Formatted SLP results
|
|
|
|
#############################
|
|
|
|
if ( @$responses[0] =~ /^FORMATDATA6sK4ci$/ ) {
|
|
|
|
shift @$responses;
|
|
|
|
foreach ( keys %$responses ) {
|
|
|
|
$slp_result{$_} = 1;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# rspconfig results
|
|
|
|
#############################
|
|
|
|
if ( @$responses[0] =~ /^RSPCONFIG6sK4ci$/ ) {
|
|
|
|
shift @$responses;
|
|
|
|
my $ip = shift(@$responses);
|
|
|
|
|
|
|
|
$rsp_result{$ip} = $responses;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# Message or verbose trace
|
|
|
|
#############################
|
|
|
|
foreach ( @$responses ) {
|
|
|
|
$callback->( $_ );
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Done - close handle
|
2008-06-03 19:09:21 +00:00
|
|
|
#################################
|
|
|
|
$fds->remove($rfh);
|
|
|
|
close($rfh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# Preprocess request from xCat daemon and send request to service nodes
|
|
|
|
#############################################################################
|
|
|
|
sub preprocess_request {
|
|
|
|
|
|
|
|
my $req = shift;
|
2009-07-15 15:13:46 +00:00
|
|
|
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
2008-06-17 17:18:02 +00:00
|
|
|
my $callback=shift;
|
|
|
|
my @requests;
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Prompt for usage if needed
|
|
|
|
####################################
|
|
|
|
my $noderange = $req->{node}; #Should be arrayref
|
|
|
|
my $command = $req->{command}->[0];
|
|
|
|
my $extrargs = $req->{arg};
|
|
|
|
my @exargs=($req->{arg});
|
|
|
|
if (ref($extrargs)) {
|
|
|
|
@exargs=@$extrargs;
|
|
|
|
}
|
|
|
|
my $usage_string=xCAT::Usage->parseCommand($command, @exargs);
|
|
|
|
if ($usage_string) {
|
|
|
|
$callback->({data=>[$usage_string]});
|
|
|
|
$req = {};
|
|
|
|
return;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# find all the service nodes for xCAT cluster
|
|
|
|
# build an individual request for each service node
|
|
|
|
###########################################
|
|
|
|
my %sv_hash=();
|
2009-06-02 09:52:10 +00:00
|
|
|
my @all = xCAT::Utils::getAllSN();
|
|
|
|
foreach (@all) {
|
|
|
|
if ($_->{servicenode}) {$sv_hash{$_->{servicenode}}=1;}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# build each request for each service node
|
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
my @result = ();
|
2008-09-16 15:31:17 +00:00
|
|
|
my $mncopy = {%$req};
|
|
|
|
push @result, $mncopy;
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach my $sn (keys (%sv_hash)) {
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{_xcatdest} = $sn;
|
2009-07-15 15:13:46 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2008-09-10 15:44:45 +00:00
|
|
|
push @result, $reqcopy;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2008-09-10 15:44:45 +00:00
|
|
|
return \@result;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Match SLP IP/ARP MAC/Switch table port to actual switch data
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
|
|
|
sub switch_cmd {
|
|
|
|
|
|
|
|
my $req = shift;
|
|
|
|
my $slp = shift;
|
2009-01-19 09:06:39 +00:00
|
|
|
my $slp_all = undef;
|
2008-06-17 12:58:26 +00:00
|
|
|
my %hosts;
|
|
|
|
my @entries;
|
2008-10-14 07:07:38 +00:00
|
|
|
my $targets = {};
|
2008-06-03 19:09:21 +00:00
|
|
|
my $hosttab = xCAT::Table->new( 'hosts' );
|
|
|
|
my $swtab = xCAT::Table->new( 'switch' );
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# No tables
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
if ( !defined($swtab)) {
|
|
|
|
#if ( !defined($swtab) or !defined($hosttab) ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
# Any MMs/HMCs/FSPs/BPAs in SLP response
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-10-14 07:07:38 +00:00
|
|
|
foreach my $slp_entry ( @$slp ) {
|
2009-01-19 09:06:39 +00:00
|
|
|
my $slp_hash = get_slp_attr( $slp_entry);
|
|
|
|
$slp_all->{$slp_hash->{'ip-address'}} = $slp_hash if ($slp_hash);
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
# No MMs/HMCs/FSPs/BPAs in response
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
if ( !$slp_all ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-30 13:45:36 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-06-17 12:58:26 +00:00
|
|
|
# Any entries in switch table
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
foreach ( $swtab->getAllNodeAttribs([qw(node)]) ) {
|
2008-06-17 12:58:26 +00:00
|
|
|
push @entries, $_->{node};
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2008-06-17 12:58:26 +00:00
|
|
|
# Any entries in hosts table
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
if ( $verbose ) {
|
2008-06-17 12:58:26 +00:00
|
|
|
trace( $req, "SWITCH/HOSTS TABLE:" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( $opt{u})
|
|
|
|
{
|
|
|
|
foreach my $nodename ( @entries ) {
|
|
|
|
my $ent = undef;
|
|
|
|
if ( $hosttab)
|
|
|
|
{
|
|
|
|
my $enthash = $hosttab->getNodeAttribs( $nodename,[qw(ip)]);
|
|
|
|
$ent = $enthash->{ip};
|
|
|
|
}
|
|
|
|
if (!$ent)
|
|
|
|
{
|
|
|
|
my $net_bin = inet_aton($nodename);
|
|
|
|
$ent = inet_ntoa($net_bin) if ($net_bin);
|
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( !$ent ) {
|
|
|
|
next;
|
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
$hosts{ $nodename} = $ent;
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $req, "\t\t($nodename)->($ent)" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# No MMs/HMCs in hosts/switch table
|
|
|
|
###########################################
|
|
|
|
if ( !%hosts ) {
|
|
|
|
return undef;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Ping each MM/HMCs to update arp table
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2009-07-20 18:46:13 +00:00
|
|
|
my %internal_ping_catch;
|
2009-01-19 09:06:39 +00:00
|
|
|
foreach my $ips ( keys %$slp_all ) {
|
|
|
|
my @all_ips = split /,/, $ips;
|
|
|
|
my $rc = 0;
|
|
|
|
for my $single_ip (@all_ips)
|
2008-10-14 07:07:38 +00:00
|
|
|
{
|
2009-07-20 18:46:13 +00:00
|
|
|
my $rc;
|
|
|
|
if ( exists $internal_ping_catch{ $single_ip})
|
|
|
|
{
|
|
|
|
$rc = $internal_ping_catch{ $single_ip};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace ($req, "Trying ping $single_ip");
|
|
|
|
#$rc = system("ping -c 1 -w 1 $single_ip 2>/dev/null 1>/dev/null");
|
|
|
|
my $res = `LANG=C ping -c 1 -w 1 $single_ip 2>&1`;
|
|
|
|
if ( $res =~ /100% packet loss/g)
|
|
|
|
{
|
|
|
|
$rc = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$rc = 0;
|
|
|
|
}
|
|
|
|
#$rc = $?;
|
|
|
|
$internal_ping_catch{ $single_ip} = $rc;
|
|
|
|
}
|
|
|
|
if ( !$rc )
|
2009-01-19 09:06:39 +00:00
|
|
|
{
|
|
|
|
$slp_all->{$single_ip} = $slp_all->{ $ips};
|
|
|
|
delete $slp_all->{ $ips};
|
|
|
|
last;
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
if ( $rc)
|
2008-10-14 07:07:38 +00:00
|
|
|
{
|
2009-01-19 09:06:39 +00:00
|
|
|
trace( $req, "Cannot ping any IP of $ips, it's because the network is too slow?");
|
|
|
|
delete $slp_all->{ $ips};
|
2008-10-14 07:07:38 +00:00
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
|
|
|
# Match discovered IP to MAC in arp table
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
return undef if ( ! scalar( keys %$slp_all));
|
2008-10-14 07:07:38 +00:00
|
|
|
my $arp;
|
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
$arp = `/usr/sbin/arp -a`;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$arp = `/sbin/arp -n`;
|
|
|
|
}
|
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
my @arpents = split /\n/, $arp;
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $req, "ARP TABLE:" );
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
my $isMacFound = 0;
|
|
|
|
foreach my $arpent ( @arpents ) {
|
|
|
|
my ($ip, $mac);
|
|
|
|
if ( $^O eq 'aix' && $arpent =~ /\((\S+)\)\s+at\s+(\S+)/)
|
|
|
|
{
|
|
|
|
($ip, $mac) = ($1,$2);
|
2009-06-02 09:52:10 +00:00
|
|
|
######################################################
|
|
|
|
# Change mac format to be same as linux. For example:
|
|
|
|
# '0:d:60:f4:f8:22' to '00:0d:60:f4:f8:22'
|
|
|
|
######################################################
|
|
|
|
if ( $mac)
|
|
|
|
{
|
|
|
|
my @mac_sections = split /:/, $mac;
|
|
|
|
for (@mac_sections)
|
|
|
|
{
|
|
|
|
$_ = "0$_" if ( length($_) == 1);
|
|
|
|
}
|
|
|
|
$mac = join ':', @mac_sections;
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
}
|
|
|
|
elsif ( $arpent =~ /^(\S+)+\s+\S+\s+(\S+)\s/)
|
|
|
|
{
|
|
|
|
($ip, $mac) = ($1,$2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($ip, $mac) = (undef,undef);
|
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
if ( exists( $slp_all->{$ip} )) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
2008-10-14 07:07:38 +00:00
|
|
|
trace( $req, "\t\t($ip)->($mac)" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
$slp_all->{$ip}->{'mac'} = $mac;
|
2008-10-14 07:07:38 +00:00
|
|
|
$isMacFound = 1;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
###########################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# No discovered IP - MAC matches
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-10-14 07:07:38 +00:00
|
|
|
if ( ! $isMacFound) {
|
2008-06-03 19:09:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $req, "getting switch information...." );
|
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
foreach my $ip ( sort keys %$slp_all ) {
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
|
|
|
# Not in SLP response
|
|
|
|
#######################################
|
2009-01-19 09:06:39 +00:00
|
|
|
if ( !defined( $slp_all->{$ip}->{'mac'} ) or !defined( $macmap )) {
|
2008-06-03 19:09:21 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Get node from switch
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
2009-01-19 09:06:39 +00:00
|
|
|
my $names = $macmap->find_mac( $slp_all->{$ip}->{'mac'} );
|
|
|
|
if ( !defined( $names )) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
2009-01-19 09:06:39 +00:00
|
|
|
trace( $req, "\t\t($slp_all->{$ip}->{'mac'})-> NOT FOUND" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Identify multiple nodes
|
|
|
|
#######################################
|
|
|
|
my $name;
|
|
|
|
if ( $names =~/,/ ) {
|
|
|
|
$name = disti_multi_node( $req, $names, $slp_all->{$ip});
|
|
|
|
if ( ! $name)
|
|
|
|
{
|
2009-07-20 18:46:13 +00:00
|
|
|
trace( $req, "\t\tCannot identify node $ip.");
|
2009-01-19 09:06:39 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$name = $names;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
2009-01-19 09:06:39 +00:00
|
|
|
trace( $req, "\t\t($slp_all->{$ip}->{'mac'})-> $name" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
#######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# In hosts table
|
2008-06-03 19:09:21 +00:00
|
|
|
#######################################
|
2009-07-20 18:46:13 +00:00
|
|
|
if ( $opt{u})
|
|
|
|
{
|
|
|
|
if ( defined( $hosts{$name} )) {
|
|
|
|
if ( $ip eq $hosts{$name} ) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $req, "\t\t\t$slp_all->{$ip}->{'type'} already set '$ip' - skipping" );
|
2008-09-30 13:45:36 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
}
|
2008-06-17 12:58:26 +00:00
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
else
|
2009-01-19 09:06:39 +00:00
|
|
|
{
|
2009-07-20 18:46:13 +00:00
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'args'} = "$hosts{$name},$name";
|
|
|
|
if ( $targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'type'} ne 'MM')
|
|
|
|
{
|
|
|
|
my %netinfo = xCAT::DBobjUtils->getNetwkInfo([$hosts{$name}]);
|
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'args'} .= ",$netinfo{$hosts{$name}}{'gateway'},$netinfo{$hosts{$name}}{'mask'}";
|
|
|
|
}
|
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'mac'} = $slp_all->{$ip}->{'mac'};
|
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'name'} = $name;
|
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'ip'} = $hosts{$name};
|
|
|
|
$targets->{$slp_all->{$ip}->{'type'}}->{$ip}->{'type'} = $slp_all->{$ip}->{'type'};
|
2009-01-19 09:06:39 +00:00
|
|
|
}
|
2008-06-17 12:58:26 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#An tentative solution. The final solution should be
|
|
|
|
#if there is any conflicting, remove this entry
|
|
|
|
$hosts{$name} = $ip if ( ! $hosts{$name});
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
# No rspconfig target found
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2009-07-20 18:46:13 +00:00
|
|
|
if (( $opt{u} and !%$targets) or ( $opt{H} and !%hosts)) {
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $verbose ) {
|
2008-11-04 16:55:59 +00:00
|
|
|
trace( $req, "No ARP-Switch-SLP matches found" );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
2009-07-20 18:46:13 +00:00
|
|
|
return undef;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2009-01-19 09:06:39 +00:00
|
|
|
# Update target hardware w/discovery info
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2009-07-20 18:46:13 +00:00
|
|
|
return rspconfig( $req, $targets ) if ($opt{u});
|
|
|
|
###########################################
|
|
|
|
# Update hosts table
|
|
|
|
###########################################
|
|
|
|
send_msg( $req, 0, "Updating hosts table...");
|
|
|
|
return update_hosts( $req, \%hosts);
|
2008-10-14 07:07:38 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
###########################################
|
|
|
|
# Update hosts table
|
|
|
|
###########################################
|
|
|
|
sub update_hosts
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
my $hosts = shift;
|
|
|
|
my $hoststab = xCAT::Table->new( 'hosts', -create=>1, -autocommit=>0 );
|
|
|
|
if ( !$hoststab)
|
|
|
|
{
|
|
|
|
send_msg( $req, 1, "Cannot open hosts table");
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
for my $node (keys %$hosts)
|
|
|
|
{
|
|
|
|
send_msg( $req, 0, "\t$node => $hosts->{$node}");
|
|
|
|
$hoststab->setNodeAttribs( $node, {ip=>$hosts->{$node}});
|
|
|
|
}
|
|
|
|
$hoststab->commit;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
2009-01-19 09:06:39 +00:00
|
|
|
# Distinguish
|
2008-06-03 19:09:21 +00:00
|
|
|
##########################################################################
|
2009-01-19 09:06:39 +00:00
|
|
|
sub disti_multi_node
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
my $names = shift;
|
|
|
|
my $slp = shift;
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2009-07-20 18:46:13 +00:00
|
|
|
return undef if ( $slp->{'type'} eq 'FSP' and ! exists $slp->{'cage-number'});
|
|
|
|
return undef if ( $slp->{'type'} eq 'BPA' and ! exists $slp->{'frame-number'});
|
2008-06-03 19:09:21 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
my $ppctab = xCAT::Table->new( 'ppc');
|
|
|
|
return undef if ( ! $ppctab);
|
2009-07-20 18:46:13 +00:00
|
|
|
my $nodetypetab = xCAT::Table->new( 'nodetype');
|
|
|
|
return undef if ( ! $nodetypetab);
|
2008-10-14 07:07:38 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
my $vpdtab = xCAT::Table->new( 'vpd');
|
|
|
|
my @nodes = split /,/, $names;
|
|
|
|
my $correct_node = undef;
|
|
|
|
for my $node ( @nodes)
|
2008-09-30 13:45:36 +00:00
|
|
|
{
|
2009-01-19 09:06:39 +00:00
|
|
|
my $id_parent = $ppctab->getNodeAttribs( $node, ['id','parent']);
|
2009-02-24 11:02:34 +00:00
|
|
|
next if (! defined $id_parent or ! exists $id_parent->{'id'});
|
2009-07-20 18:46:13 +00:00
|
|
|
my $nodetype = $nodetypetab->getNodeAttribs($node, ['nodetype']);
|
|
|
|
next if (! defined $nodetype or ! exists $nodetype->{'nodetype'});
|
|
|
|
next if ( $nodetype->{'nodetype'} ne lc($slp->{type}));
|
|
|
|
if ( ($nodetype->{'nodetype'} eq 'fsp' and $id_parent->{'id'} eq $slp->{'cage-number'}) or
|
|
|
|
($nodetype->{'nodetype'} eq 'bpa' and $id_parent->{'id'} eq $slp->{
|
|
|
|
'frame-number'}))
|
2009-01-19 09:06:39 +00:00
|
|
|
{
|
|
|
|
my $vpdnode = undef;
|
2009-02-24 11:02:34 +00:00
|
|
|
if ( defined $id_parent->{ 'parent'})#if no parent defined, take it as is.
|
2009-01-19 09:06:39 +00:00
|
|
|
{
|
2009-02-24 11:02:34 +00:00
|
|
|
if( $vpdtab
|
|
|
|
and $vpdnode = $vpdtab->getNodeAttribs($id_parent->{ 'parent'}, ['serial','mtm'])
|
|
|
|
and exists $vpdnode->{'serial'}
|
|
|
|
and exists $vpdnode->{'mtm'})
|
|
|
|
{
|
|
|
|
if ( $vpdnode->{'serial'} ne $slp->{'bpc-serial-number'}
|
|
|
|
or $vpdnode->{'mtm'} ne $slp->{'bpc-machinetype-model'})
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( "$slp->{'bpc-machinetype-model'}*$slp->{'bpc-serial-number'}" ne $id_parent->{ 'parent'})
|
|
|
|
{
|
2009-01-19 09:06:39 +00:00
|
|
|
next;
|
2009-02-24 11:02:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 13:45:36 +00:00
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
return undef if ( $correct_node);#had matched another node before
|
|
|
|
$correct_node = $node;
|
2008-09-30 13:45:36 +00:00
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
}
|
|
|
|
return $correct_node;
|
|
|
|
}
|
|
|
|
##########################################################################
|
|
|
|
# Run rspconfig against targets
|
|
|
|
##########################################################################
|
|
|
|
sub get_slp_attr
|
|
|
|
{
|
|
|
|
my $slp_entry = shift;
|
|
|
|
my $slp_hash = undef;
|
2008-09-30 13:45:36 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
$slp_entry =~ s/^[^\(]*?\((.*)\)[^\)]*?$/$1/;
|
|
|
|
|
|
|
|
my @entries = split /\),\(/, $slp_entry;
|
|
|
|
for my $entry ( @entries)
|
|
|
|
{
|
|
|
|
if ( $entry =~ /^(.+?)=(.*)$/)
|
|
|
|
{
|
|
|
|
$slp_hash->{$1} = $2;
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-19 09:06:39 +00:00
|
|
|
|
|
|
|
if ( $slp_hash->{'type'})
|
2008-09-30 13:45:36 +00:00
|
|
|
{
|
2009-01-19 09:06:39 +00:00
|
|
|
$slp_hash->{'type'} = 'MM' if ($slp_hash->{'type'} eq SERVICE_MM);
|
|
|
|
$slp_hash->{'type'} = 'FSP' if ($slp_hash->{'type'} eq SERVICE_FSP);
|
|
|
|
$slp_hash->{'type'} = 'BPA' if ($slp_hash->{'type'} eq SERVICE_BPA);
|
|
|
|
$slp_hash->{'type'} = 'HMC' if ($slp_hash->{'type'} eq SERVICE_HMC);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $slp_hash;
|
|
|
|
}
|
2008-09-30 13:45:36 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
##########################################################################
|
|
|
|
# Run rspconfig against targets
|
|
|
|
##########################################################################
|
|
|
|
sub rspconfig {
|
2008-09-30 13:45:36 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $targets = shift;
|
|
|
|
my $callback = $request->{callback};
|
|
|
|
my $start = Time::HiRes::gettimeofday();
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
my %rsp_dev = get_rsp_dev( $request, $targets);
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Fork one process per MM/HMC
|
2008-06-03 19:09:21 +00:00
|
|
|
#############################################
|
|
|
|
my $children = 0;
|
|
|
|
$SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) { $children--; } };
|
|
|
|
my $fds = new IO::Select;
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-10-14 07:07:38 +00:00
|
|
|
foreach my $ip ( keys %rsp_dev) {
|
|
|
|
my $pipe = fork_cmd( $request, $ip, \%rsp_dev);
|
2008-06-03 19:09:21 +00:00
|
|
|
if ( $pipe ) {
|
|
|
|
$fds->add( $pipe );
|
|
|
|
$children++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Process responses from children
|
|
|
|
#############################################
|
|
|
|
while ( $children > 0 ) {
|
|
|
|
child_response( $callback, $fds );
|
|
|
|
}
|
|
|
|
while (child_response($callback,$fds)) {}
|
|
|
|
|
|
|
|
if ( $verbose ) {
|
|
|
|
my $elapsed = Time::HiRes::gettimeofday() - $start;
|
|
|
|
my $msg = sprintf( "Total rspconfig Time: %.3f sec\n", $elapsed );
|
|
|
|
trace( $request, $msg );
|
|
|
|
}
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach my $ip ( keys %rsp_result ) {
|
|
|
|
#################################
|
|
|
|
# Error logging on to MM
|
|
|
|
#################################
|
|
|
|
my $result = $rsp_result{$ip};
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
#############################
|
|
|
|
# MM connect error
|
|
|
|
#############################
|
|
|
|
if ( ref(@$result[0]) ne 'ARRAY' ) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "$ip: @$result[0]" );
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
delete $rsp_dev{$ip};
|
2008-06-03 19:09:21 +00:00
|
|
|
next;
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
##################################
|
|
|
|
# Process each response
|
|
|
|
##################################
|
|
|
|
foreach ( @{@$result[0]} ) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "$ip: $_" );
|
|
|
|
}
|
|
|
|
/^(\S+)\s+(\d+)/;
|
|
|
|
my $cmd = $1;
|
|
|
|
$Rc = $2;
|
|
|
|
|
|
|
|
if ( $cmd =~ /^network_reset/ ) {
|
|
|
|
if ( $Rc != SUCCESS ) {
|
2008-10-14 07:07:38 +00:00
|
|
|
delete $rsp_dev{$ip};
|
2008-06-03 19:09:21 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request,"Resetting management-module ($ip)...." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Update etc/hosts
|
2008-06-03 19:09:21 +00:00
|
|
|
######################################
|
|
|
|
my $fname = "/etc/hosts";
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "updating /etc/hosts...." );
|
|
|
|
}
|
|
|
|
unless ( open( HOSTS,"<$fname" )) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "Error opening '$fname'" );
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
return( \%rsp_dev );
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
my @rawdata = <HOSTS>;
|
|
|
|
close( HOSTS );
|
|
|
|
|
|
|
|
######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Remove old entry
|
2008-06-03 19:09:21 +00:00
|
|
|
######################################
|
2008-10-14 07:07:38 +00:00
|
|
|
foreach ( keys %rsp_dev) {
|
|
|
|
my ($ip,$host) = split /,/,$rsp_dev{$_}->{args};
|
2008-06-03 19:09:21 +00:00
|
|
|
foreach ( @rawdata ) {
|
|
|
|
if ( /^#/ or /^\s*\n$/ ) {
|
|
|
|
next;
|
|
|
|
} elsif ( /\s+$host\s+$/ ) {
|
|
|
|
s/$_//;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push @rawdata,"$ip\t$host\n";
|
|
|
|
}
|
|
|
|
######################################
|
2008-11-04 16:55:59 +00:00
|
|
|
# Rewrite file
|
2008-06-03 19:09:21 +00:00
|
|
|
######################################
|
|
|
|
unless ( open( HOSTS,">$fname" )) {
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "Error opening '$fname'" );
|
|
|
|
}
|
2008-10-14 07:07:38 +00:00
|
|
|
return( \%rsp_dev );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
print HOSTS @rawdata;
|
|
|
|
close( HOSTS );
|
2008-10-14 07:07:38 +00:00
|
|
|
return( \%rsp_dev );
|
2008-06-03 19:09:21 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 09:06:39 +00:00
|
|
|
#############################################
|
|
|
|
# Get rsp devices and their logon info
|
|
|
|
#############################################
|
|
|
|
sub get_rsp_dev
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $targets = shift;
|
|
|
|
|
|
|
|
my $mm = $targets->{'MM'} ? $targets->{'MM'} : {};
|
|
|
|
my $hmc = $targets->{'HMC'} ? $targets->{'HMC'}: {};
|
|
|
|
my $fsp = $targets->{'FSP'} ? $targets->{'FSP'}: {};
|
|
|
|
my $bpa = $targets->{'BPA'} ? $targets->{'BPA'}: {};
|
|
|
|
|
|
|
|
if (%$mm)
|
|
|
|
{
|
|
|
|
my $bladeuser = 'USERID';
|
|
|
|
my $bladepass = 'PASSW0RD';
|
|
|
|
if ( $verbose ) {
|
|
|
|
trace( $request, "telneting to management-modules....." );
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Check passwd table for userid/password
|
|
|
|
#############################################
|
|
|
|
my $passtab = xCAT::Table->new('passwd');
|
|
|
|
if ( $passtab ) {
|
|
|
|
my ($ent) = $passtab->getAttribs({key=>'blade'},'username','password');
|
|
|
|
if ( defined( $ent )) {
|
|
|
|
$bladeuser = $ent->{username};
|
|
|
|
$bladepass = $ent->{password};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Get MM userid/password
|
|
|
|
#############################################
|
|
|
|
my $mpatab = xCAT::Table->new('mpa');
|
|
|
|
foreach ( keys %$mm ) {
|
|
|
|
my $user = $bladeuser;
|
|
|
|
my $pass = $bladepass;
|
|
|
|
|
|
|
|
if ( defined( $mpatab )) {
|
|
|
|
my ($ent) = $mpatab->getAttribs({mpa=>$_},'username','password');
|
|
|
|
if ( defined( $ent->{password} )) { $pass = $ent->{password}; }
|
|
|
|
if ( defined( $ent->{username} )) { $user = $ent->{username}; }
|
|
|
|
}
|
|
|
|
$mm->{$_}->{username} = $user;
|
|
|
|
$mm->{$_}->{password} = $pass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (%$hmc )
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get HMC userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$hmc ) {
|
|
|
|
( $hmc->{$_}->{username}, $hmc->{$_}->{password}) = xCAT::PPCdb::credentials( $_, lc($hmc->{$_}->{'type'}));
|
|
|
|
trace( $request, "user/passwd for $_ is $hmc->{$_}->{username} $hmc->{$_}->{password}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( %$fsp)
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get FSP userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$fsp ) {
|
|
|
|
( $fsp->{$_}->{username}, $fsp->{$_}->{password}) = xCAT::PPCdb::credentials( $_, lc($fsp->{$_}->{'type'}));
|
|
|
|
trace( $request, "user/passwd for $_ is $fsp->{$_}->{username} $fsp->{$_}->{password}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( %$bpa)
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get BPA userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$bpa ) {
|
|
|
|
( $bpa->{$_}->{username}, $bpa->{$_}->{password}) = xCAT::PPCdb::credentials( $_, lc($bpa->{$_}->{'type'}));
|
|
|
|
trace( $request, "user/passwd for $_ is $bpa->{$_}->{username} $bpa->{$_}->{password}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (%$mm,%$hmc,%$fsp,%$bpa);
|
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Process request from xCat daemon
|
|
|
|
##########################################################################
|
|
|
|
sub process_request {
|
|
|
|
|
|
|
|
my $req = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Build hash to pass around
|
|
|
|
###########################################
|
|
|
|
my %request;
|
|
|
|
$request{arg} = $req->{arg};
|
|
|
|
$request{callback} = $callback;
|
2008-06-17 17:18:02 +00:00
|
|
|
$request{command} = $req->{command}->[0];
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Process command-specific options
|
|
|
|
####################################
|
|
|
|
my $result = parse_args( \%request );
|
2008-11-04 16:55:59 +00:00
|
|
|
|
2008-06-17 17:18:02 +00:00
|
|
|
####################################
|
|
|
|
# Return error
|
|
|
|
####################################
|
|
|
|
if ( ref($result) eq 'ARRAY' ) {
|
|
|
|
send_msg( \%request, 1, @$result );
|
|
|
|
return(1);
|
2008-11-04 16:55:59 +00:00
|
|
|
}
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
# SLP service-request - select program
|
2008-06-03 19:09:21 +00:00
|
|
|
###########################################
|
2008-09-10 15:44:45 +00:00
|
|
|
$result = $openSLP ? slptool( \%request ) : slp_query( \%request );
|
|
|
|
my $Rc = shift(@$result);
|
2008-06-03 19:09:21 +00:00
|
|
|
|
|
|
|
return( $Rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-17 12:58:26 +00:00
|
|
|
|
2008-06-17 17:18:02 +00:00
|
|
|
|