2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 11:42:05 +00:00

modify netcfg and add rinv and rvitals command

This commit is contained in:
Casandra Qiu 2017-09-14 09:50:44 -04:00
parent 1ab961f083
commit 555eef7794
3 changed files with 140 additions and 39 deletions

View File

@ -85,7 +85,9 @@ my %usage = (
OpenPOWER (OpenBMC) specific:
rvitals noderange [temp|voltage|wattage|fanspeed|power|altitude|all]
MIC specific:
rvitals noderange {thermal|all}",
rvitals noderange {thermal|all}"
pdu specific:
rvitals noderange ",
"reventlog" =>
"Usage: reventlog <noderange> [all [-s]|clear|<number of entries to retrieve> [-s]] [-V|--verbose]
reventlog [-h|--help|-v|--version]",

View File

@ -7,6 +7,7 @@
Supported command:
rpower
rinv
rvitals
=cut
@ -63,6 +64,7 @@ sub handled_commands
return {
rpower => ["nodehm:mgt","pduoutlet:pdu=\.\*"],
rinv => ["nodehm:mgt"],
rvitals => ["nodehm:mgt"],
nodeset => ["nodehm:mgt"],
rspconfig => ["nodehm:mgt"],
pdudiscover => "pdu",
@ -138,11 +140,13 @@ sub process_request
#fill in the total outlet count for each pdu
$pdutab = xCAT::Table->new('pdu');
@pduents = $pdutab->getAllNodeAttribs(['node', 'outlet']);
fill_outletCount(\@pduents, $callback);
#fill_outletCount(\@pduents, $callback);
if( $command eq "rinv") {
#for higher performance, handle node in batch
return powerstat($noderange, $callback);
return showMFR($noderange, $callback);
}elsif ($command eq "rvitals") {
return showMonitorData($noderange, $callback);
}elsif ($command eq "rpower") {
my $subcmd = $exargs[0];
if (($subcmd eq 'pduoff') || ($subcmd eq 'pduon') || ($subcmd eq 'pdustat')|| ($subcmd eq 'pdureset') ){
@ -178,6 +182,7 @@ sub process_request
if ($subcmd eq 'sshcfg') {
process_sshcfg($noderange, $subcmd, $callback);
}elsif ($subcmd =~ /ip|netmask|hostname/) {
print "prcess_netcfg\n";
process_netcfg($request, $subreq, $subcmd, $callback);
} else {
$callback->({ errorcode => [1],error => "The input $command $subcmd is not support for pdu"});
@ -495,6 +500,8 @@ sub process_netcfg {
my $ip;
my $netmask;
my $args;
my $ret;
my $err;
my $extrargs = $request->{arg};
my @exargs = ($request->{arg});
@ -503,18 +510,24 @@ sub process_netcfg {
}
my $nodes = $request->{node};
my $pdu = @$nodes;
my $rsp = {};
my $nodetab = xCAT::Table->new('hosts');
my $nodehash = $nodetab->getNodesAttribs($nodes,['ip','otherinterfaces']);
# connect to PDU
my $static_ip = $nodehash->{$pdu}->[0]->{ip};
my $discover_ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
my ($exp, $errstr) = session_connect($static_ip, $discover_ip);
foreach my $cmd (@exargs) {
my ($key, $value) = split(/=/, $cmd);
if ($key =~ /hostname/) {
$hostname = $value;
$args = "echo $hostname > /etc/hostname;/etc/init.d/hostname.sh";
xCAT::Utils->runxcmd({ command => ['xdsh'],
node => $nodes,
arg => [ $args ] }, $subreq, 0, 1);
if ($::RUNCMD_RC != 0) {
xCAT::SvrUtils::sendmsg("xdsh command to set hostname failed", $callback);
($ret, $err) = session_exec($exp, "echo $hostname > /etc/hostname;/etc/init.d/hostname.sh");
if (defined $err) {
xCAT::SvrUtils::sendmsg("Failed to set hostname", $callback);
}
}elsif ($key =~ /ip/) {
$ip = $value;
@ -537,11 +550,12 @@ sub process_netcfg {
my $dshcmd = $args . $opt ;
xCAT::SvrUtils::sendmsg($dshcmd, $callback);
#comment this for now, coralPDU on the lab is not support PduManager yet
my $output = xCAT::Utils->runxcmd({ command => ['xdsh'], node => $nodes, arg => [ $dshcmd ] }, $subreq, 0, 1);
if ($::RUNCMD_RC != 0) {
xCAT::SvrUtils::sendmsg("@$output", $callback);
($ret, $err) = session_exec($exp, $dshcmd);
if (defined $err) {
xCAT::SvrUtils::sendmsg("Failed to run $dshcmd", $callback);
}
}
$exp->hard_close();
}
#-------------------------------------------------------
@ -560,6 +574,7 @@ sub process_sshcfg {
my $subcmd = shift;
my $callback = shift;
#this is default password for CoralPDU
my $password = "password8";
my $userid = "root";
my $timeout = 10;
@ -580,20 +595,7 @@ sub process_sshcfg {
my $static_ip = $nodehash->{$pdu}->[0]->{ip};
my $discover_ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
my $ssh_ip;
my $p = Net::Ping->new();
if ($p->ping($static_ip)) {
$ssh_ip = $static_ip;
} elsif ($p->ping($discover_ip)) {
$ssh_ip = $discover_ip;
} else {
$msg = " is not reachable";
xCAT::SvrUtils::sendmsg($msg, $callback, $pdu, %allerrornodes);
next;
}
my ($exp, $errstr) = session_connect($ssh_ip, $userid, $password, $timeout);
my ($exp, $errstr) = session_connect($static_ip, $discover_ip);
if (!defined $exp) {
$msg = " Failed to connect $errstr";
xCAT::SvrUtils::sendmsg($msg, $callback, $pdu, %allerrornodes);
@ -607,10 +609,6 @@ sub process_sshcfg {
($ret, $err) = session_exec($exp, "chmod 700 /home/root/.ssh");
($ret, $err) = session_exec($exp, "echo \"$rootkey\" >/home/root/.ssh/authorized_keys");
($ret, $err) = session_exec($exp, "chmod 644 /home/root/.ssh/authorized_keys");
#config dhcp ip address to static
if ($ssh_ip eq $discover_ip) {
# ($ret, $err) = session_exec($exp, "ifconfig eth0 $static_ip");
}
$exp->hard_close();
}
@ -619,14 +617,27 @@ sub process_sshcfg {
}
sub session_connect {
my $server = shift;
my $userid = shift;
my $password = shift;
my $timeout = shift;
my $static_ip = shift;
my $discover_ip = shift;
my $ssh = Expect->new;
my $command = 'ssh';
my @parameters = ($userid . "@" . $server);
#default password for coral pdu
my $password = "password8";
my $userid = "root";
my $timeout = 10;
my $ssh_ip;
my $p = Net::Ping->new();
if ($p->ping($static_ip)) {
$ssh_ip = $static_ip;
} elsif ($p->ping($discover_ip)) {
$ssh_ip = $discover_ip;
} else {
return(undef, " is not reachable\n");
}
my $ssh = Expect->new;
my $command = 'ssh';
my @parameters = ($userid . "@" . $ssh_ip);
$ssh->debug(0);
$ssh->log_stdout(0); # suppress stdout output..
@ -717,6 +728,94 @@ sub process_pdudiscover {
xCAT::MsgUtils->message("I", $rsp, $callback);
}
#-------------------------------------------------------
=head3 showMFR
show MFR information of PDU via PduManager command
PduManager is a tool for CoralPdu to manager the PDU.
* /dev/shm/bin/PduManager -h
'-m' show MFR info
example: rinv coralpdu
=cut
#-------------------------------------------------------
sub showMFR {
my $noderange = shift;
my $callback = shift;
my $output;
my $nodetab = xCAT::Table->new('hosts');
my $nodehash = $nodetab->getNodesAttribs($noderange,['ip','otherinterfaces']);
foreach my $pdu (@$noderange) {
# connect to PDU
my $static_ip = $nodehash->{$pdu}->[0]->{ip};
my $discover_ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
my ($exp, $errstr) = session_connect($static_ip, $discover_ip);
if (defined $errstr) {
xCAT::SvrUtils::sendmsg("Failed to connect: $errstr", $callback);
}
my ($ret, $err) = session_exec($exp, "/dev/shm/bin/PduManager -m");
if (defined $err) {
xCAT::SvrUtils::sendmsg("Failed to list MFR information: $err", $callback);
}
if (defined $ret) {
xCAT::SvrUtils::sendmsg("$ret", $callback);
}
$exp->hard_close();
}
}
#-------------------------------------------------------
=head3 showMonitorData
Show realtime monitor data(input voltage, current, power)
of PDU via PduManager command
PduManager is a tool for CoralPdu to manager the PDU.
* /dev/shm/bin/PduManager -h
'-d' show realtime monitor data(input voltage, current, power)
example: rvitals coralpdu
=cut
#-------------------------------------------------------
sub showMonitorData {
my $noderange = shift;
my $callback = shift;
my $output;
my $nodetab = xCAT::Table->new('hosts');
my $nodehash = $nodetab->getNodesAttribs($noderange,['ip','otherinterfaces']);
foreach my $pdu (@$noderange) {
# connect to PDU
my $static_ip = $nodehash->{$pdu}->[0]->{ip};
my $discover_ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
my ($exp, $errstr) = session_connect($static_ip, $discover_ip);
my $ret;
my $err;
($ret, $err) = session_exec($exp, "/dev/shm/bin/PduManager -d");
if (defined $err) {
xCAT::SvrUtils::sendmsg("Failed to show monitor data: $err", $callback);
}
if (defined $ret) {
xCAT::SvrUtils::sendmsg("$ret", $callback,$pdu);
}
$exp->hard_close();
}
}
1;

View File

@ -1452,14 +1452,14 @@ sub switchsetup {
foreach my $pdu(@{${nodes_to_config}->{$mytype}}) {
my $cmd = "rspconfig $pdu sshcfg";
xCAT::Utils->runcmd($cmd, 0);
my $ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
my $ip = $nodehash->{$pdu}->[0]->{ip};
my $mask;
foreach my $net (@nets) {
if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) {
$mask=$net->{'mask'};
}
}
$cmd = "rspconfig $pdu hostname=$pdu ip=$otherinterfaces netmask=$mask";
$cmd = "rspconfig $pdu hostname=$pdu ip=$ip netmask=$mask";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC == 0) {
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$pdu,"ip=$ip","otherinterfaces="] }, $sub_req, 0, 1);