2008-05-27 13:53:53 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPCcfg;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
|
2012-08-11 11:06:49 +00:00
|
|
|
use xCAT::PPCfsp;
|
2008-05-27 13:53:53 +00:00
|
|
|
use xCAT::Usage;
|
2012-06-18 05:36:15 +00:00
|
|
|
use Storable qw(freeze thaw);
|
2012-04-06 03:33:56 +00:00
|
|
|
use POSIX "WNOHANG";
|
2012-08-09 03:48:50 +00:00
|
|
|
use xCAT::NetworkUtils;
|
2012-06-21 09:43:16 +00:00
|
|
|
use xCAT::MsgUtils qw(verbose_message);
|
2008-05-27 13:53:53 +00:00
|
|
|
|
2012-07-12 08:51:22 +00:00
|
|
|
use LWP;
|
|
|
|
use HTTP::Cookies;
|
2008-05-27 13:53:53 +00:00
|
|
|
##########################################
|
|
|
|
# Globals
|
|
|
|
##########################################
|
|
|
|
my %rspconfig = (
|
2009-09-02 16:25:46 +00:00
|
|
|
sshcfg => \&sshcfg,
|
2010-03-04 09:38:44 +00:00
|
|
|
frame => \&frame,
|
|
|
|
hostname => \&hostname
|
2008-05-27 13:53:53 +00:00
|
|
|
);
|
|
|
|
|
2012-04-06 03:33:56 +00:00
|
|
|
my %rsp_result;
|
2012-07-01 03:11:25 +00:00
|
|
|
my $start;
|
2008-05-27 13:53:53 +00:00
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $command = $request->{command};
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my %opt = ();
|
|
|
|
my %cmds = ();
|
|
|
|
my @fsp = (
|
|
|
|
"memdecfg",
|
|
|
|
"decfg",
|
|
|
|
"procdecfg",
|
|
|
|
"iocap",
|
|
|
|
"time",
|
|
|
|
"date",
|
|
|
|
"autopower",
|
|
|
|
"sysdump",
|
2009-01-19 08:58:29 +00:00
|
|
|
"spdump",
|
2009-12-29 11:42:49 +00:00
|
|
|
"network",
|
|
|
|
"HMC_passwd",
|
|
|
|
"admin_passwd",
|
2010-03-04 09:38:44 +00:00
|
|
|
"general_passwd",
|
|
|
|
"*_passwd",
|
2011-05-23 10:09:14 +00:00
|
|
|
"hostname",
|
|
|
|
"resetnet",
|
2011-06-17 07:29:17 +00:00
|
|
|
"dev",
|
|
|
|
"celogin1"
|
2009-01-19 08:58:29 +00:00
|
|
|
);
|
|
|
|
my @bpa = (
|
2010-01-05 06:31:25 +00:00
|
|
|
"frame",
|
2009-12-29 11:42:49 +00:00
|
|
|
"password",
|
|
|
|
"newpassword",
|
|
|
|
"HMC_passwd",
|
|
|
|
"admin_passwd",
|
2010-03-04 09:38:44 +00:00
|
|
|
"general_passwd",
|
|
|
|
"*_passwd",
|
2011-05-23 10:09:14 +00:00
|
|
|
"hostname",
|
|
|
|
"resetnet",
|
2011-07-25 03:40:30 +00:00
|
|
|
"dev",
|
|
|
|
"celogin1"
|
2008-05-27 13:53:53 +00:00
|
|
|
);
|
|
|
|
my @ppc = (
|
|
|
|
"sshcfg"
|
|
|
|
);
|
|
|
|
my %rsp = (
|
2011-05-10 08:11:22 +00:00
|
|
|
cec=> \@fsp,
|
|
|
|
frame=>\@bpa,
|
2008-05-27 13:53:53 +00:00
|
|
|
fsp => \@fsp,
|
2009-01-19 08:58:29 +00:00
|
|
|
bpa => \@bpa,
|
2008-05-27 13:53:53 +00:00
|
|
|
ivm => \@ppc,
|
|
|
|
hmc => \@ppc
|
|
|
|
);
|
|
|
|
#############################################
|
|
|
|
# Get support command list
|
|
|
|
#############################################
|
2011-06-07 06:02:28 +00:00
|
|
|
#my $typetab = xCAT::Table->new( 'nodetype' );
|
|
|
|
#my $nodes = $request->{node};
|
|
|
|
#foreach (@$nodes) {
|
|
|
|
# if ( defined( $typetab )) {
|
|
|
|
# my ($ent) = $typetab->getAttribs({ node=>$_},'nodetype');
|
|
|
|
# if ( defined($ent) ) {
|
|
|
|
# $request->{hwtype} = $ent->{nodetype};
|
|
|
|
# last;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
#}
|
|
|
|
|
2009-07-01 06:03:26 +00:00
|
|
|
my $nodes = $request->{node};
|
2012-05-17 03:33:03 +00:00
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype($nodes);
|
2011-06-07 06:02:28 +00:00
|
|
|
foreach my $nn (@$nodes) {
|
2012-02-10 10:43:31 +00:00
|
|
|
$request->{hwtype} = $$typehash{$nn};
|
2011-06-07 06:02:28 +00:00
|
|
|
last if ($request->{hwtype});
|
2009-07-01 06:03:26 +00:00
|
|
|
}
|
2011-05-10 08:11:22 +00:00
|
|
|
|
2008-05-27 13:53:53 +00:00
|
|
|
my $supported = $rsp{$request->{hwtype}};
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
|
|
|
my $usage_string = xCAT::Usage->getUsage($command);
|
|
|
|
return( [$_[0], $usage_string] );
|
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
return(usage( "No command specified" ));
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# 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" );
|
|
|
|
$request->{method} = undef;
|
|
|
|
|
2012-06-29 09:03:22 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(V|verbose resetnet))) {
|
2008-05-27 13:53:53 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for "=" with no argument
|
|
|
|
####################################
|
|
|
|
if (my ($c) = grep(/=$/, @ARGV )) {
|
|
|
|
return(usage( "Missing argument: $c" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Check for unsupported commands
|
|
|
|
####################################
|
|
|
|
foreach my $arg ( @ARGV ) {
|
|
|
|
my ($command,$value) = split( /=/, $arg );
|
2011-05-23 10:09:14 +00:00
|
|
|
if ( !grep( /^$command$/, @$supported) and !$opt{resetnet}) {
|
2008-05-27 13:53:53 +00:00
|
|
|
return(usage( "Invalid command: $arg" ));
|
|
|
|
}
|
|
|
|
if ( exists( $cmds{$command} )) {
|
|
|
|
return(usage( "Command multiple times: $command" ));
|
|
|
|
}
|
|
|
|
$cmds{$command} = $value;
|
|
|
|
}
|
2009-12-29 11:42:49 +00:00
|
|
|
|
2008-05-27 13:53:53 +00:00
|
|
|
####################################
|
|
|
|
# Check command arguments
|
|
|
|
####################################
|
|
|
|
foreach ( keys %cmds ) {
|
|
|
|
if ( $cmds{$_} ) {
|
|
|
|
my $result = parse_option( $request, $_, $cmds{$_} );
|
|
|
|
if ( $result ) {
|
|
|
|
return( usage($result) );
|
|
|
|
}
|
2012-01-30 06:34:38 +00:00
|
|
|
} elsif ($_ =~ /_passwd$/) {
|
|
|
|
return( usage("No argument specified for '$_'"));
|
2008-05-27 13:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-17 07:29:17 +00:00
|
|
|
{
|
2012-01-30 06:34:38 +00:00
|
|
|
if ($request->{dev} eq '1' && $request->{other} eq '1') {
|
|
|
|
return ( usage("Invalid command arrays"));
|
|
|
|
}
|
|
|
|
# my $result = parse_dev_option( $request, \%cmds);
|
|
|
|
# if ($result) {
|
|
|
|
# return ( usage($result));
|
|
|
|
# }
|
2011-06-17 07:29:17 +00:00
|
|
|
}
|
2008-05-27 13:53:53 +00:00
|
|
|
####################################
|
|
|
|
# Return method to invoke
|
|
|
|
####################################
|
|
|
|
if ( $request->{hwtype} =~ /(^hmc|ivm)$/ ) {
|
|
|
|
$request->{method} = "cfg";
|
|
|
|
return( \%opt );
|
|
|
|
}
|
2009-09-02 16:25:46 +00:00
|
|
|
####################################
|
|
|
|
# Return method to invoke
|
|
|
|
####################################
|
2010-03-04 09:38:44 +00:00
|
|
|
if ( exists($cmds{frame}) or exists($cmds{hostname}) ) {
|
2009-12-29 08:23:20 +00:00
|
|
|
$request->{hcp} = "hmc";
|
2009-09-02 16:25:46 +00:00
|
|
|
$request->{method} = "cfg";
|
|
|
|
return( \%opt );
|
|
|
|
}
|
2011-05-23 10:09:14 +00:00
|
|
|
####################################
|
|
|
|
# Return method to invoke
|
|
|
|
####################################
|
|
|
|
if ( $opt{resetnet} ) {
|
|
|
|
$request->{hcp} = "hmc";
|
|
|
|
$request->{method} = "resetnet";
|
|
|
|
return( \%opt );
|
|
|
|
}
|
2009-12-29 11:42:49 +00:00
|
|
|
|
|
|
|
####################################
|
|
|
|
# Return method to invoke
|
|
|
|
####################################
|
2010-03-04 09:38:44 +00:00
|
|
|
if ( exists($cmds{HMC_passwd}) or exists($cmds{general_passwd}) or exists($cmds{admin_passwd}) or exists($cmds{"*_passwd"}) ) {
|
2009-12-29 11:42:49 +00:00
|
|
|
$request->{hcp} = "hmc";
|
|
|
|
$request->{method} = "passwd";
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
2008-05-27 13:53:53 +00:00
|
|
|
$request->{method} = \%cmds;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 07:29:17 +00:00
|
|
|
sub parse_dev_option{
|
|
|
|
my $req = shift;
|
|
|
|
my $cmds = shift;
|
|
|
|
foreach my $cmd (keys %$cmds) {
|
|
|
|
if ( $cmd =~ /^(dev|celogin1)$/ ) {
|
|
|
|
if ($cmds->{$cmd} and ($cmds->{$cmd} !~ /^(enable|disable)$/i) ) {
|
|
|
|
return( "Invalid argument ".$cmds->{$cmd}." for ".$cmd );
|
|
|
|
}
|
|
|
|
$req->{dev} = 1;
|
|
|
|
} else {
|
|
|
|
$req->{other} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($req->{dev} eq '1' && $req->{other} eq '1') {
|
|
|
|
return ("Invalid command arrays");
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
2008-05-27 13:53:53 +00:00
|
|
|
##########################################################################
|
|
|
|
# Parse the command line optional arguments
|
|
|
|
##########################################################################
|
|
|
|
sub parse_option {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $command = shift;
|
|
|
|
my $value = shift;
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Set/get time
|
|
|
|
####################################
|
|
|
|
if ( $command =~ /^time$/ ) {
|
|
|
|
if ( $value !~
|
|
|
|
/^([0-1]?[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9]):(0?[0-9]|[1-5][0-9])$/){
|
|
|
|
return( "Invalid time format '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Set/get date
|
|
|
|
####################################
|
|
|
|
if ( $command =~ /^date$/ ) {
|
|
|
|
if ( $value !~
|
|
|
|
/^(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])-(20[0-9]{2})$/){
|
|
|
|
return( "Invalid date format '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Set/get options
|
|
|
|
####################################
|
|
|
|
if ( $command =~ /^(autopower|iocap|sshcfg)$/ ) {
|
|
|
|
if ( $value !~ /^(enable|disable)$/i ) {
|
|
|
|
return( "Invalid argument '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Deconfiguration policy
|
|
|
|
####################################
|
|
|
|
if ( $command =~ /^decfg$/ ) {
|
|
|
|
if ( $value !~ /^(enable|disable):.*$/i ) {
|
|
|
|
return( "Invalid argument '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Processor deconfiguration
|
|
|
|
####################################
|
|
|
|
if ( $command =~ /^procdecfg$/ ) {
|
|
|
|
if ( $value !~ /^(configure|deconfigure):\d+:(all|[\d,]+)$/i ) {
|
|
|
|
return( "Invalid argument '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
################################
|
|
|
|
# Memory deconfiguration
|
|
|
|
################################
|
|
|
|
elsif ( $command =~ /^memdecfg$/ ) {
|
|
|
|
if ($value !~/^(configure|deconfigure):\d+:(unit|bank):(all|[\d,]+)$/i){
|
|
|
|
return( "Invalid argument '$value'" );
|
|
|
|
}
|
|
|
|
}
|
2009-01-19 08:58:29 +00:00
|
|
|
if ( $command eq 'network'){
|
|
|
|
my ( $adapter_name, $ip, $host, $gateway, $netmask) =
|
|
|
|
split /,/, $value;
|
|
|
|
return ( "Network interface name is required") if ( ! $adapter_name);
|
|
|
|
return ( "Invalide network interface name $adapter_name") if ( $adapter_name !~ /^eth\d$/);
|
|
|
|
return undef if ( $ip eq '*');
|
|
|
|
return ( "Invalid IP address format") if ( $ip and $ip !~ /\d+\.\d+\.\d+\.\d+/);
|
|
|
|
return ( "Invalid netmask format") if ( $netmask and $netmask !~ /\d+\.\d+\.\d+\.\d+/);
|
|
|
|
}
|
|
|
|
|
2009-09-02 16:25:46 +00:00
|
|
|
if ( $command eq 'frame' ){
|
|
|
|
if ( $value !~ /^\d+$/i && $value ne '*' ) {
|
|
|
|
return( "Invalid frame number '$value'" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 09:38:44 +00:00
|
|
|
if ( $command eq 'admin_passwd' or $command eq 'general_passwd' or $command eq '*_passwd' ){
|
2009-12-29 11:42:49 +00:00
|
|
|
my ($passwd,$newpasswd) = split /,/, $value;
|
|
|
|
if ( !$passwd or !$newpasswd) {
|
2010-03-04 09:38:44 +00:00
|
|
|
return( "Current password and new password couldn't be empty" );
|
2009-12-29 11:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $command eq 'HMC_passwd' ) {
|
|
|
|
my ($passwd,$newpasswd) = split /,/, $value;
|
|
|
|
if ( !$newpasswd ) {
|
|
|
|
return( "New password couldn't be empty for user 'HMC'" );
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 06:34:38 +00:00
|
|
|
|
|
|
|
if ( $command eq 'dev' or $command eq 'celogin1' ) {
|
|
|
|
if ($value !~ /^(enable|disable)$/i ) {
|
|
|
|
return( "Invalid argument '$value'" );
|
|
|
|
}
|
|
|
|
$request->{dev} = 1;
|
|
|
|
} else {
|
|
|
|
$request->{other} = 1;
|
|
|
|
}
|
2008-05-27 13:53:53 +00:00
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2009-12-29 11:42:49 +00:00
|
|
|
##########################################################################
|
|
|
|
# Update passwords for different users on FSP/BPA
|
|
|
|
##########################################################################
|
|
|
|
sub passwd {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my $result;
|
2010-03-04 09:38:44 +00:00
|
|
|
my $users;
|
2009-12-29 11:42:49 +00:00
|
|
|
|
|
|
|
foreach my $arg ( @$args ) {
|
|
|
|
my ($user,$value) = split /=/, $arg;
|
|
|
|
my ($passwd,$newpasswd) = split /,/, $value;
|
|
|
|
$user =~ s/_passwd$//;
|
2010-03-04 09:38:44 +00:00
|
|
|
$user =~ s/^HMC$/access/g;
|
|
|
|
|
|
|
|
if ( $user eq "*" ) {
|
|
|
|
push @$users, "access";
|
|
|
|
push @$users, "admin";
|
|
|
|
push @$users, "general";
|
|
|
|
} else {
|
|
|
|
push @$users, $user;
|
|
|
|
}
|
2009-12-29 11:42:49 +00:00
|
|
|
|
2010-03-04 09:38:44 +00:00
|
|
|
foreach my $usr ( @$users ) {
|
|
|
|
while ( my ($cec,$h) = each(%$hash) ) {
|
|
|
|
while ( my ($node,$d) = each(%$h) ) {
|
|
|
|
my $type = @$d[4];
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :modify password of $usr for node:$node.");
|
2010-03-25 06:38:39 +00:00
|
|
|
my $data = xCAT::PPCcli::chsyspwd( $exp, $usr, $type, $cec, $passwd, $newpasswd );
|
2010-03-04 09:38:44 +00:00
|
|
|
my $Rc = shift(@$data);
|
2010-03-25 06:38:39 +00:00
|
|
|
my $usr_back = $usr;
|
|
|
|
$usr_back =~ s/^access$/HMC/g;
|
|
|
|
push @$result, [$node,"$usr_back: @$data[0]",$Rc];
|
2010-03-04 09:38:44 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Write the new password to table
|
|
|
|
##################################
|
|
|
|
if ( $Rc == SUCCESS ) {
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :update xCATdb for node:$node,ID:$usr_back.");
|
2010-03-25 06:38:39 +00:00
|
|
|
xCAT::PPCdb::update_credentials( $node, $type, $usr_back, $newpasswd );
|
2010-03-04 09:38:44 +00:00
|
|
|
}
|
2009-12-29 11:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-27 13:53:53 +00:00
|
|
|
|
2009-12-29 11:42:49 +00:00
|
|
|
return( [@$result] );
|
|
|
|
}
|
2008-05-27 13:53:53 +00:00
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Handles all PPC rspconfig commands
|
|
|
|
##########################################################################
|
|
|
|
sub cfg {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
foreach ( @$args ) {
|
|
|
|
##################################
|
|
|
|
# Ignore switches in command-line
|
|
|
|
##################################
|
|
|
|
unless ( /^-/ ) {
|
|
|
|
my ($cmd,$value) = split /=/;
|
|
|
|
|
|
|
|
no strict 'refs';
|
2009-09-02 16:25:46 +00:00
|
|
|
$result = $rspconfig{$cmd}( $request, $exp, $value, $hash );
|
2008-05-27 13:53:53 +00:00
|
|
|
use strict;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Enables/disables/displays SSH access to HMC/IVM
|
|
|
|
##########################################################################
|
|
|
|
sub sshcfg {
|
2009-09-25 03:14:50 +00:00
|
|
|
my $request = shift;
|
2009-09-02 16:25:46 +00:00
|
|
|
my $exp = shift;
|
|
|
|
my $mode = shift;
|
|
|
|
my $server = @$exp[3];
|
|
|
|
my $userid = @$exp[4];
|
|
|
|
my $fname = ((xCAT::Utils::isAIX()) ? "/.ssh/":"/root/.ssh/")."id_rsa.pub";
|
|
|
|
my $auth = "/home/$userid/.ssh/authorized_keys2";
|
2008-05-27 13:53:53 +00:00
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Get SSH key on Management Node
|
|
|
|
#####################################
|
|
|
|
unless ( open(RSAKEY,"<$fname") ) {
|
|
|
|
return( [[$server,"Error opening '$fname'",RC_ERROR]] );
|
|
|
|
}
|
|
|
|
my ($sshkey) = <RSAKEY>;
|
|
|
|
close(RSAKEY);
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# userid@host not found in key file
|
|
|
|
#####################################
|
|
|
|
if ( $sshkey !~ /\s+(\S+\@\S+$)/ ) {
|
|
|
|
return( [[$server,"Cannot find userid\@host in '$fname'",RC_ERROR]] );
|
|
|
|
}
|
|
|
|
my $logon = $1;
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# Determine if SSH is enabled
|
|
|
|
#####################################
|
|
|
|
if ( !defined( $mode )) {
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :check sshcfg for user:$logon on node:$server.");
|
2008-05-27 13:53:53 +00:00
|
|
|
my $result = xCAT::PPCcli::send_cmd( $exp, "cat $auth" );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$server,@$result[0],$Rc]] );
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Find logon in key file
|
|
|
|
#################################
|
|
|
|
foreach ( @$result ) {
|
2011-06-08 06:21:41 +00:00
|
|
|
if ( /$logon$/ ) {
|
2008-05-27 13:53:53 +00:00
|
|
|
return( [[$server,"enabled",SUCCESS]] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( [[$server,"disabled",SUCCESS]] );
|
|
|
|
}
|
|
|
|
#####################################
|
|
|
|
# Enable/disable SSH
|
|
|
|
#####################################
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :sshcfg $mode for user:$logon on node:$server.");
|
2008-05-27 13:53:53 +00:00
|
|
|
my $result = xCAT::PPCcli::mkauthkeys( $exp, $mode, $logon, $sshkey );
|
|
|
|
my $Rc = shift(@$result);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$server,@$result[0],$Rc]] );
|
|
|
|
}
|
|
|
|
return( [[$server,lc($mode."d"),SUCCESS]] );
|
|
|
|
}
|
|
|
|
|
2009-09-02 16:25:46 +00:00
|
|
|
sub frame {
|
|
|
|
my $request = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $value = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $arg = $request->{arg};
|
2008-05-27 13:53:53 +00:00
|
|
|
|
2009-09-02 16:25:46 +00:00
|
|
|
foreach ( @$arg ) {
|
|
|
|
my $result;
|
|
|
|
my $Rc;
|
|
|
|
my $data;
|
|
|
|
|
|
|
|
my ($cmd, $value) = split /=/, $_;
|
|
|
|
if ( $cmd ne "frame" ) {
|
|
|
|
return( [[@$exp[2],"Multiple option $cmd and frame is not accepted",SUCCESS]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Open xCAT database to sync with
|
|
|
|
# the frame number between hcp
|
|
|
|
# and database
|
|
|
|
#################################
|
|
|
|
my $tab = xCAT::Table->new( "ppc" );
|
|
|
|
|
|
|
|
while ( my ($cec,$h) = each(%$hash) ) {
|
|
|
|
while ( my ($node,$d) = each(%$h) ) {
|
|
|
|
if ( !defined($value) ) {
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Get frame number
|
|
|
|
#################################
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :get frame_num for node:$node.");
|
2009-09-02 16:25:46 +00:00
|
|
|
$data = xCAT::PPCcli::lssyscfg( $exp, @$d[4], @$d[2], 'frame_num' );
|
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$node,@$data[0],$Rc]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Set frame number to database
|
|
|
|
#################################
|
|
|
|
$tab->setNodeAttribs( $node, { id=>@$data[0] } );
|
|
|
|
|
|
|
|
} elsif ( $value eq '*' ) {
|
|
|
|
#################################
|
|
|
|
# Set frame number
|
|
|
|
# Read the settings from database
|
|
|
|
#################################
|
|
|
|
my $ent=$tab->getNodeAttribs( $node,['id'] );
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( !defined($ent) or !defined($ent->{id}) ) {
|
|
|
|
return( [[$node,"Cannot find frame num in database",RC_ERROR]] );
|
|
|
|
}
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :set frame_num=".$ent->{id}." for node:$node.");
|
2010-03-04 09:38:44 +00:00
|
|
|
$data = xCAT::PPCcli::chsyscfg( $exp, "bpa", $d, "frame_num=".$ent->{id} );
|
2009-09-02 16:25:46 +00:00
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$node,@$data[0],$Rc]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
#################################
|
|
|
|
# Set frame number
|
|
|
|
# Read the frame number from opt
|
|
|
|
#################################
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :set frame_num=$value for node:$node.");
|
2010-03-04 09:38:44 +00:00
|
|
|
$data = xCAT::PPCcli::chsyscfg( $exp, "bpa", $d, "frame_num=$value" );
|
2009-09-02 16:25:46 +00:00
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
return( [[$node,@$data[0],$Rc]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Set frame number to database
|
|
|
|
#################################
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig : set frame_num, update node:$node attr id=$value.");
|
2009-09-02 16:25:46 +00:00
|
|
|
$tab->setNodeAttribs( $node, { id=>$value } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( [@$result] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 09:38:44 +00:00
|
|
|
sub hostname {
|
|
|
|
my $request = shift;
|
|
|
|
my $exp = shift;
|
|
|
|
my $value = shift;
|
|
|
|
my $hash = shift;
|
|
|
|
my $arg = $request->{arg};
|
|
|
|
my $result;
|
|
|
|
|
|
|
|
foreach ( @$arg ) {
|
|
|
|
my $data;
|
|
|
|
my $Rc;
|
|
|
|
|
|
|
|
my ($cmd, $value) = split /=/, $_;
|
|
|
|
if ( $cmd ne "hostname" ) {
|
|
|
|
return( [[@$exp[2],"Multiple option $cmd and hostname is not accepted",SUCCESS]] );
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( my ($cec,$h) = each(%$hash) ) {
|
|
|
|
while ( my ($node,$d) = each(%$h) ) {
|
|
|
|
if ( !defined($value) ) {
|
|
|
|
#################################
|
|
|
|
# Get system name
|
|
|
|
#################################
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :get system name for node:$node.");
|
2010-03-04 09:38:44 +00:00
|
|
|
$data = xCAT::PPCcli::lssyscfg( $exp, @$d[4], @$d[2], 'name' );
|
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
push @$result, [$node,@$data[0],$Rc];
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
} elsif ( $value eq '*' ) {
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :set system name:$node for node:$node.");
|
2010-03-04 09:38:44 +00:00
|
|
|
$data = xCAT::PPCcli::chsyscfg( $exp, @$d[4], $d, "new_name=$node" );
|
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
push @$result, [$node,@$data[0],$Rc];
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
} else {
|
2012-06-21 09:43:16 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($request, "rspconfig :set system name:$value for node:$node.");
|
2010-03-04 09:38:44 +00:00
|
|
|
$data = xCAT::PPCcli::chsyscfg( $exp, @$d[4], $d, "new_name=$value" );
|
|
|
|
$Rc = shift(@$data);
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Return error
|
|
|
|
#################################
|
|
|
|
if ( $Rc != SUCCESS ) {
|
|
|
|
push @$result, [$node,@$data[0],$Rc];
|
|
|
|
}
|
|
|
|
|
|
|
|
push @$result, [$node,@$data[0],SUCCESS];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( [@$result] );
|
|
|
|
}
|
2011-05-23 10:09:14 +00:00
|
|
|
##########################################################################
|
2012-07-01 03:11:25 +00:00
|
|
|
# Do resetnet public entry
|
2011-05-23 10:09:14 +00:00
|
|
|
##########################################################################
|
|
|
|
sub resetnet {
|
|
|
|
my $request = shift;
|
2012-07-01 03:11:25 +00:00
|
|
|
doresetnet($request);
|
2012-08-02 06:54:50 +00:00
|
|
|
return 0;
|
2011-05-23 10:09:14 +00:00
|
|
|
}
|
2012-04-06 03:33:56 +00:00
|
|
|
##########################################################################
|
|
|
|
# Reset the network interfraces if necessary
|
|
|
|
##########################################################################
|
|
|
|
sub doresetnet {
|
|
|
|
|
2012-07-01 03:11:25 +00:00
|
|
|
my $req = shift;
|
|
|
|
my %iphash;
|
2012-04-06 03:33:56 +00:00
|
|
|
my $targets;
|
|
|
|
my $result;
|
2012-07-01 03:11:25 +00:00
|
|
|
my %grouphash;
|
|
|
|
my %oihash;
|
|
|
|
my %machash;
|
|
|
|
my %vpdhash;
|
|
|
|
|
|
|
|
unless ($req) {
|
|
|
|
send_msg( $req, 1, "request is empty, return" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# prepare to reset network
|
|
|
|
###########################################
|
|
|
|
xCAT::MsgUtils->verbose_message($req, "rspconfig :do resetnet begin to phase nodes");
|
2012-04-06 03:33:56 +00:00
|
|
|
my $hoststab = xCAT::Table->new( 'hosts' );
|
|
|
|
if ( !$hoststab ) {
|
|
|
|
send_msg( $req, 1, "Error open hosts table" );
|
2012-07-01 03:11:25 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
my @hostslist = $hoststab->getAllNodeAttribs(['node','otherinterfaces']);
|
|
|
|
foreach my $otherentry ( @hostslist) {
|
|
|
|
$oihash{$otherentry->{node}} = $otherentry->{otherinterfaces};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-06 03:33:56 +00:00
|
|
|
my $mactab = xCAT::Table->new( 'mac' );
|
|
|
|
if ( !$mactab ) {
|
|
|
|
send_msg( $req, 1, "Error open mac table" );
|
2012-07-01 03:11:25 +00:00
|
|
|
return;
|
|
|
|
}else{
|
2012-07-12 08:51:22 +00:00
|
|
|
my @maclist = $mactab->getAllNodeAttribs(['node','mac']);
|
2012-07-01 03:11:25 +00:00
|
|
|
foreach my $macentry (@maclist) {
|
|
|
|
$machash{$macentry->{node}} = $macentry->{mac};
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-12 08:51:22 +00:00
|
|
|
$mactab = ();
|
2012-04-06 03:33:56 +00:00
|
|
|
|
2012-07-01 03:11:25 +00:00
|
|
|
my $vpdtab = xCAT::Table->new( 'vpd' );
|
|
|
|
if ( !$vpdtab ) {
|
|
|
|
send_msg( $req, 1, "Error open vpd table" );
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
my @vpdlist = $vpdtab->getAllNodeAttribs(['node','mtm','serial','side']);
|
|
|
|
foreach my $vpdentry (@vpdlist) {
|
|
|
|
if ($vpdentry->{side} =~ /(\w)\-\w/) {
|
|
|
|
my $side = $1;
|
|
|
|
$vpdhash{$vpdentry->{node}} = $vpdentry->{mtm}."*".$vpdentry->{serial}."*".$side;
|
|
|
|
}
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
}
|
2012-07-12 08:51:22 +00:00
|
|
|
$vpdtab = ();
|
2012-04-06 03:33:56 +00:00
|
|
|
|
2012-07-01 03:11:25 +00:00
|
|
|
unless ( $req->{node} ) {
|
|
|
|
send_msg( $req, 0, "no node specified" );
|
|
|
|
return;
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
###########################################
|
2012-07-01 03:11:25 +00:00
|
|
|
# Process nodes and get network information
|
2012-04-06 03:33:56 +00:00
|
|
|
###########################################
|
2012-07-01 03:11:25 +00:00
|
|
|
my $nodetype = $req->{hwtype};
|
|
|
|
if ( $nodetype =~ /^(cec|frame)$/ ) {
|
|
|
|
# this brunch is just for the xcat 2.6(or 2.6+) database
|
|
|
|
foreach my $nn ( @{ $req->{node}} ) {
|
|
|
|
my $cnodep = xCAT::DBobjUtils->getchildren($nn);
|
|
|
|
$nodetype = ( $nodetype =~ /^frame$/i ) ? "bpa" : "fsp";
|
|
|
|
if ($cnodep) {
|
|
|
|
foreach my $cnode (@$cnodep) {
|
2012-08-09 03:48:50 +00:00
|
|
|
my $ip = xCAT::NetworkUtils::getNodeIPaddress( $cnode );
|
2012-07-01 03:11:25 +00:00
|
|
|
my $oi = $oihash{$cnode};
|
2012-07-12 08:51:22 +00:00
|
|
|
if(!defined $ip) {
|
|
|
|
send_msg($req, "doresetnet: can't get $cnode ip");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if(!defined $oi) {
|
|
|
|
send_msg($req, "doresetnet: can't get $cnode hosts.otherinterfaces");
|
|
|
|
next;
|
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
if ( exists($oihash{$cnode}) and $ip eq $oihash{$cnode}) {
|
|
|
|
send_msg( $req, 0, "$cnode: same ip address, skipping $nn network reset" );
|
|
|
|
} elsif( ! exists $machash{$cnode}){
|
|
|
|
send_msg( $req, 0, "$cnode: no mac defined, skipping $nn network reset" );
|
|
|
|
} else {
|
|
|
|
$iphash{$cnode}{sip} = $ip;
|
|
|
|
$iphash{$cnode}{tip} = $oihash{$cnode};
|
|
|
|
if(exists $grouphash{$vpdhash{$cnode}}) {
|
|
|
|
$grouphash{$vpdhash{$cnode}} .= ",$cnode";
|
|
|
|
} else {
|
|
|
|
$grouphash{$vpdhash{$cnode}} = "$cnode";
|
|
|
|
}
|
|
|
|
$targets->{$nodetype}->{$ip}->{'args'} = "0.0.0.0,$cnode";
|
|
|
|
$targets->{$nodetype}->{$ip}->{'mac'} = $machash{$cnode};
|
|
|
|
$targets->{$nodetype}->{$ip}->{'name'} = $cnode;
|
2012-07-12 08:51:22 +00:00
|
|
|
$targets->{$nodetype}->{$ip}->{'ip'} = $ip;
|
2012-07-01 03:11:25 +00:00
|
|
|
$targets->{$nodetype}->{$ip}->{'type'} = $nodetype;
|
2012-07-12 08:51:22 +00:00
|
|
|
my %netinfo = xCAT::DBobjUtils->getNetwkInfo( [$ip] );
|
|
|
|
$targets->{$nodetype}->{$ip}->{'args'} .= ",$netinfo{$ip}{'gateway'},$netinfo{$ip}{'mask'}";
|
|
|
|
#xCAT::MsgUtils->verbose_message($req, "doresetnet: get node $cnode info $targets->{$nodetype}->{$ip}->{'args'}, ip is $ip");
|
|
|
|
$targets->{$nodetype}->{$oi}->{'args'} = "0.0.0.0,$cnode";
|
|
|
|
$targets->{$nodetype}->{$oi}->{'mac'} = $machash{$cnode};
|
|
|
|
$targets->{$nodetype}->{$oi}->{'name'} = $cnode;
|
|
|
|
$targets->{$nodetype}->{$oi}->{'ip'} = $oi;
|
|
|
|
$targets->{$nodetype}->{$oi}->{'type'} = $nodetype;
|
|
|
|
%netinfo = xCAT::DBobjUtils->getNetwkInfo( [$oi] );
|
|
|
|
$targets->{$nodetype}->{$oi}->{'args'} .= ",$netinfo{$oi}{'gateway'},$netinfo{$oi}{'mask'}";
|
|
|
|
#xCAT::MsgUtils->verbose_message($req, "doresetnet: get node $cnode info $targets->{$nodetype}->{$oi}->{'args'}, oi is $oi");
|
|
|
|
|
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
send_msg( $req, 1, "Can't get the fsp/bpa nodes for the $nn" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# this brunch is just for the xcat 2.5(or 2.5-) databse
|
|
|
|
} elsif ( $nodetype =~ /^(fsp|bpa)$/ ) {
|
|
|
|
foreach my $nn ( @{ $req->{node}} ) {
|
2012-08-09 03:48:50 +00:00
|
|
|
my $ip = xCAT::NetworkUtils::getNodeIPaddress( $nn );
|
2012-07-12 08:51:22 +00:00
|
|
|
if(!defined $ip) {
|
|
|
|
send_msg($req, "doresetnet: can't get $nn ip");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if(!exists $oihash{$nn}) {
|
|
|
|
send_msg($req, "doresetnet: can't get $nn hosts.otherinterfaces");
|
|
|
|
next;
|
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
my $oi = $oihash{$nn};
|
|
|
|
if( exists($oihash{$nn}) and $ip eq $oihash{$nn}) {
|
|
|
|
send_msg( $req, 0, "$nn: same ip address, skipping network reset" );
|
|
|
|
} elsif (!exists $machash{$nn}){
|
|
|
|
send_msg( $req, 0, "$nn: no mac defined, skipping network reset" );
|
|
|
|
} else {
|
|
|
|
$iphash{$nn}{sip} = $ip;
|
|
|
|
$iphash{$nn}{tip} = $oihash{$nn};
|
|
|
|
if(exists $grouphash{$vpdhash{$nn}}) {
|
|
|
|
$grouphash{$vpdhash{$nn}} .= ",$nn";
|
|
|
|
} else {
|
|
|
|
$grouphash{$vpdhash{$nn}} = "$nn";
|
|
|
|
}
|
|
|
|
$targets->{$nodetype}->{$ip}->{'args'} = "0.0.0.0,$nn";
|
|
|
|
$targets->{$nodetype}->{$ip}->{'mac'} = $machash{$nn};
|
|
|
|
$targets->{$nodetype}->{$ip}->{'name'} = $nn;
|
2012-07-12 08:51:22 +00:00
|
|
|
$targets->{$nodetype}->{$ip}->{'ip'} = $ip;
|
2012-07-01 03:11:25 +00:00
|
|
|
$targets->{$nodetype}->{$ip}->{'type'} = $nodetype;
|
2012-07-12 08:51:22 +00:00
|
|
|
my %netinfo = xCAT::DBobjUtils->getNetwkInfo( [$ip] );
|
|
|
|
$targets->{$nodetype}->{$ip}->{'args'} .= ",$netinfo{$ip}{'gateway'},$netinfo{$ip}{'mask'}";
|
|
|
|
#xCAT::MsgUtils->verbose_message($req, "doresetnet: get node $nn info $targets->{$nodetype}->{$ip}->{'args'},ip is $ip");
|
|
|
|
$targets->{$nodetype}->{$oi}->{'args'} = "0.0.0.0,$nn";
|
|
|
|
$targets->{$nodetype}->{$oi}->{'mac'} = $machash{$nn};
|
|
|
|
$targets->{$nodetype}->{$oi}->{'name'} = $nn;
|
|
|
|
$targets->{$nodetype}->{$oi}->{'ip'} = $oi;
|
|
|
|
$targets->{$nodetype}->{$oi}->{'type'} = $nodetype;
|
|
|
|
%netinfo = xCAT::DBobjUtils->getNetwkInfo( [$oi] );
|
|
|
|
$targets->{$nodetype}->{$oi}->{'args'} .= ",$netinfo{$oi}{'gateway'},$netinfo{$oi}{'mask'}";
|
|
|
|
#xCAT::MsgUtils->verbose_message($req, "doresetnet: get node $nn info $targets->{$nodetype}->{$oi}->{'args'}, oi is $oi");
|
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
}
|
|
|
|
} elsif ( !$nodetype ){
|
|
|
|
send_msg( $req, 0, "no nodetype defined, skipping network reset" );
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
send_msg( $req, 0, "$nodetype not supported, skipping network reset" );
|
|
|
|
return;
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
|
|
|
|
unless (%grouphash) {
|
|
|
|
send_msg( $req, 0, "Failed to group the nodes, skipping network reset" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
###########################################
|
|
|
|
# Update target hardware w/discovery info
|
|
|
|
###########################################
|
|
|
|
my %rsp_dev = get_rsp_dev( $req, $targets);
|
|
|
|
|
|
|
|
######################################################
|
|
|
|
# Start to reset network. Fork one process per BPA/FSP
|
|
|
|
######################################################
|
2012-07-12 08:51:22 +00:00
|
|
|
%oihash = ();
|
|
|
|
%machash = ();
|
|
|
|
%vpdhash = ();
|
2012-07-01 03:11:25 +00:00
|
|
|
$start = Time::HiRes::gettimeofday();
|
2012-04-06 03:33:56 +00:00
|
|
|
my $children = 0;
|
|
|
|
$SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) { $children--; } };
|
|
|
|
my $fds = new IO::Select;
|
2012-07-01 03:11:25 +00:00
|
|
|
my $callback = $req->{callback};
|
2012-08-24 01:55:11 +00:00
|
|
|
my $ij = 0;
|
2012-07-01 03:11:25 +00:00
|
|
|
foreach my $node ( keys %grouphash) {
|
2012-07-12 08:51:22 +00:00
|
|
|
my %iphashfornode;
|
|
|
|
my $gc = $grouphash{$node};
|
|
|
|
my %rsp_devfornode;
|
|
|
|
|
|
|
|
foreach my $tn (split /,/, $gc) {
|
|
|
|
$iphashfornode{$tn} = $iphash{$tn};
|
|
|
|
for my $ti (keys %{$iphash{$tn}}){
|
|
|
|
my $tip = $iphash{$tn}{$ti};
|
|
|
|
$rsp_devfornode{$tip} = $rsp_dev{$tip};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-01 03:11:25 +00:00
|
|
|
xCAT::MsgUtils->verbose_message($req, "========> begin to fork process for node $node");
|
2012-07-12 08:51:22 +00:00
|
|
|
######################################################
|
|
|
|
# Begin fork
|
|
|
|
######################################################
|
|
|
|
my $pipe;
|
|
|
|
my $rspdevref = \%rsp_devfornode;
|
|
|
|
my $grouphashref = $gc;
|
|
|
|
my $iphashref = \%iphashfornode;
|
|
|
|
my $result;
|
|
|
|
my @data = ("RSPCONFIG6sK4ci");
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
# Pipe childs output back to parent
|
|
|
|
#######################################
|
|
|
|
my $parent;
|
|
|
|
my $child;
|
|
|
|
pipe $parent, $child;
|
2012-08-24 01:55:11 +00:00
|
|
|
$ij ++;
|
|
|
|
$ij = int($ij%60);
|
2012-07-12 08:51:22 +00:00
|
|
|
my $pid = xCAT::Utils->xfork();
|
|
|
|
|
|
|
|
if ( !defined($pid) ) {
|
|
|
|
###################################
|
|
|
|
# Fork error
|
|
|
|
###################################
|
|
|
|
send_msg( $req, 1, "Fork error: $!" );
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
elsif ( $pid == 0 ) {
|
2012-08-24 01:55:11 +00:00
|
|
|
sleep $ij;
|
2012-07-12 08:51:22 +00:00
|
|
|
###################################
|
|
|
|
# Child process, clear memory first
|
|
|
|
###################################
|
|
|
|
%rsp_dev = ();
|
|
|
|
%grouphash = ();
|
|
|
|
%iphash = ();
|
|
|
|
close( $parent );
|
|
|
|
$req->{pipe} = $child;
|
2012-08-11 14:21:42 +00:00
|
|
|
my $msgs;
|
|
|
|
my $report;
|
2012-08-24 01:55:11 +00:00
|
|
|
#try and try to avoid the fail that caused by refreshing IP when doing resetnet
|
2012-08-11 14:21:42 +00:00
|
|
|
my $time = 0;
|
|
|
|
while (1) {
|
|
|
|
my $erflag = 0;
|
|
|
|
$msgs = child_process($grouphashref, $iphashref, $rspdevref, $req, $node );
|
|
|
|
foreach my $port (keys %$msgs){
|
|
|
|
unless ($msgs->{$port} =~ /successful/) {
|
|
|
|
$erflag = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($erflag) {
|
|
|
|
$report = ();
|
|
|
|
foreach my $port1 (keys %$msgs){
|
|
|
|
$report .= $port1.":".$msgs->{$port1}.";";
|
|
|
|
}
|
|
|
|
xCAT::MsgUtils->verbose_message($req, "========> try again, $report");
|
2012-08-14 06:53:05 +00:00
|
|
|
#send_msg( $req, 0, "========> try again, $report");
|
2012-08-11 14:21:42 +00:00
|
|
|
sleep 3;
|
|
|
|
$time++;
|
|
|
|
} else {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
last if ($time > 10);
|
|
|
|
}
|
|
|
|
$report = ();
|
|
|
|
foreach my $port (keys %$msgs){
|
|
|
|
$report .= $port.":".$msgs->{$port}.";";
|
|
|
|
}
|
2012-08-24 01:55:11 +00:00
|
|
|
send_msg( $req, 0, "Resetnet result for $node is : $report");
|
2012-07-12 08:51:22 +00:00
|
|
|
####################################
|
|
|
|
# Pass result array back to parent
|
|
|
|
####################################
|
2012-08-11 11:06:49 +00:00
|
|
|
my %data;
|
|
|
|
$data{errorcode} = 0;
|
2012-07-12 08:51:22 +00:00
|
|
|
my $out = $req->{pipe};
|
2012-08-11 11:06:49 +00:00
|
|
|
print $out freeze( [\%data] );
|
2012-07-12 08:51:22 +00:00
|
|
|
print $out "\nENDOFFREEZE6sK4ci\n";
|
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
###################################
|
|
|
|
# Parent process
|
|
|
|
###################################
|
|
|
|
close( $child );
|
|
|
|
$pipe = $parent ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-06 03:33:56 +00:00
|
|
|
if ( $pipe ) {
|
|
|
|
$fds->add( $pipe );
|
|
|
|
$children++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Process responses from children
|
|
|
|
#############################################
|
|
|
|
while ( $children > 0 ) {
|
|
|
|
child_response( $callback, $fds );
|
|
|
|
}
|
|
|
|
while (child_response($callback,$fds)) {}
|
|
|
|
|
2012-07-01 03:11:25 +00:00
|
|
|
my $elapsed = Time::HiRes::gettimeofday() - $start;
|
|
|
|
my $msg = sprintf( "Total rspconfig Time: %.3f sec\n", $elapsed );
|
|
|
|
xCAT::MsgUtils->verbose_message($req, $msg);
|
2012-04-06 03:33:56 +00:00
|
|
|
|
2012-08-11 11:06:49 +00:00
|
|
|
return undef;
|
|
|
|
}
|
2012-08-24 01:55:11 +00:00
|
|
|
##########################################################################
|
|
|
|
# child process
|
|
|
|
##########################################################################
|
2012-08-11 11:06:49 +00:00
|
|
|
sub child_process {
|
|
|
|
my $grouphashref = shift;
|
|
|
|
my $iphashref = shift;
|
|
|
|
my $rspdevref = shift;
|
|
|
|
my $req = shift;
|
|
|
|
my $node = shift;
|
|
|
|
my %msginfo;
|
|
|
|
my @ns = split /,/, $grouphashref;
|
|
|
|
my @valid_ips;
|
|
|
|
my @portneedreset;
|
|
|
|
my @portsuccess;
|
2012-08-24 01:55:11 +00:00
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# ping static ip firstly, if succesufully, skip resetnet
|
|
|
|
##########################################################
|
2012-08-11 11:06:49 +00:00
|
|
|
foreach my $fspport (@ns) {
|
|
|
|
my $ip = ${$iphashref->{$fspport}}{sip};
|
|
|
|
my $rc = system("ping -q -n -c 1 -w 1 $ip > /dev/null");
|
|
|
|
if ($rc == 0) {
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "ping static $ip successfully");
|
|
|
|
push @valid_ips, $ip; # static ip should be used first
|
|
|
|
push @portsuccess, $fspport;
|
2012-08-24 01:55:11 +00:00
|
|
|
$msginfo{$fspport} = "successful";
|
2012-04-06 03:33:56 +00:00
|
|
|
} else {
|
2012-08-11 11:06:49 +00:00
|
|
|
xCAT::MsgUtils->verbose_message( $req, "ping static $ip failed, need to do resetnet for $fspport");
|
|
|
|
push @portneedreset, $fspport;
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-11 11:06:49 +00:00
|
|
|
if (scalar (@portneedreset) == 0) {
|
2012-08-11 14:21:42 +00:00
|
|
|
return \%msginfo;
|
2012-08-11 11:06:49 +00:00
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
###########################################
|
2012-08-24 01:55:11 +00:00
|
|
|
# ping temp ip secondary
|
2012-07-01 03:11:25 +00:00
|
|
|
###########################################
|
2012-08-11 11:06:49 +00:00
|
|
|
foreach my $fspport (@ns) {
|
|
|
|
my $ip = ${$iphashref->{$fspport}}{tip};
|
|
|
|
my $rc = system("ping -q -n -c 1 -w 1 $ip > /dev/null");
|
|
|
|
if ($rc == 0) {
|
|
|
|
push @valid_ips, $ip;
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "ping temp $ip successfully");
|
|
|
|
} else {
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "ping temp $ip failed");
|
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
}
|
2012-08-11 11:06:49 +00:00
|
|
|
if (scalar (@valid_ips) == 0) {
|
2012-08-11 14:21:42 +00:00
|
|
|
foreach my $fspport (@ns) {
|
|
|
|
$msginfo{$fspport} = "failed to find valid ip to log on";
|
|
|
|
}
|
|
|
|
return \%msginfo;
|
2012-07-01 03:11:25 +00:00
|
|
|
}
|
2012-08-24 01:55:11 +00:00
|
|
|
#########################################
|
|
|
|
# log on, no retry here
|
|
|
|
#########################################
|
2012-08-11 11:06:49 +00:00
|
|
|
my @exp;
|
|
|
|
my $goodip;
|
|
|
|
my $retry = 2;
|
|
|
|
foreach my $ip(@valid_ips) {
|
|
|
|
@exp = xCAT::PPCcfg::connect(${$rspdevref->{$ip}}{username},${$rspdevref->{$ip}}{password}, $ip);
|
2012-08-24 01:55:11 +00:00
|
|
|
####################################
|
|
|
|
# Successfully connected
|
|
|
|
####################################
|
2012-08-11 11:06:49 +00:00
|
|
|
if ( ref($exp[0]) eq "LWP::UserAgent" ) {
|
|
|
|
$goodip = $ip;
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "log in successfully with $ip");
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $msg = "login result is :".join(',', @exp);
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, $msg);
|
2012-08-24 01:55:11 +00:00
|
|
|
|
|
|
|
####################################
|
|
|
|
# do resetnet
|
|
|
|
####################################
|
2012-08-11 11:06:49 +00:00
|
|
|
unless ($goodip) {
|
2012-08-11 14:21:42 +00:00
|
|
|
foreach my $fspport (@ns) {
|
|
|
|
$msginfo{$fspport} = "failed to log on with $exp[0]";
|
|
|
|
}
|
|
|
|
return \%msginfo;
|
2012-08-11 11:06:49 +00:00
|
|
|
}
|
|
|
|
my %handled;
|
|
|
|
my $port;
|
|
|
|
if (scalar(@portneedreset) == 2 ) { ## do resetnet for the other port first
|
|
|
|
$port = $portneedreset[0];
|
|
|
|
my $ip = ${$iphashref->{$port}}{sip};
|
|
|
|
if ($goodip eq $ip) {
|
|
|
|
$port = $portneedreset[1];
|
|
|
|
}
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "begin to reset for port $port.. good ip is $goodip, ip is $ip....................................");
|
|
|
|
my $rc = system("ping -q -n -c 1 -w 1 $ip > /dev/null");
|
|
|
|
unless ($rc == 0) {
|
|
|
|
$ip = ${$iphashref->{$port}}{tip};
|
|
|
|
$handled{network} = $ip.",".${$rspdevref->{$ip}}{args};
|
|
|
|
my @cmds = ("network=$ip,${$rspdevref->{$ip}}{args}");
|
|
|
|
my %request = (
|
|
|
|
ppcretry => 1,
|
|
|
|
verbose => 0,
|
|
|
|
ppcmaxp => 64,
|
|
|
|
ppctimeout => 0,
|
|
|
|
fsptimeout => 0,
|
|
|
|
ppcretry => 3,
|
|
|
|
maxssh => 8,
|
|
|
|
arg => \@cmds,
|
|
|
|
method => \%handled,
|
|
|
|
command => 'rspconfig',
|
|
|
|
hwtype => ${$rspdevref->{$ip}}{type},
|
|
|
|
);
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "Begin to do reset for $port, nic is $ip");
|
|
|
|
my $result = xCAT::PPCfsp::handler($ip, \%request, \@exp, 1 );
|
|
|
|
if ($result) {
|
|
|
|
my $errcode = ${@$result[0]}{errorcode};
|
|
|
|
if ( $errcode == 0) {
|
2012-08-11 14:21:42 +00:00
|
|
|
$msginfo{$port} = "successful";
|
2012-08-11 11:06:49 +00:00
|
|
|
} else {
|
|
|
|
my $node = ${@$result[0]}{node};
|
|
|
|
$msginfo{$port} = @{${@{${@$node[0]}{data}}[0]}{contents}}[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msginfo{$port} = "failed with unknown reason";
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-24 01:55:11 +00:00
|
|
|
$msginfo{$port} = "successful";
|
2012-08-11 11:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($port) {
|
|
|
|
if ($port eq $portneedreset[0] ) {
|
|
|
|
$port = $portneedreset[1];
|
|
|
|
} else {
|
|
|
|
$port = $portneedreset[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$port = $portneedreset[0];
|
|
|
|
}
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "begin to reset for port $port......................................");
|
|
|
|
my $ip = ${$iphashref->{$port}}{sip};
|
|
|
|
my $rc = system("ping -q -n -c 1 -w 1 $ip > /dev/null");
|
|
|
|
unless ($rc == 0) { #should be unless!!!!!!!!!!!!!
|
|
|
|
$ip = ${$iphashref->{$port}}{tip};
|
|
|
|
$handled{network} = $ip.",".${$rspdevref->{$ip}}{args};
|
|
|
|
my @cmds = ("network=$ip,${$rspdevref->{$ip}}{args}");
|
|
|
|
my %request = (
|
|
|
|
ppcretry => 1,
|
|
|
|
verbose => 0,
|
|
|
|
ppcmaxp => 64,
|
|
|
|
ppctimeout => 0,
|
|
|
|
fsptimeout => 0,
|
|
|
|
ppcretry => 3,
|
|
|
|
maxssh => 8,
|
|
|
|
arg => \@cmds,
|
|
|
|
method => \%handled,
|
|
|
|
command => 'rspconfig',
|
|
|
|
hwtype => ${$rspdevref->{$ip}}{type},
|
|
|
|
);
|
|
|
|
xCAT::MsgUtils->verbose_message( $req, "Begin to do reset for $port, nic is $ip");
|
|
|
|
my $result = xCAT::PPCfsp::handler($ip, \%request, \@exp);
|
|
|
|
if ($result) {
|
|
|
|
my $errcode = ${@$result[0]}{errorcode};
|
|
|
|
if ( $errcode == 0) {
|
2012-08-11 14:21:42 +00:00
|
|
|
$msginfo{$port} = "successful";
|
2012-08-11 11:06:49 +00:00
|
|
|
} else {
|
|
|
|
my $node = ${@$result[0]}{node};
|
|
|
|
$msginfo{$port} = @{${@{${@$node[0]}{data}}[0]}{contents}}[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msginfo{$port} = "failed with unknown reason";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
xCAT::PPCfsp::disconnect( \@exp );
|
2012-08-24 01:55:11 +00:00
|
|
|
$msginfo{$port} = "successful";
|
2012-08-11 11:06:49 +00:00
|
|
|
}
|
2012-08-11 14:21:42 +00:00
|
|
|
return \%msginfo;
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
2012-07-01 03:11:25 +00:00
|
|
|
|
2012-04-06 03:33:56 +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');
|
|
|
|
my $ent = $passtab->getNodeAttribs('blade', ['username','password']);
|
|
|
|
if ( defined( $ent )) {
|
|
|
|
$bladeuser = $ent->{username};
|
|
|
|
$bladepass = $ent->{password};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#############################################
|
2012-07-01 03:11:25 +00:00
|
|
|
# Get userid/password
|
2012-04-06 03:33:56 +00:00
|
|
|
#############################################
|
|
|
|
my $mpatab = xCAT::Table->new('mpa');
|
|
|
|
for my $nd ( keys %$mm ) {
|
|
|
|
my $user = $bladeuser;
|
|
|
|
my $pass = $bladepass;
|
|
|
|
|
|
|
|
if ( defined( $mpatab )) {
|
|
|
|
#my ($ent) = $mpatab->getAttribs({mpa=>$_},'username','password');
|
|
|
|
my $ent = $mpatab->getNodeAttribs($nd, ['username','password']);
|
|
|
|
if ( defined( $ent->{password} )) { $pass = $ent->{password}; }
|
|
|
|
if ( defined( $ent->{username} )) { $user = $ent->{username}; }
|
|
|
|
}
|
|
|
|
$mm->{$nd}->{username} = $user;
|
|
|
|
$mm->{$nd}->{password} = $pass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (%$hmc )
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get HMC userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$hmc ) {
|
|
|
|
( $hmc->{$_}->{username}, $hmc->{$_}->{password}) = xCAT::PPCdb::credentials( $hmc->{$_}->{name}, lc($hmc->{$_}->{'type'}), "hscroot" );
|
2012-07-01 03:11:25 +00:00
|
|
|
xCAT::MsgUtils->verbose_message( $request, "user/passwd for $_ is $hmc->{$_}->{username} $hmc->{$_}->{password}");
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( %$fsp)
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get FSP userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$fsp ) {
|
|
|
|
( $fsp->{$_}->{username}, $fsp->{$_}->{password}) = xCAT::PPCdb::credentials( $fsp->{$_}->{name}, lc($fsp->{$_}->{'type'}), "admin");
|
2012-07-01 03:11:25 +00:00
|
|
|
xCAT::MsgUtils->verbose_message( $request, "user/passwd for $_ is $fsp->{$_}->{username} $fsp->{$_}->{password}");
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( %$bpa)
|
|
|
|
{
|
|
|
|
#############################################
|
|
|
|
# Get BPA userid/password
|
|
|
|
#############################################
|
|
|
|
foreach ( keys %$bpa ) {
|
|
|
|
( $bpa->{$_}->{username}, $bpa->{$_}->{password}) = xCAT::PPCdb::credentials( $bpa->{$_}->{name}, lc($bpa->{$_}->{'type'}), "admin");
|
2012-07-01 03:11:25 +00:00
|
|
|
xCAT::MsgUtils->verbose_message( $request, "user/passwd for $_ is $bpa->{$_}->{username} $bpa->{$_}->{password}");
|
2012-04-06 03:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (%$mm,%$hmc,%$fsp,%$bpa);
|
|
|
|
}
|
|
|
|
##########################################################################
|
|
|
|
# Invokes the callback with the specified message
|
|
|
|
##########################################################################
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##########################################################################
|
|
|
|
# Collect output from the child processes
|
|
|
|
##########################################################################
|
|
|
|
sub child_response {
|
|
|
|
|
|
|
|
my $callback = shift;
|
|
|
|
my $fds = shift;
|
|
|
|
my @ready_fds = $fds->can_read(1);
|
|
|
|
|
|
|
|
foreach my $rfh (@ready_fds) {
|
|
|
|
my $data = <$rfh>;
|
|
|
|
|
|
|
|
#################################
|
|
|
|
# Read from child process
|
|
|
|
#################################
|
|
|
|
if ( defined( $data )) {
|
|
|
|
while ($data !~ /ENDOFFREEZE6sK4ci/) {
|
|
|
|
$data .= <$rfh>;
|
|
|
|
}
|
|
|
|
my $responses = thaw($data);
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# rspconfig results
|
|
|
|
#############################
|
|
|
|
if ( @$responses[0] =~ /^RSPCONFIG6sK4ci$/ ) {
|
2012-08-11 11:06:49 +00:00
|
|
|
#shift @$responses;
|
|
|
|
#my $ip = @$responses[0];
|
|
|
|
#my @rsp1 = (@$responses[1]);
|
|
|
|
#$rsp_result{$ip} = \@rsp1;
|
|
|
|
#$ip = @$responses[2];
|
|
|
|
#if ($ip) {
|
|
|
|
# my @rsp2 = (@$responses[3]);
|
|
|
|
# $rsp_result{$ip} = \@rsp2;
|
|
|
|
#}
|
2012-04-06 03:33:56 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
#############################
|
|
|
|
# Message or verbose trace
|
|
|
|
#############################
|
|
|
|
foreach ( @$responses ) {
|
|
|
|
$callback->( $_ );
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
#################################
|
|
|
|
# Done - close handle
|
|
|
|
#################################
|
|
|
|
$fds->remove($rfh);
|
|
|
|
close($rfh);
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 08:51:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# Logon through remote FSP HTTP-interface
|
|
|
|
##########################################################################
|
|
|
|
sub connect {
|
|
|
|
|
2012-08-11 11:06:49 +00:00
|
|
|
my $username = shift;
|
|
|
|
my $passwd = shift;
|
2012-07-12 08:51:22 +00:00
|
|
|
my $server = shift;
|
2012-08-11 11:06:49 +00:00
|
|
|
my $verbose = shift;
|
2012-07-12 08:51:22 +00:00
|
|
|
my $lwp_log;
|
|
|
|
|
|
|
|
##################################
|
2012-08-24 01:55:11 +00:00
|
|
|
# Use timeout
|
2012-07-12 08:51:22 +00:00
|
|
|
##################################
|
2012-08-11 14:21:42 +00:00
|
|
|
my $timeout = 10;
|
2012-07-12 08:51:22 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Redirect STDERR to variable
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
close STDERR;
|
|
|
|
if ( !open( STDERR, '>', \$lwp_log )) {
|
|
|
|
return( "Unable to redirect STDERR: $!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$IO::Socket::SSL::VERSION = undef;
|
|
|
|
eval { require Net::SSL };
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Turn on tracing
|
|
|
|
##################################
|
|
|
|
if ( $verbose ) {
|
|
|
|
LWP::Debug::level( '+' );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# Create cookie
|
|
|
|
##################################
|
|
|
|
my $cookie = HTTP::Cookies->new();
|
|
|
|
$cookie->set_cookie( 0,'asm_session','0','cgi-bin','','443',0,0,3600,0 );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Create UserAgent
|
|
|
|
##################################
|
|
|
|
my $ua = LWP::UserAgent->new();
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Set options
|
|
|
|
##################################
|
|
|
|
my $url = "https://$server/cgi-bin/cgi?form=2";
|
|
|
|
$ua->cookie_jar( $cookie );
|
|
|
|
$ua->timeout( $timeout );
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Submit logon
|
|
|
|
##################################
|
|
|
|
my $res = $ua->post( $url,
|
2012-08-11 11:06:49 +00:00
|
|
|
[ user => $username,
|
|
|
|
password => $passwd,
|
2012-07-12 08:51:22 +00:00
|
|
|
lang => "0",
|
|
|
|
submit => "Log in" ]
|
|
|
|
);
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Logon failed
|
|
|
|
##################################
|
|
|
|
if ( !$res->is_success() ) {
|
|
|
|
return( $lwp_log.$res->status_line );
|
|
|
|
}
|
|
|
|
##################################
|
|
|
|
# To minimize number of GET/POSTs,
|
|
|
|
# if we successfully logon, we should
|
|
|
|
# get back a valid cookie:
|
|
|
|
# Set-Cookie: asm_session=3038839768778613290
|
|
|
|
#
|
|
|
|
##################################
|
|
|
|
if ( $res->as_string =~ /Set-Cookie: asm_session=(\d+)/ ) {
|
|
|
|
##############################
|
|
|
|
# Successful logon....
|
|
|
|
# Return:
|
|
|
|
# UserAgent
|
|
|
|
# Server hostname
|
|
|
|
# UserId
|
|
|
|
# Redirected STDERR/STDOUT
|
|
|
|
##############################
|
|
|
|
return( $ua,
|
|
|
|
$server,
|
2012-08-11 11:06:49 +00:00
|
|
|
$username,
|
2012-07-12 08:51:22 +00:00
|
|
|
\$lwp_log );
|
|
|
|
}
|
|
|
|
##############################
|
|
|
|
# Logon error
|
|
|
|
##############################
|
|
|
|
$res = $ua->get( $url );
|
|
|
|
##############################
|
|
|
|
# Check for specific failures
|
2012-08-24 01:55:11 +00:00
|
|
|
# $res->status_line is like "200 OK"
|
|
|
|
# $res->content is like <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" .....Too many users......</html>
|
|
|
|
# $res->base is like https://41.17.4.2/cgi-bin/cgi?form=2
|
2012-07-12 08:51:22 +00:00
|
|
|
##############################
|
2012-08-24 01:55:11 +00:00
|
|
|
my $err;
|
|
|
|
if ( $res->content =~ /Too many users/i ) {
|
|
|
|
$err = "Too many users";
|
2012-08-11 11:06:49 +00:00
|
|
|
}elsif ( $res->content =~ /Invalid user ID or password/i ) {
|
|
|
|
$err = "Invalid user ID or password";
|
|
|
|
}else{
|
|
|
|
$err = "Logon failure with unknown reason";
|
2012-07-12 08:51:22 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 11:06:49 +00:00
|
|
|
return ($lwp_log.$err);
|
2012-07-12 08:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-02 16:25:46 +00:00
|
|
|
1;
|
2008-05-27 13:53:53 +00:00
|
|
|
|