2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 11:42:05 +00:00
Bin Xu eea661e405 merge from master to 2.13 branch for 2.13.9 release. (1) (#4525)
* fix issueNode range not specified, see man page for syntax. return with no output when site.master is not set #4299

* Fix issue 4246, record rflash process in log file

* dodiscovery: better disksize - ordered by major,minor and no `\n` (#4219)

* better disksize: ordered by major,minor and no `\n`

* nodediscover:`disksize` sent correctly: no need to `split`,`join`

* general sort with explicit key columns, fix search pattern

* dodiscovery: Fix bugs

* dodiscovery: Fix ShellCheck SC2007,SC2004

* dodiscovery: simpler kcmdline parsing, disksize as IEC binary prefix

* Add test case - switch_to_dns_forward_mode

* Modify timeout of login by curl command for OpenBMC

* Add makegocons command

This patch enable goconserver service and manage the node sessions
with a new `makegocons` command.

Implement: #4215

* Refine the Cumulus Linux Section of the Doc (#4249)

* No content in the switches subdirectory in docs, remove

* Change the Network topic to Networking

* Refine and reformat the Cumulus Linux documentation

* Modify the script to build xCAT-genesis-base package (#4292)

* Verify hash ID

* change log messages

* Timeout the ntpd process if ntpd service is not running on ntpserver (#4321)

* enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP (#3995)

* enhance nodediscovery process, if only 1 mac and have \*NOIP\* append, don't write mac table and don't generate dhcp lease entry

* Enhance PR 3995: enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP

* modified depending on comments

* natural_sort_cmp: recursion to iterative implementation (#4314)

* natural_sort_cmp: recursion to iterative implementation

* natural_sort_cmp: correct prototype with parameters, as per `man perlfunc`

* Task 3339, rspconfig ip/netmask/gateway/vlan support

*   * Minor enhance on xcatperftest to put all logs into one file
  * Fix a bug in simulatorctl.sh, and it cause the script cannot be found

* modified depending on comments

* QA list for makehosts (#4284)

* QA list for makehosts

* Fix some bus in makegocons

* Revise test case - switch_to_dns_forward_mode

* Enhancements after the review

* Use IO::Socket to check BMC console port

* Revise test case - switch_to_dns_forward_mode

* modified depending on comments

* Add messages to inform the user of the general action started via xCAT for flashing firmware

* Fix bug, anything in the functional array is the one that's really active, priority will not be 0 if there is pending firmware

* Fix 4338, remove all of  in child process

* fix issue #4354 :The XCATTEST_CN in xcattest can not detect HCP as config file (#4355)

* Fix #4330, close the socket

* Add image name to /opt/xcat/xcatinfo on compute node (#4359)

* Integrate congo console from goconserver with rcons

Enhance the original implement of rcons to support goconserver.
`rcons` will help the user choose from one of the console backend
service based on the console server status of management node.

Implement #4216

* Fix 4363 - discovery broken (#4364)

* do not set exit_code to 1 when the clock is not synced before the timeout (#4362)

* Fix check for MTM values with spaces

* modified depending on comments

* rspconfig admin_password for OpenBMC

* Fix merging in xdcpmerge.sh (#4328)

* Fixes in xdcpmerge.sh

Two fixes:
1. The grep pattern when finding duplicate usernames is missing ":" at the end. So, for example user "test" would also match "test2, etc.". Adding the ":" delimiter fixes the issue.
2. Another issue happens when the file to be merged is a superset of the files on the nodes. For example, if a new user is added and entire passwd file (that is otherwise identical) is sent to be merged. In this case, the $filebackup.nodups file, i.e. the original file with duplicates removed, becomes empty and the condition "if [ -s "$filebackup.nodups" ]" does not execute. Then the merged file ends up being original file with the merge file fully appended, clearly not what was intended.

This is solved by changing the condition to check for file existence "-a" rather then for size. Additionally, I also turn the logic around so that the duplicates are removed from the merge file and then added to the original file. I think this makes logic a bit cleaner and also ensures that existing entries are not reordered or changed in any way.

* Streamlining previous commit

Adjustment to previous commit, streamlining and simplifying logic. Once $mergefile.nodups is created, just concatenate it the original file.

* Update to xdcpmerge

No need to copy $filebackup to $curfile, they are the same.

* Modify for debug conveniently

* add new cases and delete outdated test cases

* Modify genesis build script for centos x86_64

* Add space between at and the time

* Add a print out of the firmware levels for the various UT cases

* Add unit test cases for rspconfig

* rspconfig fix for set hostname

* Enhance the testing case for rspconfig setting hostname

* modified depending on comments

* modified depending on comments

* Add %pretrans script in <lua>. Handle directory to symlink change properly. See comment #3 of https://bugs.launchpad.net/rpm/+bug/633636

* Make xCAT-genesis-base confliects with early version of xCAT-genesis-scripts

* rspconfig dump to allow admins capture logs

* Adding comment

* Improve the error message when BMC does not return a dump ID

* Improve some messages and add timestamp for downloaded dump file

* Improve the message to help Admin figure out where the file is missing

* Leave a log file there when xCAT upgrade in case to debug issue while upgrading (#4389)

* Listen on 0.0.0.0 instead of the hostname

This patch modify the configuration of `makegocons` and `rcons`
for goconserver.

`cat /etc/goconserver/server.conf`
```
global:
  host: 0.0.0.0
  ssl_key_file: /etc/xcat/cert/server-key.pem
  ssl_cert_file: /etc/xcat/cert/server-cert.pem
  ssl_ca_cert_file: /etc/xcat/cert/ca.pem
  logfile: /var/log/goconserver/server.log
api:
  port: 12429
console:
  port: 12430
```

* Support hostname=* for openbmc

* Relay action and snmp configuration support for Coral PDU

* ddns.pm: specify the "directory" option for DNS slaves too (cf. bug #4392)

* Fix issue 4361, modify some sendmsg to message

* 1. add "makeconserver -d" to "rmdef -C", 2. add "makeconserver -C|--cleanup" to remove entries for removed nodes

* When there is a problem with the login, do not hide the message on debug mode. BMCReady does not make sense if the admin does not know how to find that state

* Change function from login_logout_request to login_request, not doing any logout here

* Check that RC is 200 to prevent unknown issues, handle the response generically

* OpenBMC rspconfig dump timeout fixes

* Fix issue 4408, modify error for rspconfig dump

* Clear all BMC Dump logs when BMC firmware flash

* modified depending on comments

* More modifications for pr 4386, to deal with the conflicts

* To handle one case which have 2 implementations, which one is for specific platform, on is for all platforms

* return when current status is RSPCONFIG_DUMP_DOWNLOAD_REQUEST

* fix issue 4417, delete 'clear next_status'

* fix issue 4353: rspconfig needs to support multiple IPs on the BMC and ignore ZeroConfigIPs

* Wait 15 seconds after OpenBMC interface with vlan tag to be activated

* Fix issue #4397: rspconfig <> hostname=xxx show error message when there is multiple network in bmc

* Some sentence modify for makeconservercf -C|--cleanup

* OpenBMC rspconfig dump better dump file name formatting

* Removed the --check and --ipsource option with PR 4258, update the man page

* Improve the message on the HTTP response

* modified depending on comments

* Only handle 404 and 504 in the login request code, defer the rest to deal_with_response()

* rflash stream support

* 1. configure ip/netmask/gateway only on the NIC whose IP match node BMC attribute, 2. add some information for LinkLocal address

* Fix confignetwork bond nic_type detection with multiple bonds

* Modified configonie --ntp command (#4436)

* Add man page for makegocons

This is the guide about how to make goconserver as
a replacement for conserver to help slove the issues reported
for conserver, like: #4043, #3543. For openbmc, the solution of
goconserver is much light-weighted than the conserver which could
help save the system resource. In addition, sshpass is not needed
for openbmc with goconserver.

Implement: #4337

* Add another key for node_info in order not to after the content of $node_info{$node}{bmc}

* enhance rflash stream

* makedhcp does not work well when all service nodes not running dhcp but disjointdhcps=1 (#4426) (#4440)

- if all service nodes not running dhcp, to treat it as disjointdhcps=0
- nodeset will send request to MN by default even if disjointdhcps=1
- Move out of the dhcp service checking from opts pre-check, and do it just before real makedhcp handling.

* rspconfig configure bmc vlan will hung because of PR 4383

* OpenBMC rspconfig dump enhancements

* Changes due to review comments

* Print debug message before login attempt

* Add warning when xCAT throttles SSL connections

* Display first [openbmc_debug] when entering openbmc.pm

* modified error msg

* Make sure credential files have a trailing newline (#4442)

* modified depending on comments

* Fix the typo in the man page of makegocons

* Update the print out based on the review comment, should not use  since the regular expression is removed

* Modify the nodeset disjoint test case accordingly for #4426

* Use short hostname in rcons for goconserver

As the certificate of xcat is signed with short hostname, this
commit force to use the short hostname in  the environment variable for
`congo console`.

* Fix issue 3497, make sense for reventlog msg

* Give summary after flash active when no debugmode

* Fix the issue that the IP configuration will fail if bmc attribute is a hostname

* enhance genimage for sles12sp2 (#4450)

* Add dhcp-client-identifier to lease block (#4429)

Machines that use Infiniband for PXE booting need to have the
dhcp-client-identifier set in the lease block.
Without it, they will not get the lease from the server.

* Support multiple bonds on bring-up

* modified depending on comments

* fix the check for rc to 1 on error cases

* modify response for bmcdiscover when error

* Ignore syslog error in monitorctrl when setNodeStatusAttributes (#4459)

* fix issue https://github.com/xcat2/xcat-core/issues/4411 (#4462)

* fix issue Compute nodes fail to get provisioned #4411: covert imgsrv and xcatmaster to their ip addresses in case the hostname cannot be resolved inside initrd for diskless

* More strict check to tell if it is a chroot env to avoid modify DB (#4463)

when genimage for SN image (#4365)

* issues for install license file on accton switches (#4460)

* Add test cases for rflash regular usage against openbmc

* modify depending on xuwei's comment

* add 2 more cases for option d

* enhance rflash upload message

* Do not display message for clearing dumps when only PNOR

* Display hostname even if multiple IP addresses

* modified depending on comments

* polished message

* Modify the default consoleondemand based on the global setting

This commit fix the bug that consoleondemand works incorrectly.

* modify depending on comments

* modified depending on comments

* enhance rflash error messages

* Modify documenation for servicenode attributes

* build rst file from Schema.pm by db2man

* change status back to starts

* modified depending on comments

* rm openbmcevents

* Usage and man page update for rspconfig dump

* let rflash error message flexible

* Add support for the "file -> (noderange) file" syntax in synclist with ServiceNodes (#4445)

* Add support for "file -  (noderange) file" in synclist when using
hierarchical mode. Fixes #4425

  This patch ensures that:
  1. the synclist is correctly parsed when running on a Service Node
  2. all files are synchronized to SNs in hierarchical mode

* Better test condition for #4425, addresses issue in
https://github.com/xcat2/xcat-core/pull/4445#issuecomment-349472901

* Fix issue 4477, if has node-<mac> will not create node-<mtms> for the same node

* fix issue updatenode -f loses directories when copying files to SN #4456 (#4494)

* comment from ErTao

* Crude attempt at including external configuration files in named.conf

* Fixes after the review

* Fix issue 4490, record any error when rflash active process

* add -d usage and manpage

* updatenode -F not work in hierachy env as the user name is FQDN of MN (#4484)

* updatenode -F not work in hierachy env (#4455)
 - add trace when -V is enabled
 - get the DSH_FROM_USERID from updatenode client

*  - when 'updatenode -F' need to push SN first, using root as non-root does not have permission write to 'SNsyncfiledir'
 - move the set DSH_FROM_USERID code out of the loop, and also cover remote client case.

* fix issue for command rspconfig hostname=*

* enhance rflash

* Adjust the server used for kernel/initrd and imgurl for petitboot (#4416)
 - URL for kernel/initrd, get the value from below value tftpserver -> xcatmaster -> myipfn
 - URL for image, get the value from below value nfsserver -> tftpserver -> xcatmaster -> myipfn

* NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot (#4428)

* NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot

* Get NODE from mypostscripts

* Improve the output message for reventlog, use a global variable to set PolicyFile Path

* If debug_msg is not provided, use an empty string

* Check for LinkLocal as well as 169.254 IP address

* Fix issue 4507, add parameter check for rspconfig admin_passwd

* record more information when rflash upload error

* Fix the error when using array ref in updatenode with old version perl, it is introduced by PR#4484 (#4518)

* Do not restart conserver if goconserver was started

If goconserver was enabled, do not start conserver when restart
xcatd on service node.

* remove the /etc/localtime before copy timezone file

* Use CONGO_CLIENT_TYPE to tell goconserver the source of client (#4501)

goconserver could send back message based on the client type
this commit set CONGO_CLIENT_TYPE to xcat to make the message
from goconserver more friendly.

* add rflash -d doc

* only ignore 169.254.x.x for OpenBMC

* Fix issue 4513, print out better error msg for reventlog -s

* Modify or add openbmc test cases or bundle

* add test cases for updatenode -f/F in hierarchy environment, covers issues #4456,#4455 and PR #4425 (#4500)
2017-12-14 05:03:34 -06:00

2010 lines
63 KiB
Perl
Executable File

#!/usr/bin/env perl
#
# © Copyright 2009 Hewlett-Packard Development Company, L.P.
# EPL license http://www.eclipse.org/legal/epl-v10.html
#
# Revision history:
# July, 2010 vallard@sumavi.com comments added.
# August, 2009 blade.pm adapted to generate hpblade.pm
#
package xCAT_plugin::hpblade;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
use strict;
use xCAT::Table;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::ServiceNodeUtils;
use xCAT::Usage;
use IO::Socket;
use Thread 'yield';
use Storable qw(freeze thaw);
use XML::Simple;
use Net::SSLeay qw(die_now die_if_ssl_error);
use Data::Dumper;
use POSIX "WNOHANG";
use Getopt::Long;
#use xCAT::hpoa; # require this dynamically below instead
sub handled_commands {
return {
findme => 'blade',
getmacs => 'nodehm:getmac,mgt',
rscan => 'nodehm:mgt',
rpower => 'nodehm:power,mgt',
gethpbladecons => 'hpblade',
getrvidparms => 'nodehm:mgt',
rvitals => 'nodehm:mgt',
rinv => 'nodehm:mgt',
rbeacon => 'nodehm:mgt',
rspreset => 'nodehm:mgt',
rspconfig => 'nodehm:mgt',
rbootseq => 'nodehm:mgt',
reventlog => 'nodehm:mgt',
switchblade => 'nodehm:mgt',
};
}
my $hpoa;
my $activeOABay;
my $slot;
my ($username, $password);
my %mm_comm_pids;
my %macmap; #Store responses from rinv for discovery
my $macmaptimestamp; #reflect freshness of cache
my %oahash;
my $curn;
my $oa;
my $getBladeStatusResponse; # Make this a global here so we can re-use the result
my $status_noop = "XXXno-opXXX";
my $eventHash;
my $globalDebug = 0;
my $ctx;
my @cfgtext;
my %bootdevices = (
0 => 'IPL_NO_OP',
1 => 'CD',
2 => 'FLOPPY',
3 => 'USB',
4 => 'HDD',
5 => 'PXE_NIC1',
6 => 'PXE_NIC2',
7 => 'PXE_NIC3',
8 => 'PXE_NIC4'
);
my %bootnumbers = (
'none' => 0,
'c' => 1,
'cd' => 1,
'dvd' => 1,
'cdrom' => 1,
'dvdrom' => 1,
'f' => 2,
'floppy' => 2,
'usb' => 3,
'usbflash' => 3,
'flash' => 3,
'h' => 4,
'hd' => 4,
'hdd' => 4,
'hd0' => 4,
'harddisk' => 4,
'eth0' => 5,
'nic1' => 5,
'net1' => 5,
'net' => 5,
'n' => 5,
'pxe_nic1' => 5,
'eth1' => 6,
'nic2' => 6,
'net2' => 6,
'pxe_nic2' => 6,
'eth2' => 7,
'nic3' => 7,
'net3' => 7,
'pxe_nic3' => 7,
'eth3' => 8,
'nic4' => 8,
'net4' => 8,
'pxe_nic4' => 8
);
my @rscan_attribs = qw(nodetype name id mtm serial mpa groups mgt);
my @rscan_header = (
[ "type", "%-8s" ],
[ "name", "" ],
[ "id", "%-8s" ],
[ "type-model", "%-12s" ],
[ "serial-number", "%-15s" ],
[ "address", "%s\n" ]);
sub waitforack {
my $sock = shift;
my $select = new IO::Select;
$select->add($sock);
my $str;
if ($select->can_read(10)) { # Continue after 10 seconds, even if not acked...
if ($str = <$sock>) {
} else {
$select->remove($sock); #Block until parent acks data
}
}
}
# Login to the OA using credentials found in the database.
sub oaLogin {
my $oaName = shift;
my $result = "";
my $hopa = "";
my $errHash;
# we need to get the info on the OA. If the specfied OA is NOT the
# ACTIVE OA then we return failure because we can't get the desired
# info from a STANDBY OA.
my ($username, $passwd, $encinfo);
my $mpatab = xCAT::Table->new('mpa');
my $ent;
if (defined($mpatab)) {
($ent) = $mpatab->getAttribs({ 'mpa' => $oaName }, 'username', 'password');
if (defined($ent->{password})) { $password = $ent->{password}; }
if (defined($ent->{username})) { $username = $ent->{username}; }
}
$hpoa = xCAT::hpoa->new('oaAddress' => $oaName);
my $loginResponse = $hpoa->userLogIn('username' => $username, 'password' => $password);
if ($loginResponse->fault) {
$errHash = $loginResponse->fault;
print Dumper($errHash);
$result = $loginResponse->oaErrorText;
if ($loginResponse->fault) {
return (1, "Error on login attempt");
}
}
my $response = $hpoa->getEnclosureInfo();
if ($response->fault) {
return (1, "Error on get Enclosure Info call");
}
my $numOABays = $response->result->{oaBays};
# OK We now know how many oaBays we have in this enclosure. Ask the OAs in each bay
# if they are active. If they are not, then leave since we can't get what we want
# from a standby OA
$activeOABay = 0;
for (my $oaBay = 1 ; $oaBay <= $numOABays ; $oaBay++) {
$response = $hpoa->getOaInfo(bayNumber => $oaBay);
if (!defined $response->result() || $response->result()->{oaRole} eq "OA_ABSENT" ||
$response->result->{youAreHere} eq "false") {
# either there is no OA here or this is not the one I am currently
# communicating with
next;
} elsif ($response->result->{youAreHere} eq "true") {
$activeOABay = $oaBay;
last;
}
}
if (!$activeOABay) {
return (1, "Cannot determine active OnBoard Administrator");
}
# Last thing. Need to determine if this is the active OA. If not, then we
# just tell the caller, and they can make the decision as to what they want
# to do.
$response = $hpoa->getOaStatus(bayNumber => $activeOABay);
if ($response->result->{oaRole} ne "ACTIVE") {
return (-1);
}
return ($hpoa);
}
sub oaLogout
{
my $hpoa = shift;
my $response = $hpoa->userLogOut();
}
sub convertSlot {
my $origSlot = shift;
if ($origSlot =~ /\D/) {
my $slotNum = $origSlot;
my $slotAlpha = $slotNum;
$slotNum =~ s/\D//;
$slotAlpha =~ s/\d//;
my $side;
if ($slotAlpha eq "a" or $slotAlpha eq "A") {
$side = 1;
} elsif ($slotAlpha eq "b" or $slotAlpha eq "B") {
$side = 2;
} else {
return (-1);
}
my $returnSlot = $side * 16 + $slotNum;
return ($returnSlot);
}
return ($origSlot);
}
sub gethpbladecons {
my $noderange = shift;
my $callback = shift;
my $mpatab = xCAT::Table->new('mpa');
my $passtab = xCAT::Table->new('passwd');
my $tmp;
my $user = "USERID";
if ($passtab) {
($tmp) = $passtab->getAttribs({ 'key' => 'blade' }, 'username');
if (defined($tmp)) {
$user = $tmp->{username};
}
}
my $mptab = xCAT::Table->new('mp');
my $mptabhash = $mptab->getNodesAttribs($noderange, [ 'mpa', 'id' ]);
foreach my $node (@$noderange) {
my $rsp = { node => [ { name => [$node] } ] };
my $ent = $mptabhash->{$node}->[0]; #$mptab->getNodeAttribs($node,['mpa', 'id']);
if (defined($ent->{mpa})) {
$oa = $ent->{mpa};
$slot = convertSlot($ent->{id});
if ($slot == 0) { # want to open a console on the OA
$rsp->{node}->[0]->{mm} = $oa;
} else {
$hpoa = oaLogin($oa);
my $mpInfoResp = $hpoa->getBladeMpInfo("bayNumber" => $slot);
if ($mpInfoResp->fault) {
$rsp->{node}->[0]->{error} = ["Error getting MP info"];
$rsp->{node}->[0]->{errorcode} = [1];
$callback->($rsp);
next;
}
my $ipaddress = $mpInfoResp->result->{ipAddress};
$rsp->{node}->[0]->{mm} = $ipaddress;
}
($tmp) = $mpatab->getAttribs({ 'mpa' => $oa }, 'username');
$user = [ $tmp->{username} ];
$rsp->{node}->[0]->{username} = $user;
} else {
$rsp->{node}->[0]->{error} = ["no mpa defined"];
$rsp->{node}->[0]->{errorcode} = [1];
$callback->($rsp);
next;
}
if (defined($ent->{id})) {
$rsp->{node}->[0]->{slot} = $ent->{id};
} else {
$rsp->{node}->[0]->{slot} = "";
}
$callback->($rsp);
}
}
sub preprocess_request {
my $request = shift;
#if ($request->{_xcatdest}) { return [$request]; } #exit if preprocessed
if ((defined($request->{_xcatpreprocessed}))
&& ($request->{_xcatpreprocessed}->[0] == 1))
{
return [$request];
}
my $callback = shift;
my @requests;
#display usage statement if -h is present or no noderage is specified
my $noderange = $request->{node}; #Should be arrayref
my $command = $request->{command}->[0];
my $extrargs = $request->{arg};
my @exargs = ($request->{arg});
if (ref($extrargs)) {
@exargs = @$extrargs;
}
my $usage_string = xCAT::Usage->parseCommand($command, @exargs);
if ($usage_string) {
$callback->({ data => $usage_string });
$request = {};
return;
}
if (!$noderange) {
$usage_string = xCAT::Usage->getUsage($command);
$callback->({ data => $usage_string });
$request = {};
return;
}
# require SOAP::Lite for hpoa.pm so we can do it dynamically
my $soapsupport = eval { require SOAP::Lite; };
unless ($soapsupport) { #Still no SOAP::Lite module
$callback->({ error => "SOAP::Lite perl module missing. Install perl-SOAP-Lite before running HP blade commands.", errorcode => [42] });
return [];
}
require xCAT::hpoa;
#get the MMs for the nodes for the nodes in order to figure out which service nodes to send the requests to
my $mptab = xCAT::Table->new("mp");
unless ($mptab) {
$callback->({ data => ["Cannot open mp table"] });
$request = {};
return;
}
my %mpa_hash = ();
my $mptabhash = $mptab->getNodesAttribs($noderange, [ 'mpa', 'id' ]);
if ($request->{command}->[0] eq "gethpbladecons") { #Can handle it here and now
gethpbladecons($noderange, $callback);
return ();
}
foreach my $node (@$noderange) {
my $ent = $mptabhash->{$node}->[0]; #$mptab->getNodeAttribs($node,['mpa', 'id']);
if (defined($ent->{mpa})) { push @{ $mpa_hash{ $ent->{mpa} }{nodes} }, $node; }
else {
$callback->({ data => ["no mpa defined for node $node"] });
$request = {};
return;
}
my $tempid;
if (defined($ent->{id})) {
#if the ide is defined, we need to see if there is a letter embedded in it. If there is,
#then we need to convert the id to the correct slot
$tempid = convertSlot($ent->{id});
push @{ $mpa_hash{ $ent->{mpa} }{ids} }, $tempid;
} else {
push @{ $mpa_hash{ $ent->{mpa} }{ids} }, "";
}
}
# find service nodes for the MMs
# build an individual request for each service node
my $service = "xcat";
my @mms = keys(%mpa_hash);
my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@mms, $service, "MN");
# build each request for each service node
foreach my $snkey (keys %$sn)
{
#print "snkey=$snkey\n";
my $reqcopy = {%$request};
$reqcopy->{'_xcatdest'} = $snkey;
my $mms1 = $sn->{$snkey};
my @moreinfo = ();
my @nodes = ();
foreach (@$mms1) {
push @nodes, @{ $mpa_hash{$_}{nodes} };
push @moreinfo, "\[$_\]\[" . join(',', @{ $mpa_hash{$_}{nodes} }) . "\]\[" . join(',', @{ $mpa_hash{$_}{ids} }) . "\]";
}
$reqcopy->{node} = \@nodes;
#print "nodes=@nodes\n";
$reqcopy->{moreinfo} = \@moreinfo;
push @requests, $reqcopy;
}
return \@requests;
}
sub build_more_info {
my $noderange = shift;
my $callback = shift;
my $mptab = xCAT::Table->new("mp");
my @moreinfo = ();
unless ($mptab) {
$callback->({ data => ["Cannot open mp table"] });
return @moreinfo;
}
my %mpa_hash = ();
my $mptabhash = $mptab->getNodesAttribs($noderange, [ 'mpa', 'id' ]);
foreach my $node (@$noderange) {
my $ent = $mptabhash->{$node}->[0]; #$mptab->getNodeAttribs($node,['mpa', 'id']);
if (defined($ent->{mpa})) { push @{ $mpa_hash{ $ent->{mpa} }{nodes} }, $node; }
else {
$callback->({ data => ["no mpa defined for node $node"] });
return @moreinfo;
}
if (defined($ent->{id})) { push @{ $mpa_hash{ $ent->{mpa} }{ids} }, $ent->{id}; }
else { push @{ $mpa_hash{ $ent->{mpa} }{ids} }, ""; }
}
foreach (keys %mpa_hash) {
push @moreinfo, "\[$_\]\[" . join(',', @{ $mpa_hash{$_}{nodes} }) . "\]\[" . join(',', @{ $mpa_hash{$_}{ids} }) . "\]";
}
return \@moreinfo;
}
sub handle_depend {
my $request = shift;
my $callback = shift;
my $doreq = shift;
my $dp = shift;
my %node = ();
my $dep = @$dp[0];
my $dep_hash = @$dp[1];
# send all dependencies (along w/ those dependent on nothing)
# build moreinfo for dependencies
my %mpa_hash = ();
my @moreinfo = ();
my $reqcopy = {%$request};
my @nodes = ();
foreach my $node (keys %$dep) {
my $mpa = @{ $dep_hash->{$node} }[0];
push @{ $mpa_hash{$mpa}{nodes} }, $node;
push @{ $mpa_hash{$mpa}{ids} }, @{ $dep_hash->{$node} }[1];
}
foreach (keys %mpa_hash) {
push @nodes, @{ $mpa_hash{$_}{nodes} };
push @moreinfo, "\[$_\]\[" . join(',', @{ $mpa_hash{$_}{nodes} }) . "\]\[" . join(',', @{ $mpa_hash{$_}{ids} }) . "\]";
}
$reqcopy->{node} = \@nodes;
$reqcopy->{moreinfo} = \@moreinfo;
process_request($reqcopy, $callback, $doreq, 1);
my $start = Time::HiRes::gettimeofday();
# build list of dependent nodes w/delays
while (my ($name, $h) = each(%$dep)) {
foreach (keys %$h) {
if ($h->{$_} =~ /(^\d+$)/) {
$node{$_} = $1 / 1000.0;
}
}
}
# send each dependent node as its delay expires
while (%node) {
my @noderange = ();
my $delay = 0.1;
my $elapsed = Time::HiRes::gettimeofday() - $start;
# sort in ascending delay order
foreach (sort { $node{$a} <=> $node{$b} } keys %node) {
if ($elapsed < $node{$_}) {
$delay = $node{$_} - $elapsed;
last;
}
push @noderange, $_;
delete $node{$_};
}
if (@noderange) {
%mpa_hash = ();
foreach my $node (@noderange) {
my $mpa = @{ $dep_hash->{$node} }[0];
push @{ $mpa_hash{$mpa}{nodes} }, $node;
push @{ $mpa_hash{$mpa}{ids} }, @{ $dep_hash->{$node} }[1];
}
@moreinfo = ();
$reqcopy = {%$request};
@nodes = ();
foreach (keys %mpa_hash) {
push @nodes, @{ $mpa_hash{$_}{nodes} };
push @moreinfo, "\[$_\]\[" . join(',', @{ $mpa_hash{$_}{nodes} }) . "\]\[" . join(',', @{ $mpa_hash{$_}{ids} }) . "\]";
}
$reqcopy->{node} = \@nodes;
$reqcopy->{moreinfo} = \@moreinfo;
# clear global hash variable
%oahash = ();
process_request($reqcopy, $callback, $doreq, 1);
}
# millisecond sleep
Time::HiRes::sleep($delay);
}
return 0;
}
sub build_depend {
my $noderange = shift;
my $exargs = shift;
my $depstab = xCAT::Table->new('deps');
my $mptab = xCAT::Table->new('mp');
my %dp = ();
my %no_dp = ();
my %mpa_hash;
if (!defined($depstab)) {
return ([ \%dp ]);
}
unless ($mptab) {
return ("Cannot open mp table");
}
my $depset = $depstab->getNodesAttribs($noderange, [qw(nodedep msdelay cmd)]);
foreach my $node (@$noderange) {
my $delay = 0;
my $dep;
my @ent = @{ $depset->{$node} }; #$depstab->getNodeAttribs($node,[qw(nodedep msdelay cmd)]);
foreach my $h (@ent) {
if (grep(/^@$exargs[0]$/, split /,/, $h->{cmd})) {
if (exists($h->{nodedep})) { $dep = $h->{nodedep}; }
if (exists($h->{msdelay})) { $delay = $h->{msdelay}; }
last;
}
}
if (!defined($dep)) {
$no_dp{$node} = 1;
}
else {
foreach my $n (split /,/, $dep) {
if (!grep(/^$n$/, @$noderange)) {
return ("Missing dependency on command-line: $node -> $n");
} elsif ($n eq $node) {
next; # ignore multiple levels
}
$dp{$n}{$node} = $delay;
}
}
}
# if there are dependencies, add any non-dependent nodes
if (scalar(%dp)) {
foreach (keys %no_dp) {
if (!exists($dp{$_})) {
$dp{$_}{$_} = -1;
}
}
# build hash of all nodes in preprocess_request() format
my @namelist = keys %dp;
my $mphash = $mptab->getNodesAttribs(\@namelist, [ 'mpa', 'id' ]);
while (my ($name, $h) = each(%dp)) {
my $ent = $mphash->{$name}->[0]; #$mptab->getNodeAttribs($name,['mpa', 'id']);
if (!defined($ent->{mpa})) {
return ("no mpa defined for node $name");
}
my $id = (defined($ent->{id})) ? $ent->{id} : "";
push @{ $mpa_hash{$name} }, $ent->{mpa};
push @{ $mpa_hash{$name} }, $id;
@namelist = keys %$h;
my $mpsubhash = $mptab->getNodesAttribs(\@namelist, [ 'mpa', 'id' ]);
foreach (keys %$h) {
if ($h->{$_} =~ /(^\d+$)/) {
my $ent = $mpsubhash->{$_}->[0]; #$mptab->getNodeAttribs($_,['mpa', 'id']);
if (!defined($ent->{mpa})) {
return ("no mpa defined for node $_");
}
my $id = (defined($ent->{id})) ? $ent->{id} : "";
push @{ $mpa_hash{$_} }, $ent->{mpa};
push @{ $mpa_hash{$_} }, $id;
}
}
}
}
return ([ \%dp, \%mpa_hash ]);
}
sub process_request {
$SIG{INT} = $SIG{TERM} = sub {
foreach (keys %mm_comm_pids) {
kill 2, $_;
}
exit 0;
};
my $request = shift;
my $callback = shift;
my $doreq = shift;
my $level = shift;
my $noderange = $request->{node};
my $command = $request->{command}->[0];
my @exargs;
unless ($command) {
return; #Empty request
}
# require SOAP::Lite for hpoa.pm so we can do it dynamically
my $soapsupport = eval { require SOAP::Lite; };
unless ($soapsupport) { #Still no SOAP::Lite module
$callback->({ error => "SOAP::Lite perl module missing. Install perl-SOAP-Lite before running HP blade commands.", errorcode => [42] });
return [];
}
require xCAT::hpoa;
if (ref($request->{arg})) {
@exargs = @{ $request->{arg} };
} else {
@exargs = ($request->{arg});
}
my $moreinfo;
if ($request->{moreinfo}) { $moreinfo = $request->{moreinfo}; }
else { $moreinfo = build_more_info($noderange, $callback); }
#pdu commands will be handled in the pdu plugin
if ($command eq "rpower" and grep(/^pduon|pduoff|pdureset|pdustat$/, @exargs)) {
return;
}
if ($command eq "rpower" and grep(/^on|off|boot|reset|cycle$/, @exargs)) {
if (my ($index) = grep($exargs[$_] =~ /^--nodeps$/, 0 .. $#exargs)) {
splice(@exargs, $index, 1);
} else {
# handles 1 level of dependencies only
if (!defined($level)) {
my $dep = build_depend($noderange, \@exargs);
if (ref($dep) ne 'ARRAY') {
$callback->({ data => [$dep], errorcode => 1 });
return;
}
if (scalar(%{ @$dep[0] })) {
handle_depend($request, $callback, $doreq, $dep);
return 0;
}
}
}
}
# only 1 node when changing textid to something other than '*'
if ($command eq "rspconfig" and grep(/^textid=[^*]/, @exargs)) {
if (@$noderange > 1) {
$callback->({ data => ["Single node required when changing textid"],
errorcode => 1 });
return;
}
}
my $bladeuser = 'USERID';
my $bladepass = 'PASSW0RD';
my $blademaxp = 64;
#my $sitetab = xCAT::Table->new('site');
my $mpatab = xCAT::Table->new('mpa');
my $mptab = xCAT::Table->new('mp');
my $tmp;
#if ($sitetab) {
#($tmp)=$sitetab->getAttribs({'key'=>'blademaxp'},'value');
my @entries = xCAT::TableUtils->get_site_attribute("blademaxp");
my $t_entry = $entries[0];
if (defined($t_entry)) { $blademaxp = $t_entry; }
#}
my $passtab = xCAT::Table->new('passwd');
if ($passtab) {
($tmp) = $passtab->getAttribs({ 'key' => 'blade' }, 'username', 'password');
if (defined($tmp)) {
$bladeuser = $tmp->{username};
$bladepass = $tmp->{password};
}
}
if ($request->{command}->[0] eq "findme") {
if (defined($request->{discoverymethod}) and defined($request->{discoverymethod}->[0]) and ($request->{discoverymethod}->[0] ne 'undef')) {
# The findme request had been processed by other module, just return
return;
}
my $mptab = xCAT::Table->new("mp");
unless ($mptab) { return 2; }
my @bladents = $mptab->getAllNodeAttribs([qw(node)]);
my @blades;
foreach (@bladents) {
push @blades, $_->{node};
}
my %invreq;
$invreq{node} = \@blades;
$invreq{arg} = ['mac'];
$invreq{command} = ['rinv'];
my $mac;
my $ip = $request->{'_xcat_clientip'};
my $arptable;
if (-x "/usr/sbin/arp") {
$arptable = `/usr/sbin/arp -n`;
}
else {
$arptable = `/sbin/arp -n`;
}
my @arpents = split /\n/, $arptable;
foreach (@arpents) {
if (m/^($ip)\s+\S+\s+(\S+)\s/) {
$mac = $2;
last;
}
}
unless ($mac) { return }
#Only refresh the the cache when the request permits and no useful answer
if ($macmaptimestamp < (time() - 300)) { #after five minutes, invalidate cache
%macmap = ();
}
unless ($request->{cacheonly}->[0] or $macmap{$mac} or $macmaptimestamp > (time() - 20)) { #do not refresh cache if requested not to, if it has an entry, or is recent
%macmap = ();
$macmaptimestamp = time();
foreach (@{ preprocess_request(\%invreq, \&fillresps) }) {
%invreq = %$_;
process_request(\%invreq, \&fillresps);
}
}
unless ($macmap{$mac}) {
xCAT::MsgUtils->message("S", "xcat.discovery.hpblade: ($request->{_xcat_clientmac}->[0]) Warning: Could not find any nodes using hpblade-based discovery");
return 1; #failure
}
# The discovered command will update mac table, no need to update here
#my $mactab = xCAT::Table->new('mac',-create=>1);
#$mactab->setNodeAttribs($macmap{$mac},{mac=>$mac});
#$mactab->close();
#my %request = (
# command => ['makedhcp'],
# node => [$macmap{$mac}]
# );
#$doreq->(\%request);
xCAT::MsgUtils->message("S", "xcat.discovery.hpblade: ($request->{_xcat_clientmac}->[0]) Found node: $macmap{$mac}");
my $req = {%$request};
$req->{command} = ['discovered'];
$req->{noderange} = [ $macmap{$mac} ];
if (defined($req->{error})) {
$request->{error}->[0] = '1';
$request->{error_msg}->[0] = $req->{error_msg}->[0];
}
$doreq->($req);
%{$req} = (); #Clear request. it is done
#undef $mactab;
return 0;
}
my $children = 0;
$SIG{CHLD} = sub { my $cpid; while ($cpid = waitpid(-1, WNOHANG) > 0) { delete $mm_comm_pids{$cpid}; $children--; } };
my $inputs = new IO::Select;
foreach my $info (@$moreinfo) {
$info =~ /^\[(.*)\]\[(.*)\]\[(.*)\]/;
my $mpa = $1;
my @nodes = split(',', $2);
my @ids = split(',', $3);
#print "mpa=$mpa, nodes=@nodes, ids=@ids\n";
my $user = $bladeuser;
my $pass = $bladepass;
my $ent;
if (defined($mpatab)) {
($ent) = $mpatab->getAttribs({ 'mpa' => $mpa }, 'username', 'password');
if (defined($ent->{password})) { $pass = $ent->{password}; }
if (defined($ent->{username})) { $user = $ent->{username}; }
}
$oahash{$mpa}->{username} = $user;
$oahash{$mpa}->{password} = $pass;
for (my $i = 0 ; $i < @nodes ; $i++) {
my $node = $nodes[$i];
my $nodeid = $ids[$i];
$oahash{$mpa}->{nodes}->{$node} = $nodeid;
}
}
my $sub_fds = new IO::Select;
foreach $oa (sort (keys %oahash)) {
while ($children > $blademaxp) { forward_data($callback, $sub_fds); }
$children++;
my $cfd;
my $pfd;
socketpair($pfd, $cfd, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!";
$cfd->autoflush(1);
$pfd->autoflush(1);
my $cpid = xCAT::Utils->xfork;
unless (defined($cpid)) { die "Fork error"; }
unless ($cpid) {
close($cfd);
eval {
doblade($pfd, $oa, \%oahash, $command, -args => \@exargs);
exit(0);
};
if ($@) { die "$@"; }
die "blade plugin encountered a general error while communication with $oa";
}
$mm_comm_pids{$cpid} = 1;
close($pfd);
$sub_fds->add($cfd);
}
while ($sub_fds->count > 0 or $children > 0) {
forward_data($callback, $sub_fds);
}
while (forward_data($callback, $sub_fds)) { }
}
my $IMPORT_SSH_KEY_HEADER = '
<LOCFGVERSION="2.21"/>
<RIBCL VERSION="2.0">
<LOGIN USER_LOGIN="AdMiNnAmE" PASSWORD="PaSsWoRd">
<RIB_INFO MODE="write">
<IMPORT_SSH_KEY>
-----BEGIN SSH KEY-----
';
my $IMPORT_SSH_KEY_FOOTER = '
-----END SSH KEY-----
</IMPORT_SSH_KEY>
</RIB_INFO>
</LOGIN>
</RIBCL>';
my $MOD_NETWORK_SETTINGS_HEADER = '
<LOCFGVERSION="2.21"/>
<RIBCL VERSION="2.0">
<LOGIN USER_LOGIN="AdMiNnAmE" PASSWORD="PaSsWoRd">
<RIB_INFO MODE="write">
<MOD_NETWORK_SETTINGS>
';
my $MOD_NETWORK_SETTINGS_FOOTER = '
</MOD_NETWORK_SETTINGS>
</RIB_INFO>
<LOGIN>
</RIBCL>';
my $GET_NETWORK_SETTINGS = '
<LOCFGVERSION="2.21"/>
<RIBCL VERSION="2.0">
<LOGIN USER_LOGIN="AdMiNnAmE" PASSWORD="PaSsWoRd">
<RIB_INFO MODE="read">
<GET_NETWORK_SETTINGS/>
</RIB_INFO>
</LOGIN>
</RIBCL>';
Net::SSLeay::load_error_strings();
Net::SSLeay::SSLeay_add_ssl_algorithms();
Net::SSLeay::randomize();
#
# opens an ssl connection to port 443 of the passed host
#
sub openSSLconnection($)
{
my $host = shift;
my ($ssl, $sin, $ip, $nip);
if (not $ip = inet_aton($host))
{
print "$host is a DNS Name, performing lookup\n" if $globalDebug;
$ip = gethostbyname($host) or die "ERROR: Host $host notfound. \n";
}
$nip = inet_ntoa($ip);
#print STDERR "Connecting to $nip:443\n";
$sin = sockaddr_in(443, $ip);
socket(S, &AF_INET, &SOCK_STREAM, 0) or die "ERROR: socket: $!";
connect(S, $sin) or die "connect: $!";
$ctx = Net::SSLeay::CTX_new() or die_now("ERROR: Failed to create SSL_CTX $! ");
Net::SSLeay::CTX_set_options($ctx, &Net::SSLeay::OP_ALL);
die_if_ssl_error("ERROR: ssl ctx set options");
$ssl = Net::SSLeay::new($ctx) or die_now("ERROR: Failed to create SSL $!");
Net::SSLeay::set_fd($ssl, fileno(S));
Net::SSLeay::connect($ssl) and die_if_ssl_error("ERROR: ssl connect");
#print STDERR 'SSL Connected ';
print 'Using Cipher: ' . Net::SSLeay::get_cipher($ssl) if $globalDebug;
#print STDERR "\n\n";
return $ssl;
}
sub closeSSLconnection($)
{
my $ssl = shift;
Net::SSLeay::free($ssl); # Tear down connection
Net::SSLeay::CTX_free($ctx);
close S;
}
# usage: sendscript(host, script)
# sends the xmlscript script to host, returns reply
sub sendScript($$)
{
my $host = shift;
my $script = shift;
my ($ssl, $reply, $lastreply, $res, $n);
$ssl = openSSLconnection($host);
# write header
$n = Net::SSLeay::ssl_write_all($ssl, '<?xml version="1.0"?>' . "\r\n");
print "Wrote $n\n" if $globalDebug;
$n = Net::SSLeay::ssl_write_all($ssl, '<LOCFG version="2.21"/>' . "\r\n");
print "Wrote $n\n" if $globalDebug;
# write script
$n = Net::SSLeay::ssl_write_all($ssl, $script);
print "Wrote $n\n$script\n" if $globalDebug;
$reply = "";
$lastreply = "";
my $reply2return = "";
READLOOP:
while (1) {
$n++;
$lastreply = Net::SSLeay::read($ssl);
die_if_ssl_error("ERROR: ssl read");
if ($lastreply eq "") {
sleep(2); # wait 2 sec for more text.
$lastreply = Net::SSLeay::read($ssl);
die_if_ssl_error("ERROR: ssl read");
last READLOOP if ($lastreply eq "");
}
$reply .= $lastreply;
print "lastreply $lastreply \b" if $globalDebug;
# Check response to see if a error was returned.
if ($lastreply =~ m/STATUS="(0x[0-9A-F]+)"[\s]+MESSAGE='(.*)'[\s]+\/>[\s]*(([\s]|.)*?)<\/RIBCL>/) {
if ($1 eq "0x0000") {
#print STDERR "$3\n" if $3;
} else {
$reply2return = "ERROR: STATUS: $1, MESSAGE: $2";
}
}
}
print "READ: $lastreply\n" if $globalDebug;
if ($lastreply =~ m/STATUS="(0x[0-9A-F]+)"[\s]+MESSAGE='(.*)'[\s]+\/>[\s]*(([\s]|.)*?)<\/RIBCL>/) {
if ($1 eq "0x0000") {
#Sprint STDERR "$3\n" if $3;
} else {
$reply2return = "ERROR: STATUS: $1, MESSAGE: $2";
}
}
closeSSLconnection($ssl);
return $reply2return;
}
sub extractValue {
my $inputString = shift;
my $testString = shift;
$testString = "<" . "$testString" . " VALUE=";
my $start = index($inputString, $testString) + length $testString;
my $end = index $inputString, "\"", ($start + 1);
return (substr($inputString, ($start + 1), ($end - $start - 1)));
}
sub iloconfig {
my $oa = shift;
my $user = shift;
my $pass = shift;
my $node = shift;
my $nodeid = shift;
my $parameter;
my $value;
my $assignment;
my $returncode = 0;
my $textid = 0;
@cfgtext = ();
# Before we get going, lets get the info on the MP (iLO)
$slot = convertSlot($nodeid);
my $mpInfoResp = $hpoa->getBladeMpInfo("bayNumber" => $slot);
if ($mpInfoResp->fault) {
my $errorText = "Error getting MP info";
next;
}
my $ipaddress = $mpInfoResp->result->{ipAddress};
foreach $parameter (@_) {
$assignment = 0;
$value = undef;
if ($parameter =~ /=/) {
$assignment = 1;
($parameter, $value) = split /=/, $parameter, 2;
}
if ($parameter =~ /^sshcfg$/) {
my $fname = "/root/.ssh/id_dsa.pub";
if (!-s $fname) {
# Key file specified does not exist. Error!
push @cfgtext, "rspconfig:key file does not exist";
next;
}
open(KEY, "$fname");
my $key = readline(KEY);
close(KEY);
my $script = "$IMPORT_SSH_KEY_HEADER" . "$key" . "$IMPORT_SSH_KEY_FOOTER";
$script =~ s/AdMiNnAmE/$user/;
$script =~ s/PaSsWoRd/$pass/;
my $reply = sendScript($ipaddress, $script);
push @cfgtext, $reply;
next;
}
if ($parameter =~ /^network$/) {
if ($value) {
# If value is set, then the user wans us to set these values
my ($newip, $newhostname, $newgateway, $newmask) = split /,/, $value;
my $script = "$MOD_NETWORK_SETTINGS_HEADER";
$script = $script . "<IP_ADDRESS VALUE=\"$newip\"\/>" if ($newip);
$script = $script . "<GATEWAY_IP_ADDRESS VALUE=\"$newgateway\"\/>" if ($newgateway);
$script = $script . "<SUBNET_MASK VALUE=\"$newmask\"\/>" if ($newmask);
$script = $script . "$MOD_NETWORK_SETTINGS_FOOTER";
$script =~ s/AdMiNnAmE/$user/;
$script =~ s/PaSsWoRd/$pass/;
my $reply = sendScript($ipaddress, $script);
if ($newip) { push @cfgtext, "iLO IP: $newip"; }
if ($newgateway) { push @cfgtext, "Gateway: $newgateway"; }
if ($newmask) { push @cfgtext, "Subnet Mask: $newmask"; }
push @cfgtext, $reply;
} else {
my $script = "$GET_NETWORK_SETTINGS";
$script =~ s/AdMiNnAmE/$user/;
$script =~ s/PaSsWoRd/$pass/;
my $reply = sendScript($ipaddress, $script);
my $readipaddress = extractValue($reply, "IP_ADDRESS");
my $gateway = extractValue($reply, "GATEWAY_IP_ADDRESS");
my $netmask = extractValue($reply, "SUBNET_MASK");
push @cfgtext, "iLO IP: $readipaddress";
push @cfgtext, "Gateway: $gateway";
push @cfgtext, "Subnet mask: $netmask";
push @cfgtext, $reply;
}
}
}
return 0, @cfgtext;
}
sub getmacs
{
(my $code, my @macs) = inv('mac');
my $mkey;
my $nic2Find;
my $nrtab = xCAT::Table->new('noderes');
if ($nrtab) {
my $nent = $nrtab->getNodeAttribs($curn, [ 'primarynic', 'installnic' ]);
if ($nent) {
if (defined $nent->{installnic}) { #Prefer the install nic
$mkey = "installnic";
} elsif (defined $nent->{primarynic}) { #see if primary nic was set
$mkey = "primarynic";
}
$nic2Find = $nent->{$mkey};
}
}
# We now have the nic2Find, so we need to convert this to the NIC format
# Strip away the "eth"
my $interface = $nic2Find;
$nic2Find =~ s/eth//;
my $numberPxeNic = $nic2Find + 1;
my $pxeNic = "NIC " . $numberPxeNic;
if ($code == 0) {
my $mac;
my @allmacs;
foreach my $macEntry (@macs) {
if ($macEntry =~ /MAC ADDRESS $pxeNic/) {
$mac = $macEntry;
$mac =~ s/MAC ADDRESS $pxeNic: //;
$mac = lc $mac;
last;
}
}
if (!$mac) {
return 1, "Unable to retrieve MAC address for interface $pxeNic from OnBoard Administrator";
}
my $mactab = xCAT::Table->new('mac', -create => 1);
$mactab->setNodeAttribs($curn, { mac => $mac }, { interface => $interface });
$mactab->close;
return 0, ":mac.mac set to $mac";
} else {
return $code, $macs[0];
}
}
sub inv {
my @invitems;
my @output;
foreach (@_) {
push @invitems, split(/,/, $_);
}
my $item;
unless (scalar(@invitems)) {
@invitems = ("all");
}
# Before going off to handle the items, issue a getBladeInfo, getBladeMpInfo, and getOaInfo
my $getBladeInfoResult = $hpoa->getBladeInfo("bayNumber" => $slot);
if ($getBladeInfoResult->fault) {
return (1, "getBladeInfo on node $curn failed");
}
my $getBladeMpInfoResult = $hpoa->getBladeMpInfo("bayNumber" => $slot);
if ($getBladeMpInfoResult->fault) {
return (1, "getBladeMpInfo on node $curn fault");
}
my $getOaInfoResult = $hpoa->getOaInfo("bayNumber" => $activeOABay);
if ($getOaInfoResult->fault) {
my $errHash = $getOaInfoResult->fault;
return (1, "getOaInfo failed");
}
while (my $item = shift @invitems) {
if ($item =~ /^all/) {
push @invitems, (qw(mtm serial mac firm));
next;
}
if ($item =~ /^firm/) {
push @invitems, (qw(bladerom mprom oarom));
}
if ($item =~ /^bladerom/) {
push @output, "BladeFW: " . $getBladeInfoResult->result->{romVersion};
}
if ($item =~ /^mprom/) {
push @output, "iLOFW: " . $getBladeMpInfoResult->result->{fwVersion};
}
if ($item =~ /~oarom/) {
push @output, "OA FW: " . $getOaInfoResult->result->{fwVersion};
}
if ($item =~ /^model/ or $item =~ /^mtm/) {
push @output, "Machine Type/Model: " . $getBladeInfoResult->result->{partNumber};
}
if ($item =~ /^serial/) {
push @output, "Serial Number: " . $getBladeInfoResult->result->{serialNumber};
}
if ($item =~ /^mac/) {
my $numberOfNics = $getBladeInfoResult->result->{numberOfNics};
for (my $i = 0 ; $i < $numberOfNics ; $i++) {
my $mac = $getBladeInfoResult->result->{nics}->{bladeNicInfo}[$i]->{macAddress};
my $port = $getBladeInfoResult->result->{nics}->{bladeNicInfo}[$i]->{port};
push @output, "MAC ADDRESS " . $port . ": " . $mac;
#push@output, "MAC Address ".($_+1).": ".$getBladeInfoResult->result->{nics}->{bladeNicInfo}[$i]->{macAddress};
}
}
}
return (0, @output);
}
sub CtoF {
my $Ctemp = shift;
return ((($Ctemp * 9) / 5) + 32);
}
my %chassiswidevitals;
sub vitals {
my @output;
my $tmp;
my @vitems;
if ($#_ == 0 && $_[0] eq '') { pop @_; push @_, "all" } #-- default is all if no argument given
if (defined $slot and $slot > 0) { #-- blade query
foreach (@_) {
if ($_ eq 'all') {
# push @vitems,qw(temp voltage wattage summary fan);
push @vitems, qw(cpu_temp memory_temp system_temp ambient_temp summary fanspeed);
push @vitems, qw(led power);
} elsif ($_ =~ '^led') {
push @vitems, qw(led);
} else {
push @vitems, split(/,/, $_);
}
}
} else { #-- chassis query
foreach (@_) {
if ($_ eq 'all') {
# push @vitems,qw(voltage wattage power summary);
push @vitems, qw(cpu_temp memory_temp system_temp ambient_temp summary fanspeed);
# push @vitems,qw(errorled beaconled infoled templed);
push @vitems, qw(led power);
} elsif ($_ =~ '^led') {
push @vitems, qw(led);
} elsif ($_ =~ '^cool') {
push @vitems, qw(fanspeed);
} elsif ($_ =~ '^temp') {
push @vitems, qw(ambient_temp);
} else {
push @vitems, split(/,/, $_);
}
}
}
my @vitals;
if (defined $slot and $slot > 0) { #-- querying some blade
if (grep /temp/, @vitems) {
my $tempResponse = $hpoa->getBladeThermalInfoArray("bayNumber" => $slot);
if ($tempResponse->fault) {
push @output, "Request to get Temperature info on slot $slot failed";
}
elsif (!$tempResponse->result) {
# If is the case then the temperature data is not yet available.
push @output, "Temperature data not available.";
} else {
# We have data so go process it....
my @tempdata = $tempResponse->result->{bladeThermalInfo};
my $lastElement = $tempResponse->result->{bladeThermalInfo}[-1]->{sensorNumber};
if (grep /cpu_temp/, @vitems) {
my $index = -1;
do {
$index++;
if (grep /CPU/, $tempResponse->result->{bladeThermalInfo}[$index]->{description}) {
my $Ctemp = $tempResponse->result->{bladeThermalInfo}[$index]->{temperatureC};
my $desc = $tempResponse->result->{bladeThermalInfo}[$index]->{description};
my $Ftemp = CtoF($Ctemp);
push @output, "$desc Temperature: $Ctemp C \( $Ftemp F \)";
}
} until $tempResponse->result->{bladeThermalInfo}[$index]->{sensorNumber} eq $lastElement;
}
if (grep /memory_temp/, @vitems) {
my $index = -1;
do {
$index++;
if (grep /Memory/, $tempResponse->result->{bladeThermalInfo}[$index]->{description}) {
my $Ctemp = $tempResponse->result->{bladeThermalInfo}[$index]->{temperatureC};
my $desc = $tempResponse->result->{bladeThermalInfo}[$index]->{description};
my $Ftemp = CtoF($Ctemp);
push @output, "$desc Temperature: $Ctemp C \( $Ftemp F \)";
}
} until $tempResponse->result->{bladeThermalInfo}[$index]->{sensorNumber} eq $lastElement;
}
if (grep /system_temp/, @vitems) {
my $index = -1;
do {
$index++;
if (grep /System/, $tempResponse->result->{bladeThermalInfo}[$index]->{description}) {
my $Ctemp = $tempResponse->result->{bladeThermalInfo}[$index]->{temperatureC};
my $desc = $tempResponse->result->{bladeThermalInfo}[$index]->{description};
my $Ftemp = CtoF($Ctemp);
push @output, "$desc Temperature: $Ctemp C \( $Ftemp F \)";
}
} until $tempResponse->result->{bladeThermalInfo}[$index]->{sensorNumber} eq $lastElement;
}
if (grep /ambient_temp/, @vitems) {
my $index = -1;
do {
$index++;
if (grep /Ambient/, $tempResponse->result->{bladeThermalInfo}[$index]->{description}) {
my $Ctemp = $tempResponse->result->{bladeThermalInfo}[$index]->{temperatureC};
my $desc = $tempResponse->result->{bladeThermalInfo}[$index]->{description};
my $Ftemp = CtoF($Ctemp);
push @output, "$desc Temperature: $Ctemp C \( $Ftemp F \)";
}
} until $tempResponse->result->{bladeThermalInfo}[$index]->{sensorNumber} eq $lastElement;
}
}
}
if (grep /fanspeed/, @vitems) {
my $fanInfoResponse = $hpoa->getFanInfo("bayNumber" => $slot);
if ($fanInfoResponse->fault) {
push @output, "Request to get Fan Info from slot $slot failed ";
} elsif (!$fanInfoResponse->result) {
push @output, "No Fan Information";
} else {
my $fanStatus = $fanInfoResponse->result->{operationalStatus};
my $fanMax = $fanInfoResponse->result->{maxFanSpeed};
my $fanCur = $fanInfoResponse->result->{fanSpeed};
my $fanPercent = ($fanCur / $fanMax) * 100;
push @output, "Fan status: $fanStatus Percent of max: $fanPercent\%";
}
}
if (grep /led/, @vitems) {
my $currstat = $getBladeStatusResponse->result->{uid};
if ($currstat eq "UID_ON") {
push @output, "Current UID Status On";
} elsif ($currstat eq "UID_OFF") {
push @output, "Current UID Status Off";
} elsif ($currstat eq "UID_BLINK") {
push @output, "Current UID Status Blinking";
}
}
if (grep /power/, @vitems) {
my $currPowerStat = $getBladeStatusResponse->result->{powered};
if ($currPowerStat eq "POWER_ON") {
push @output, "Current Power Status On";
} elsif ($currPowerStat eq "POWER_OFF") {
push @output, "Current Power Status Off";
}
}
}
return (0, @output);
}
sub buildEventHash {
my $logText = shift;
my $eventLogFound = 0;
my $eventFound = 0;
my $eventNumber = 0;
my @lines = split /^/, $logText;
foreach my $line (@lines) {
if (!$eventLogFound) {
if (!$line =~ m/EVENT_LOG/) {
next;
} elsif ($line =~ m/EVENT_LOG/) {
$eventLogFound = 1;
next;
}
}
if (!$eventFound && $line =~ m/\<EVENT/) {
$eventFound = 1;
next;
} elsif ($eventFound && $line =~ m/\/\>/) {
$eventNumber++;
$eventFound = 0;
next;
}
# We have a good line. Need to split it up and build the hash.
my ($desc, $value) = split /=/, $line;
for ($desc) {
s/^\s+//;
s/\s+$//;
s/\"//g;
s/\\n//;
}
for ($value) {
s/^\s+//;
s/\"//g;
s/\s+$//;
s/\\n//;
}
$eventHash->{event}->{$eventNumber}->{$desc} = $value;
next;
}
return $eventNumber;
}
sub eventlog {
my $subcommand = shift;
my @output;
$subcommand = "all" if $subcommand eq "";
if ($subcommand eq "all" or $subcommand =~ /\d+/) {
my $mpEventLogResponse = $hpoa->getBladeMpEventLog("bayNumber" => $slot, "maxsize" => 640000);
if ($mpEventLogResponse->fault) {
return (1, "Attempt to retrieve Event Log faulted");
}
my $logText = $mpEventLogResponse->result->{logContents};
my $numEvents = buildEventHash($logText);
my $recCount = 0;
$eventHash->{'event'} = {
map {
$recCount++ => $_->[1]
} sort {
$a->[0] <=> $b->[0]
} map {
(defined $_->{LAST_UPDATE} && $_->{LAST_UPDATE} ne '[NOT SET]')
? [ &extractDate($_->{LAST_UPDATE}), $_ ]
: [ $_->{SELID}, $_ ]
} map {
$eventHash->{'event'}{$_}{SELID} = $_;
$eventHash->{'event'}{$_};
} grep {
defined $eventHash->{'event'}{$_}
} keys %{ $eventHash->{'event'} }
};
my $limitEvents = ($subcommand eq "all" ? $recCount : $subcommand);
for (my $index = 0 ; $index < $limitEvents ; $index++) {
--$recCount;
my $class = $eventHash->{event}->{$recCount}->{CLASS};
my $severity = $eventHash->{event}->{$recCount}->{SEVERITY};
my $dateTime = $eventHash->{event}->{$recCount}->{LAST_UPDATE};
my $desc = $eventHash->{event}->{$recCount}->{DESCRIPTION};
unshift @output, "$class $severity:$dateTime $desc";
}
return (0, @output);
} elsif ($subcommand eq "clear") {
return (1, "Command not supported");
} else {
return (1, "Command '$subcommand' not supported");
}
}
sub rscan {
my $args = shift;
my @values;
my $result;
my %opt;
@ARGV = @$args;
$Getopt::Long::ignorecase = 0;
Getopt::Long::Configure("bundling");
local *usage = sub {
my $usage_string = xCAT::Usage->getUsage("rscan");
return (join('', ($_[0], $usage_string)));
};
if (!GetOptions(\%opt, qw(V|Verbose w x z))) {
return (1, usage());
}
if (defined($ARGV[0])) {
return (1, usage("Invalid argument: @ARGV\n"));
}
if (exists($opt{x}) and exists($opt{z})) {
return (1, usage("-x and -z are mutually exclusive\n"));
}
my $encInfo = $hpoa->getEnclosureInfo();
if ($encInfo->fault) {
return (1, "Attempt tp get enclosure information has failed");
}
my $numBays = $encInfo->result->{bladeBays};
my $calcBladeBays = $numBays * 3; # Need to worry aboyt casmir blades
my $encName = $encInfo->result->{enclosureName};
my $enctype = $encInfo->result->{name};
my $encmodel = $encInfo->result->{partNumber};
my $encserial = $encInfo->result->{serialNumber};
push @values, join(",", "hpoa", $encName, 0, "$enctype-$encmodel", $encserial, $oa);
my $max = length($encName);
for (my $i = 1 ; $i <= $calcBladeBays ; $i++) {
my $bayInfo = $hpoa->getBladeInfo("bayNumber" => $i);
if ($bayInfo->fault) {
return (1, "Attempt to get blade info from bay $i has failed");
}
if ($bayInfo->result->{presence} eq "ABSENT") {
# no blade in the bya
next;
}
my $name = $bayInfo->result->{serverName};
my $bayNum = $i;
my $type = $bayInfo->result->{bladeType};
my $model = $bayInfo->result->{name};
my $serial = $bayInfo->result->{serialNumber};
push @values, join(",", "hpblade", $name, $bayNum, "$type-$model", $serial, "");
}
my $format = sprintf "%%-%ds", ($max + 2);
$rscan_header[1][1] = $format;
if (exists($opt{x})) {
$result = rscan_xml($oa, \@values);
}
elsif (exists($opt{z})) {
$result = rscan_stanza($oa, \@values);
}
else {
foreach (@rscan_header) {
$result .= sprintf @$_[1], @$_[0];
}
foreach (@values) {
my @data = split /,/;
my $i = 0;
foreach (@rscan_header) {
$result .= sprintf @$_[1], $data[ $i++ ];
}
}
}
if (!exists($opt{w})) {
return (0, $result);
}
my @tabs = qw(mp nodehm nodelist);
my %db = ();
foreach (@tabs) {
$db{$_} = xCAT::Table->new($_, -create => 1, -autocommit => 0);
if (!$db{$_}) {
return (1, "Error opening '$_'");
}
}
foreach (@values) {
my @data = split /,/;
my $name = $data[1];
my ($k1, $u1);
$k1->{node} = $name;
$u1->{mpa} = $oa;
$u1->{id} = $data[2];
$db{mp}->setAttribs($k1, $u1);
$db{mp}{commit} = 1;
my ($k2, $u2);
$k2->{node} = $name;
$u2->{mgt} = "hpblade";
$db{nodehm}->setAttribs($k2, $u2);
$db{nodehm}{commit} = 1;
my ($k3, $u3);
$k3->{node} = $name;
$u3->{groups} = "blade,all";
$db{nodelist}->setAttribs($k3, $u3);
$db{nodelist}{commit} = 1;
}
foreach (@tabs) {
if (exists($db{$_}{commit})) {
$db{$_}->commit;
}
}
return (0, $result);
}
sub rscan_xml {
my $mpa = shift;
my $values = shift;
my $xml;
foreach (@$values) {
my @data = split /,/;
my $i = 0;
my $href = {
Node => {}
};
foreach (@rscan_attribs) {
my $d = $data[ $i++ ];
my $type = $data[0];
if (/^name$/) {
next;
} elsif (/^nodetype$/) {
$d = $type;
} elsif (/^groups$/) {
$d = "$type,all";
} elsif (/^mgt$/) {
$d = "blade";
} elsif (/^mpa$/) {
$d = $mpa;
}
$href->{Node}->{$_} = $d;
}
$xml .= XMLout($href, NoAttr => 1, KeyAttr => [], RootName => undef);
}
return ($xml);
}
sub rscan_stanza {
my $mpa = shift;
my $values = shift;
my $result;
foreach (@$values) {
my @data = split /,/;
my $i = 0;
my $type = $data[0];
$result .= "$data[1]:\n\tobjtype=node\n";
foreach (@rscan_attribs) {
my $d = $data[ $i++ ];
if (/^name$/) {
next;
} elsif (/^nodetype$/) {
$d = $type;
} elsif (/^groups$/) {
$d = "$type,all";
} elsif (/^mgt$/) {
$d = "blade";
} elsif (/^mpa$/) {
$d = $mpa;
}
$result .= "\t$_=$d\n";
}
}
return ($result);
}
sub beacon {
my $subcommand = shift;
if ($subcommand eq "stat") {
my $currstat = $getBladeStatusResponse->result->{uid};
if ($currstat eq "UID_ON") {
return (0, "on");
} elsif ($currstat eq "UID_OFF") {
return (0, "off");
} elsif ($currstat eq "UID_BLINK") {
return (0, "blink");
}
}
my $response;
if ($subcommand eq "on") {
$response = $hpoa->setBladeUid('bayNumber' => $slot, 'uid' => "UID_CMD_ON");
if ($response->fault) {
my $errHash = $response->fault;
my $result = $response->oaErrorText;
print "result is $result \n";
return ("1", "Uid On failed");
} else {
return ("0", "");
}
} elsif ($subcommand eq "off") {
$response = $hpoa->setBladeUid('bayNumber' => $slot, 'uid' => "UID_CMD_OFF");
if ($response->fault) {
my $errHash = $response->fault;
my $result = $response->oaErrorText;
print "result is $result \n";
return ("1", "Uid Off failed");
} else {
return ("0", "");
}
} elsif ($subcommand eq "blink") {
$response = $hpoa->setBladeUid('bayNumber' => $slot, 'uid' => "UID_CMD_BLINK");
if ($response->fault) {
my $errHash = $response->fault;
my $result = $response->oaErrorText;
print "result is $result \n";
return ("1", "Uid Blink failed");
} else {
return ("0", "");
}
} else {
return (1, "subcommand unsupported");
}
return (1, "subcommand unsupported");
}
sub bootseq {
my @args = @_;
my $data;
my @order = ();
if ($args[0] eq "list" or $args[0] eq "stat") {
# Before going off to handle the items, issue a getBladeInfo and getOaInfo
my $getBladeBootInfoResult = $hpoa->getBladeBootInfo("bayNumber" => $slot);
if ($getBladeBootInfoResult->fault) {
return (1, "getBladeBootInfo on node $curn failed");
}
# Go through the the IPL Array from the last call to GetBladeStatus
my $numberOfIpls = $getBladeBootInfoResult->result->{numberOfIpls};
foreach (my $i = 0 ; $i < $numberOfIpls ; $i++) {
foreach (my $j = 0 ; $j <= 7 ; $j++) {
if ($getBladeBootInfoResult->result->{ipls}->{ipl}[$j]->{bootPriority} eq ($i + 1)) {
push(@order, $getBladeBootInfoResult->result->{ipls}->{ipl}[$j]->{iplDevice});
last;
}
}
}
return (0, lc join(',', @order));
} else {
foreach (@args) {
my @neworder = (split /,/, $_);
push @order, @neworder;
}
my $number = @order;
if ($number > 5) {
return (1, "Only five boot sequence entries allowed");
}
my $nonespecified = 0;
my $foundnic = 0;
foreach (@order) {
if (($bootnumbers{$_} > 4)) {
if ($foundnic == 1) {
# only one nic allowed. error out
return (1, "Only one Eth/Nic device permitted.");
} else {
$foundnic = 1;
}
}
unless (defined($bootnumbers{$_})) { return (1, "Unsupported device $_"); }
unless ($bootnumbers{$_}) { $nonespecified = 1; }
if ($nonespecified and $bootnumbers{$_}) { return (1, "Error: cannot specify 'none' before a device"); }
}
unless ($bootnumbers{ $order[0] }) {
return (1, "Error: cannot specify 'none' as first device");
}
# Build array to be sent to the blade here
my @ipl;
my $i = 1;
foreach my $dev (@order) {
push @ipl, { "bootPriority" => "$i", "iplDevice" => "$bootdevices{$bootnumbers{$order[$i - 1]}}" };
$i++;
}
my $setiplResponse = $hpoa->setBladeIplBootPriority("bladeIplArray" => [ 'ipl', \@ipl, "" ], "bayNumber" => $slot);
if ($setiplResponse->fault) {
my $errHash = $setiplResponse->fault;
my $result = $setiplResponse->oaErrorText;
print "result is $result \n";
return (1, "Error on slot $slot setting ipl");
}
return bootseq('list');
}
}
sub power {
my $subcommand = shift;
my $command2Send;
my $currPowerStat;
my $returnState;
$returnState = "";
$currPowerStat = $getBladeStatusResponse->result->{powered};
if ($subcommand eq "stat" || $subcommand eq "state") {
if ($currPowerStat eq "POWER_ON") {
return (0, "on");
} elsif ($currPowerStat eq "POWER_OFF") {
return (0, "off");
}
}
if ($subcommand eq "on") {
if ($currPowerStat eq "POWER_OFF") {
$command2Send = "MOMENTARY_PRESS";
$returnState = "on";
} else {
return (0, "on");
}
} elsif ($subcommand eq "off") {
if ($currPowerStat eq "POWER_ON") {
$command2Send = "PRESS_AND_HOLD";
$returnState = "off";
} else {
return (0, "off");
}
} elsif ($subcommand eq "reset") {
$command2Send = "RESET";
} elsif ($subcommand eq "cycle") {
if ($currPowerStat eq "POWER_ON") {
power("off");
}
$command2Send = "MOMENTARY_PRESS";
} elsif ($subcommand eq "boot") {
if ($currPowerStat eq "POWER_OFF") {
$command2Send = "MOMENTARY_PRESS";
$returnState = "off on";
} else {
$command2Send = "COLD_BOOT";
$returnState = "on reset";
}
} elsif ($subcommand eq "softoff") {
if ($currPowerStat eq "POWER_ON") {
$command2Send = "MOMENTARY_PRESS";
}
}
#If we got here with a command to send, do it, otherwise just return
if ($command2Send) {
my $pwrResult = $hpoa->setBladePower('bayNumber' => $slot, 'power' => $command2Send);
if ($pwrResult->fault) {
return (1, "Node $curn - Power command failed");
}
return (0, $returnState);
}
}
sub bladecmd {
my $oa = shift;
my $node = shift;
$slot = shift;
my $user = shift;
my $pass = shift;
my $command = shift;
my @args = @_;
my $error;
if ($slot > 0) {
$getBladeStatusResponse = $hpoa->getBladeStatus('bayNumber' => $slot);
if ($getBladeStatusResponse->fault) {
my $errHash = $getBladeStatusResponse->fault;
my $result = $getBladeStatusResponse->oaErrorText;
}
if ($getBladeStatusResponse->result->{presence} ne "PRESENT") {
return (1, "Target bay empty");
}
}
if ($command eq "rbeacon") {
return beacon(@args);
} elsif ($command eq "rpower") {
return power(@args);
} elsif ($command eq "rvitals") {
return vitals(@args);
} elsif ($command =~ /r[ms]preset/) {
return resetmp(@args);
} elsif ($command eq "rspconfig") {
return iloconfig($oa, $user, $pass, $node, $slot, @args);
} elsif ($command eq "rbootseq") {
return bootseq(@args);
} elsif ($command eq "switchblade") {
return switchblade(@args);
} elsif ($command eq "getmacs") {
return getmacs(@args);
} elsif ($command eq "rinv") {
return inv(@args);
} elsif ($command eq "reventlog") {
return eventlog(@args);
} elsif ($command eq "rscan") {
return rscan(\@args);
}
return (1, "$command not a supported command by blade method");
}
sub forward_data {
my $callback = shift;
my $fds = shift;
my @ready_fds = $fds->can_read(1);
my $rfh;
my $rc = @ready_fds;
foreach $rfh (@ready_fds) {
my $data;
if ($data = <$rfh>) {
while ($data !~ /ENDOFFREEZE6sK4ci/) {
$data .= <$rfh>;
}
print $rfh "ACK\n";
my $responses = thaw($data);
foreach (@$responses) {
$callback->($_);
}
} else {
$fds->remove($rfh);
close($rfh);
}
}
yield; #Try to avoid useless iterations as much as possible
return $rc;
}
sub doblade {
my $out = shift;
$oa = shift;
my $oahash = shift;
my $command = shift;
my %namedargs = @_;
my @exargs = @{ $namedargs{-args} };
my $node;
my $args = \@exargs;
$hpoa = oaLogin($oa);
# We are now logged into the OA and have a pointer to the OA session. Process
# the command.
#get new node status
my %nodestat = ();
my $check = 0;
my $nsh = {};
foreach $node (sort (keys %{ $oahash->{$oa}->{nodes} })) {
$curn = $node;
my ($rc, @output) = bladecmd($oa, $node, $oahash->{$oa}->{nodes}->{$node}, $oahash->{$oa}->{username}, $oahash->{$oa}->{password}, $command, @$args);
foreach (@output) {
my %output;
if ($command eq "rscan") {
$output{errorcode} = $rc;
$output{data} = [$_];
}
else {
(my $desc, my $text) = split(/:/, $_, 2);
unless ($text) {
$text = $desc;
} else {
$desc =~ s/^\s+//;
$desc =~ s/\s+$//;
if ($desc) {
$output{node}->[0]->{data}->[0]->{desc}->[0] = $desc;
}
}
$text =~ s/^\s+//;
$text =~ s/\s+$//;
$output{node}->[0]->{errorcode} = $rc;
$output{node}->[0]->{name}->[0] = $node;
$output{node}->[0]->{data}->[0]->{contents}->[0] = $text;
}
print $out freeze([ \%output ]);
print $out "\nENDOFFREEZE6sK4ci\n";
yield;
waitforack($out);
}
yield;
}
#update the node status to the nodelist.status table
if ($check) {
my %node_status = ();
#foreach (keys %nodestat) { print "node=$_,status=" . $nodestat{$_} ."\n"; } #Ling:remove
foreach my $node (keys %nodestat) {
my $stat = $nodestat{$node};
if ($stat eq "no-op") { next; }
if (exists($node_status{$stat})) {
my $pa = $node_status{$stat};
push(@$pa, $node);
}
else {
$node_status{$stat} = [$node];
}
}
xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%node_status, 1);
}
#my $msgtoparent=freeze(\@outhashes); # = XMLout(\%output,RootName => 'xcatresponse');
#print $out $msgtoparent; #$node.": $_\n";
}
sub extractDate {
use Time::Local;
my $date = shift;
return 0 unless $date =~ m/(\d{1,2})\/(\d{1,2})\/(\d{4}) (\d{1,2}):(\d{1,2})/;
return timegm(0, $5, $4, $2, $1, $3);
}
1;