First code drop for CRHS-like function. Only mkconn is available (without man page). Updated PPC.pm, PPCcli.pm, Usage.pm, hmc.pm, fsp.pm. Added bpa.pm, PPCconn.pm

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3411 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
zhanx 2009-05-20 09:04:19 +00:00
parent 2ce463ab83
commit e24e85831f
8 changed files with 362 additions and 7 deletions

View File

@ -67,6 +67,14 @@ my %lsrefcode = (
lpar =>"lsrefcode -r lpar -m %s --filter lpar_ids=%s",
);
##############################################
# mksysconn support formats
##############################################
my %mksysconn = (
fsp => "mksysconn --ip %s -r sys --passwd %s",
bpa => "mksysconn --ip %s -r frame --passwd %s"
);
##########################################################################
# Logon to remote server
##########################################################################
@ -1137,6 +1145,20 @@ sub network_reset {
}
##########################################################################
# Create connection for CEC/BPA
##########################################################################
sub mksysconn
{
my $exp = shift;
my $ip = shift;
my $type = shift;
my $passwd = shift;
my $cmd = sprintf( $mksysconn{$type}, $ip, $passwd);
my $result = send_cmd( $exp, $cmd);
return ( $result);
}
1;

241
perl-xCAT/xCAT/PPCconn.pm Normal file
View File

@ -0,0 +1,241 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::PPCconn;
use strict;
use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
##############################################
# Globals
##############################################
my %method = (
mkconn => \&mkconn_parse_args,
lsconn => \&lsconn_parse_args,
rmconn => \&rmconn_parse_args,
chconn => \&chconn_parse_args
);
##########################################################################
# Parse the command line for options and operands
##########################################################################
sub parse_args {
my $request = shift;
my $cmd = $request->{command};
###############################
# Invoke correct parse_args
###############################
my $result = $method{$cmd}( $request, $request->{arg});
return( $result );
}
##########################################################################
# Parse arguments for mkconn
##########################################################################
sub mkconn_parse_args
{
my $request = shift;
my $args = shift;
my %opt = ();
local *usage = sub {
my $usage_string = xCAT::Usage->getUsage("mkconn");
return( [ $_[0], $usage_string] );
};
#############################################
# Process command-line arguments
#############################################
if ( !defined( $args )) {
return(usage( "No command specified" ));
}
local @ARGV = @$args;
$Getopt::Long::ignorecase = 0;
Getopt::Long::Configure( "bundling" );
if ( !GetOptions( \%opt, qw(V|verbose t p=s P=s) )) {
return( usage() );
}
if ( exists $opt{t} and exists $opt{p})
{
return( usage('Flags -t and -p cannot be used together.'));
}
if ( exists $opt{P} and ! exists $opt{p})
{
return( usage('Flags -P can only be used when flag -p is specified.'));
}
##########################################
# Check if CECs are controlled by a frame
##########################################
my $nodes = $request->{node};
my $ppctab = xCAT::Table->new( 'ppc' );
my $nodetypetab = xCAT::Table->new( 'nodetype');
my @bpa_ctrled_nodes = ();
my @no_type_nodes = ();
if ( $ppctab)
{
for my $node ( @$nodes)
{
my $node_parent = undef;
my $nodetype = undef;
my $nodetype_hash = $nodetypetab->getNodeAttribs( $node,[qw(nodetype)]);
my $node_parent_hash = $ppctab->getNodeAttribs( $node,[qw(parent)]);
$nodetype = $nodetype_hash->{nodetype};
$node_parent = $node_parent_hash->{parent};
if ( !$nodetype)
{
push @no_type_nodes, $node;
next;
}
if ( $nodetype eq 'fsp' and
$node_parent and
$node_parent ne $node)
{
push @bpa_ctrled_nodes, $node;
}
}
}
if (scalar(@no_type_nodes))
{
my $tmp_nodelist = join ',', @no_type_nodes;
return ( usage("Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist"));
}
if (scalar(@bpa_ctrled_nodes))
{
my $tmp_nodelist = join ',', @bpa_ctrled_nodes;
return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA."));
}
$request->{method} = 'mkconn';
return( \%opt);
}
sub lsconn_parse_args
{
}
sub chconn_parse_args
{
}
sub rmconn_parse_args
{
}
##########################################################################
# Create connection for CECs/BPAs
##########################################################################
sub mkconn
{
my $request = shift;
my $hash = shift;
my $exp = shift;
my $hwtype = @$exp[2];
my $opt = $request->{opt};
my @value = ();
my $Rc = undef;
for my $cec_bpa ( keys %$hash)
{
my $node_hash = $hash->{$cec_bpa};
my ($node_name) = keys %$node_hash;
my $d = $node_hash->{$node_name};
############################
# Get IP address
############################
my $hosttab = xCAT::Table->new( 'hosts' );
my $node_ip = undef;
if ( $hosttab)
{
my $node_ip_hash = $hosttab->getNodeAttribs( $node_name,[qw(ip)]);
$node_ip = $node_ip_hash->{ip};
}
if (!$node_ip)
{
my $ip_tmp_res = xCAT::Utils::toIP($node_name);
($Rc, $node_ip) = @$ip_tmp_res;
if ( $Rc )
{
push @value, [$node_name, $node_ip, $Rc];
next;
}
}
my ( undef,undef,undef,undef,$type) = @$d;
my ($user, $passwd) = xCAT::PPCdb::credentials( $node_name, $type);
my $res = xCAT::PPCcli::mksysconn( $exp, $node_ip, $type, $passwd);
$Rc = shift @$res;
push @value, [$node_name, @$res[0], $Rc];
}
return \@value;
}
sub preprocess_nodes
{
my $request = shift;
my $nodes = $request->{ node};
my @hmc_group = ();
my %tabs = ();
my %nodehash = ();
if ( exists $request->{opt}->{p})
{
my $hcp = $request->{opt}->{p};
push @hmc_group, $hcp;
if ( ! exists $request->{$hcp}->{cred})
{
my @cred = xCAT::PPCdb::credentials( $hcp, 'hmc');
$request->{$hcp}->{cred} = \@cred;
}
}
else
{
foreach ( qw(ppc vpd nodetype) )
{
$tabs{$_} = xCAT::Table->new($_);
if ( !exists( $tabs{$_} ))
{
xCAT::PPC::send_msg( $request, 1, sprintf( "'%s' database not defined", $_ ));
return undef;
}
}
for my $node ( @$nodes)
{
my $d = xCAT::PPC::resolve( $request, $node, \%tabs );
######################################
# Error locating node attributes
######################################
if ( ref($d) ne 'ARRAY' )
{
xCAt::PPC::send_msg( $request, 1, "$node: $d");
next;
}
######################################
# Get data values
######################################
my $hcp = @$d[3];
my $mtms = @$d[2];
##########################################
# Get userid and password
##########################################
if ( ! exists $request->{$hcp}{cred})
{
my @cred = xCAT::PPCdb::credentials( $hcp, 'hmc');
$request->{$hcp}{cred} = \@cred;
}
while (my ($hcp,$hash) = each(%nodehash) ) {
push @hmc_group,[$hcp,$hash];
}
}
}
return \@hmc_group;
}
1;

View File

@ -133,7 +133,13 @@ my %usage = (
"rflash" =>
"Usage: rflash [ -h|--help|-v|--version]
rflash <noderange> -p directory [--activate concurrent | disruptive][-V|--verbose]
rflash <noderange> [--commit | --recover] [-V|--verbose]"
rflash <noderange> [--commit | --recover] [-V|--verbose]",
"mkconn" =>
"Usage:
mkvm [-h|--help]
mkconn noderange -t [--bind] [-V|--verbose]
mkconn noderange -p single_hmc [-P fsp/bpa passwd] [-V|--verbose]",
);
my $vers = xCAT::Utils->Version();
my %version = (

View File

@ -170,6 +170,9 @@ ln -sf ../bin/xcatDBcmds $RPM_BUILD_ROOT/%{prefix}/bin/rmdef
ln -sf ../bin/xcatDBcmds $RPM_BUILD_ROOT/%{prefix}/bin/xcat2nim
ln -sf ../bin/xdsh $RPM_BUILD_ROOT/%{prefix}/bin/xdcp
ln -sf ../bin/xcatclientnnr $RPM_BUILD_ROOT/%{prefix}/sbin/mknb
ln -sf ../bin/xcatclient $RPM_BUILD_ROOT/%{prefix}/bin/mkconn
ln -sf ../bin/xcatclient $RPM_BUILD_ROOT/%{prefix}/bin/rmconn
ln -sf ../bin/xcatclient $RPM_BUILD_ROOT/%{prefix}/bin/lsconn
%clean
# This step does not happen until *after* the %files packaging below

View File

@ -34,7 +34,10 @@ my %modules = (
getmacs => "xCAT::PPCmac",
reventlog => "xCAT::PPClog",
rspconfig => "xCAT::PPCcfg",
rflash => "xCAT::PPCrflash"
rflash => "xCAT::PPCrflash",
mkconn => "xCAT::PPCconn",
rmconn => "xCAT::PPCconn",
lsconn => "xCAT::PPCconn"
);
##########################################
@ -549,7 +552,9 @@ sub preprocess_nodes {
######################################
my $hcp = @$d[3];
my $mtms = @$d[2];
######################################
# Special case for rflash
######################################
if ( $request->{command} eq "rflash" ) {
if(@$d[4] =~/^(fsp|lpar)$/) {
$f1 = 1;
@ -565,8 +570,21 @@ sub preprocess_nodes {
}
}
$nodehash{$hcp}{$mtms}{$node} = $d;
######################################
# Special case for mkconn
######################################
if ( $request->{command} eq "mkconn" and
exists $request->{opt}->{p})
{
$nodehash{ $request->{opt}->{p}}{$mtms}{$node} = $d;
}
######################################
#The common case
######################################
else
{
$nodehash{$hcp}{$mtms}{$node} = $d;
}
}
if($f1 * $f2) {

View File

@ -0,0 +1,59 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT_plugin::bpa;
use strict;
use xCAT::PPC;
##########################################################################
# Command handler method from tables
##########################################################################
sub handled_commands {
return {
rspconfig => 'nodehm:mgt',
mkconn => 'nodehm:mgt',
rmconn => 'nodehm:mgt',
chconn => 'nodehm:mgt'
};
}
##########################################################################
# Pre-process request from xCat daemon
##########################################################################
sub preprocess_request {
#######################################################
# IO::Socket::SSL apparently does not work with LWP.pm
# When used, POST/GETs return immediately with:
# 500 Can't connect to <nodename>:443 (Timeout)
#
# Net::HTTPS, which is used by LWP::Protocol::https::Socket,
# uses either IO::Socket::SSL or Net::SSL. It chooses
# by looking to see if $IO::Socket::SSL::VERSION
# is defined (i.e. the module's already loaded) and
# uses that if so. If not, it first tries Net::SSL,
# then IO::Socket::SSL only if that cannot be loaded.
# So we should invalidate IO::Socket::SSL here and
# load Net::SSL.
#######################################################
$IO::Socket::SSL::VERSION = undef;
eval { require Net::SSL };
if ( $@ ) {
my $callback = $_[1];
$callback->( {errorcode=>1,data=>[$@]} );
return(1);
}
xCAT::PPC::preprocess_request(__PACKAGE__,@_);
}
##########################################################################
# Process request from xCat daemon
##########################################################################
sub process_request {
xCAT::PPC::process_request(__PACKAGE__,@_);
}
1;

View File

@ -12,7 +12,10 @@ sub handled_commands {
return {
rpower => 'nodehm:power,mgt',
reventlog => 'nodehm:mgt',
rspconfig => 'nodehm:mgt'
rspconfig => 'nodehm:mgt',
mkconn => 'nodehm:mgt',
rmconn => 'nodehm:mgt',
chconn => 'nodehm:mgt'
};
}

View File

@ -21,7 +21,10 @@ sub handled_commands {
getmacs => 'nodehm:mgt',
rnetboot => 'nodehm:mgt',
rspconfig => 'nodehm:mgt',
rflash => 'nodehm:mgt'
rflash => 'nodehm:mgt',
mkconn => 'nodehm:mgt',
rmconn => 'nodehm:mgt',
chconn => 'nodehm:mgt'
};
}