2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 09:13:08 +00:00

refine hardware discovery framework, modifcation based on review comments

This commit is contained in:
ertaozh 2016-06-27 02:51:09 -04:00
parent 75bc7d91f4
commit ba01665adb
11 changed files with 74 additions and 102 deletions

View File

@ -4442,9 +4442,9 @@ sub cleanup_for_powerLE_hardware_discovery {
}
my $subreq = shift;
my $host_node = $request->{node}->[0];
my $pbmc_node = undef;
if (defined($request->{pbmc_node}) and defined($request->{pbmc_node}->[0])) {
$pbmc_node = $request->{pbmc_node}->[0];
my $bmc_node = undef;
if (defined($request->{bmc_node}) and defined($request->{bmc_node}->[0])) {
$bmc_node = $request->{bmc_node}->[0];
}
my $ipmitab = xCAT::Table->new("ipmi");
@ -4457,31 +4457,31 @@ sub cleanup_for_powerLE_hardware_discovery {
my $new_bmc_ip = $ipmihash->{$host_node}->[0]->{bmc};
my $new_bmc_username = $ipmihash->{$host_node}->[0]->{username};
my $new_bmc_password = $ipmihash->{$host_node}->[0]->{password};
if (!defined($pbmc_node)) {
if (!defined($bmc_node)) {
xCAT::MsgUtils->message("S", "Discover info: configure static BMC ip:$new_bmc_ip for host_node:$host_node.");
`rspconfig $host_node ip=$new_bmc_ip`;
return;
}
xCAT::MsgUtils->message("S", "Discovery info: configure password for pbmc_node:$pbmc_node.");
xCAT::MsgUtils->message("S", "Discovery info: configure password for bmc_node:$bmc_node.");
if (defined($new_bmc_username) and $new_bmc_username ne '') {
if ($new_bmc_username eq "ADMIN" or $new_bmc_username eq 'USERID') {
# ADMIN is username for OpenPOWER server, it is not allowed to modify at present
# USERID is username for IBM system x server, just modify password
`rspconfig $pbmc_node userid=2 password=$new_bmc_password`;
`rspconfig $bmc_node userid=2 password=$new_bmc_password`;
} else {
# For other username, we'd better create new user for them
`rspconfig $pbmc_node userid=3 username=$new_bmc_username password=$new_bmc_password`;
`rspconfig $bmc_node userid=3 username=$new_bmc_username password=$new_bmc_password`;
}
} else {
`rspconfig $pbmc_node password=$new_bmc_password`;
`rspconfig $bmc_node password=$new_bmc_password`;
}
# the rspconfig doesn't update node definition, need to modify manually for modifying bmc ip address
`chdef $pbmc_node bmcusername=$new_bmc_username bmcpassword=$new_bmc_password`;
`chdef $bmc_node bmcusername=$new_bmc_username bmcpassword=$new_bmc_password`;
#if ($new_bmc_password) {
# xCAT::Utils->runxcmd(
# {
# command => ["rspconfig"],
# node => ["$pbmc_node"],
# node => ["$bmc_node"],
# arg => [ "password=$new_bmc_password" ],
# },
# $subreq, 0,1);
@ -4491,13 +4491,13 @@ sub cleanup_for_powerLE_hardware_discovery {
# }
#}
xCAT::MsgUtils->message("S", "Discover info: configure ip:$new_bmc_ip for pbmc_node:$pbmc_node.");
`rspconfig $pbmc_node ip=$new_bmc_ip`;
xCAT::MsgUtils->message("S", "Discover info: configure ip:$new_bmc_ip for bmc_node:$bmc_node.");
`rspconfig $bmc_node ip=$new_bmc_ip`;
#if($new_bmc_ip) {
# xCAT::Utils->runxcmd(
# {
# command => ["rspconfig"],
# node => ["$pbmc_node"],
# node => ["$bmc_node"],
# arg => [ "ip=$new_bmc_ip" ],
# },
# $subreq, 0,1);
@ -4506,12 +4506,12 @@ sub cleanup_for_powerLE_hardware_discovery {
# return;
# }
#}
xCAT::MsgUtils->message("S", "Discovery info: remove pbmc_node:$pbmc_node.");
`rmdef $pbmc_node`;
xCAT::MsgUtils->message("S", "Discovery info: remove bmc_node:$bmc_node.");
`rmdef $bmc_node`;
#xCAT::Utils->runxcmd(
# {
# command => ["rmdef"],
# node => ["$pbmc_node"],
# node => ["$bmc_node"],
# },
# $subreq, 0,1);
}

View File

@ -1,4 +1,5 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# The first module to deal with hardware discovery request, write the request into "discoverydata" table only
package xCAT_plugin::aaadiscovery;
BEGIN
{
@ -18,17 +19,13 @@ sub process_request {
my $cb = shift;
my $doreq = shift;
if ($req->{command}->[0] eq 'findme') {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($req->{cacheonly}) or !($req->{cacheonly}->[0])) {
return;
}
if (defined($req->{discoverymethod}) and defined($req->{discoverymethod}->[0])) {
my $rsp = {};
$rsp->{error}->[0] = "The findme request had been processed by ".$req->{discoverymethod}->[0] ." module";
$cb->($rsp);
return;
}
xCAT::MsgUtils->message("S", __PACKAGE__.": Processing findme request, writting it into 'discoverydata' table");
xCAT::MsgUtils->message("S", "xcat.discovery.aaadiscovery: ($req->{mtm}->[0]*$req->{serial}->[0]) Get a discover request");
$req->{discoverymethod}->[0] = 'undef';
xCAT::DiscoveryUtils->update_discovery_data($req);
return;

View File

@ -4359,15 +4359,12 @@ sub process_request {
}
}
if ($request->{command}->[0] eq "findme") {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($request->{cacheonly}) or !($request->{cacheonly}->[0])) {
return;
}
if (defined($request->{discoverymethod}) and defined($request->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;
}
xCAT::MsgUtils->message("S", "xcat.discovery.blade: ($request->{mtm}->[0]*$request->{serial}->[0]) Processing discovery request");
my $mptab = xCAT::Table->new("mp");
unless ($mptab) { return 2; }
my @bladents = $mptab->getAllNodeAttribs([qw(node)]);
@ -4446,6 +4443,7 @@ sub process_request {
}
}
unless ($node) {
xCAT::MsgUtils->message("S", "xcat.discovery.blade: ($request->{mtm}->[0]*$request->{serial}->[0]) Error: Could not find any node");
return 1; #failure
}
if ($request->{mtm} and $request->{mtm} =~ /^(\w{4})/) {
@ -4461,16 +4459,18 @@ sub process_request {
undef $mactab;
}
xCAT::MsgUtils->message("S", "xcat.discovery.blade: ($request->{mtm}->[0]*$request->{serial}->[0]) Find node $node for the discovery request");
#my %request = (
# command => ['makedhcp'],
# node => [$macmap{$mac}]
# );
#$doreq->(\%request);
$request->{command}=['discovered'];
$request->{noderange} = [$node];
$request->{discoverymethod} = ['blade'];
$doreq->($request);
%{$request}=(); #Clear request. it is done
my $req = {%$request};
$req->{noderange} = [$node];
$req->{discoverymethod} = ['blade'];
$doreq->($req);
%{$req}=(); #Clear request. it is done
return 0;
}

View File

@ -685,15 +685,11 @@ sub process_request {
}
}
if ($request->{command}->[0] eq "findme") {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($request->{cacheonly}) or !($request->{cacheonly}->[0])) {
return;
}
if (defined($request->{discoverymethod}) and defined($request->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;
}
xCAT::MsgUtils->message("S", "xcat.discovery.hpblade: ($request->{mtm}->[0]*$request->{serial}->[0]) Processing discovery request");
my $mptab = xCAT::Table->new("mp");
unless ($mptab) { return 2; }
my @bladents = $mptab->getAllNodeAttribs([qw(node)]);
@ -737,21 +733,25 @@ sub process_request {
}
}
unless ($macmap{$mac}) {
xCAT::MsgUtils->message("S", "xcat.discovery.hpblade: ($request->{mtm}->[0]*$request->{serial}->[0]) Error: Could not find any node");
return 1; #failure
}
my $mactab = xCAT::Table->new('mac',-create=>1);
$mactab->setNodeAttribs($macmap{$mac},{mac=>$mac});
$mactab->close();
# 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);
$request->{command}=['discovered'];
$request->{noderange} = [$macmap{$mac}];
$doreq->($request);
%{$request}=(); #Clear request. it is done
undef $mactab;
xCAT::MsgUtils->message("S", "xcat.discovery.hpblade: ($request->{mtm}->[0]*$request->{serial}->[0]) Find node:$macmap{$mac} for the discovery request");
my $req={%$request};
$req->{command}=['discovered'];
$req->{noderange} = [$macmap{$mac}];
$doreq->($req);
%{$req}=(); #Clear request. it is done
#undef $mactab;
return 0;
}

View File

@ -373,8 +373,8 @@ sub process_request {
}
if (defined($request->{bmcinband})) {
syslog("local4|info", "The attribute bmcinband is specified, just remove the temp BMC node if there is");
if (defined($request->{pbmc_node}) and defined($request->{pbmc_node}->[0])) {
my $bmc_node = $request->{pbmc_node}->[0];
if (defined($request->{bmc_node}) and defined($request->{bmc_node}->[0])) {
my $bmc_node = $request->{bmc_node}->[0];
syslog("local4|info", "Find BMC $bmc_node, so remove it");
$doreq->({ command => ['rmdef'], arg => [$bmc_node]});
}

View File

@ -1816,10 +1816,6 @@ Usage:
#-------------------------------------------------------
sub findme{
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($request->{cacheonly}) or !($request->{cacheonly}->[0])) {
return;
}
if (defined($request->{discoverymethod}) and defined($request->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;

View File

@ -54,28 +54,16 @@ sub findme {
my @SEQdiscover = xCAT::TableUtils->get_site_attribute("__SEQDiscover");
my @PCMdiscover = xCAT::TableUtils->get_site_attribute("__PCMDiscover");
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($request->{cacheonly}) or !($request->{cacheonly}->[0])) {
return;
}
if (defined($request->{discoverymethod}) and defined($request->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;
}
unless ($SEQdiscover[0]) {
#if ($PCMdiscover[0]) {
#profile disocvery is running, then just return to make profile discovery to handle it
#return;
#}
# The request data have been write into discoverydata table within aaadiscover.pm, just return here
# update the discoverydata table to have an undefined node
#$request->{discoverymethod}->[0] = 'undef';
#xCAT::DiscoveryUtils->update_discovery_data($request);
return;
}
# do the sequential discovery
xCAT::MsgUtils->message("S", "Sequential Discovery: Processing");
xCAT::MsgUtils->message("S", "xcat.discovery.seqdiscovery: ($request->{mtm}->[0]*$request->{serial}->[0]) Processing discovery request");
# Get the parameters for the sequential discovery
my %param;
@ -88,7 +76,7 @@ sub findme {
my $mac;
my $ip = $request->{'_xcat_clientip'};
if (defined $request->{nodetype} and $request->{nodetype}->[0] eq 'virtual') {
xCAT::MsgUtils->message("S", "Sequential discovery does not support virtual machines, exiting...");
xCAT::MsgUtils->message("S", "xcat.discovery.seqdiscovery: ($request->{mtm}->[0]*$request->{serial}->[0]) Error: virtual machines is not supported");
return;
}
my $arptable;
@ -108,7 +96,7 @@ sub findme {
}
unless ($mac) {
xCAT::MsgUtils->message("S", "Discovery Error: Could not find the mac of the $ip.");
xCAT::MsgUtils->message("S", "xcat.discovery.seqdiscovery: ($request->{mtm}->[0]*$request->{serial}->[0]) Error: Could not find mac of the $ip");
return;
}
@ -140,13 +128,13 @@ sub findme {
$node = $allnodes[0];
}
}
my $pbmc_node = undef;
my $bmc_node = undef;
if ($request->{'mtm'}->[0] and $request->{'serial'}->[0]) {
my $mtms = $request->{'mtm'}->[0]."*".$request->{'serial'}->[0];
my $tmp_nodes = $::XCATVPDHASH{$mtms};
foreach (@$tmp_nodes) {
if ($::XCATMPHASH{$_}) {
$pbmc_node = $_;
$bmc_node = $_;
}
}
}
@ -385,14 +373,12 @@ sub findme {
# call the discovered command to update the discovery request to a node
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme request");
xCAT::MsgUtils->message("S", "xcat.discovery.seqdiscovery: ($request->{mtm}->[0]*$request->{serial}->[0]) Find node:$node for the discovery request");
$request->{discoverymethod} = ['sequential'];
my $req = {%$request};
$req->{command}=['discovered'];
$req->{noderange} = [$node];
if ($pbmc_node) {
$request->{pbmc_node} = [$pbmc_node];
}
$request->{bmc_node} = [$bmc_node];
$req->{updateswitch} = ['yes'];
$subreq->($req);
@ -400,6 +386,7 @@ sub findme {
undef $mactab;
} else {
nodediscoverstop($callback, undef, "node names");
xCAT::MsgUtils->message("S", "xcat.discovery.seqdiscovery: ($request->{mtm}->[0]*$request->{serial}->[0]) Error: Could not find any node");
return;
}

View File

@ -268,15 +268,11 @@ sub process_request {
}
return;
} elsif ($req->{command}->[0] eq 'findme') {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($req->{cacheonly}) or !($req->{cacheonly}->[0])) {
return;
}
if (defined($req->{discoverymethod}) and defined($req->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;
}
xCAT::MsgUtils->message("S", __PACKAGE__.": Processing findme request");
xCAT::MsgUtils->message("S", "xcat.discovery.switch: ($req->{mtm}->[0]*$req->{serial}->[0]) Processing discovery request");
my $ip = $req->{'_xcat_clientip'};
if (defined $req->{nodetype} and $req->{nodetype}->[0] eq 'virtual') {
#Don't attempt switch discovery of a VM Guest
@ -314,19 +310,19 @@ sub process_request {
if ($node) { last; }
}
}
my $pbmc_node = undef;
my $bmc_node = undef;
if ($req->{'mtm'}->[0] and $req->{'serial'}->[0]) {
my $mtms = $req->{'mtm'}->[0]."*".$req->{'serial'}->[0];
my $tmp_nodes = $::XCATVPDHASH{$mtms};
foreach (@$tmp_nodes) {
if ($::XCATMPHASH{$_}) {
$pbmc_node = $_;
$bmc_node = $_;
}
}
}
if ($node) {
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme request");
xCAT::MsgUtils->message("S", "xcat.discovery.switch: ($req->{mtm}->[0]*$req->{serial}->[0]) Find node:$node for the discovery request");
# No need to write mac table here, 'discovered' command will write
# my $mactab = xCAT::Table->new('mac',-create=>1);
# $mactab->setNodeAttribs($node,{mac=>$mac});
@ -340,12 +336,12 @@ sub process_request {
my $request = {%$req};
$request->{command}=['discovered'];
$request->{noderange} = [$node];
$request->{pbmc_node} = [$pbmc_node];
$request->{bmc_node} = [$bmc_node];
$doreq->($request);
%{$request}=();#Clear req structure, it's done..
undef $mactab;
} else {
#Shouldn't complain, might be blade, but how to log total failures?
xCAT::MsgUtils->message("S", "xcat.discovery.switch: ($req->{mtm}->[0]*$req->{serial}->[0]) Error: Could not find any node");
}
}
}

View File

@ -1,4 +1,5 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# Used to deal with MTMS(machine-type/model and serial) based hardware discovery
package xCAT_plugin::typemtms;
BEGIN
{
@ -21,31 +22,32 @@ sub findme {
}
my @attr_array = ();
my $mtms = $request->{'mtm'}->[0]."*".$request->{'serial'}->[0];
xCAT::MsgUtils->message("S", "xcat.discovery.mtms: ($mtms) Processing discovery request");
my $tmp_nodes = $::XCATVPDHASH{$mtms};
my @nodes = ();
my $pbmc_node;
my $bmc_node;
foreach (@$tmp_nodes) {
if ($::XCATMPHASH{$_}) {
$pbmc_node = $_;
$bmc_node = $_;
} else {
push @nodes, $_;
}
}
my $nodenum = $#nodes;
if ($nodenum < 0) {
xCAT::MsgUtils->message("S", "Discovery Error: Could not find any node.");
xCAT::MsgUtils->message("S", "xcat.discovery.mtms: ($mtms) Error: Could not find any node");
return;
} elsif ($nodenum > 0) {
xCAT::MsgUtils->message("S", "Discovery Error: More than one node were found.");
xCAT::MsgUtils->message("S", "xcat.discovery.mtms: ($mtms) Error: More than one node were found");
return;
}
{
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme request");
xCAT::MsgUtils->message("S", "xcat.discovery.mtms: ($mtms) Find node:$nodes[0] for the discovery request");
$request->{discoverymethod}->[0] = 'mtms';
my $req = {%$request};
$req->{command} = ['discovered'];
$req->{noderange} = [$nodes[0]];
$req->{pbmc_node} = [$pbmc_node];
$req->{bmc_node} = [$bmc_node];
$subreq->($req);
%{$req} = ();
}
@ -55,15 +57,10 @@ sub process_request {
my $cb = shift;
my $doreq = shift;
if ($req->{command}->[0] eq 'findme') {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($req->{cacheonly}) or !($req->{cacheonly}->[0])) {
return;
}
if (defined($req->{discoverymethod}) and defined($req->{discoverymethod}->[0])) {
# The findme request had been processed by other module, just return
return;
}
xCAT::MsgUtils->message("S", __PACKAGE__.": Processing findme request");
&findme($req, $callback, $doreq);
return;
}

View File

@ -1,4 +1,5 @@
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# The last module to deal with hardware discovery request, write information that which module can deal with this request or no module can deal with it at all
package xCAT_plugin::zzzdiscovery;
BEGIN
{
@ -16,18 +17,15 @@ sub process_request {
my $cb = shift;
my $doreq = shift;
if ($req->{command}->[0] eq 'findme') {
# The findme request is supposed to be dealt with in the first loop that cacheonly attribute is set for a request
if (!($req->{cacheonly}) or !($req->{cacheonly}->[0])) {
return;
}
xCAT::MsgUtils->message("S", __PACKAGE__.": Processing findme request");
xCAT::MsgUtils->message("S", "xcat.discovery.zzzdiscovery: ($req->{mtm}->[0]*$req->{serial}->[0]) Finish to process the discovery request");
if (!defined($req->{discoverymethod}) or !defined($req->{discoverymethod}->[0])) {
my $rsp = {};
$rsp->{error}->[0] = "The findme request can not be processed";
$rsp->{error}->[0] = "The discovery request can not be processed";
$cb->($rsp);
xCAT::MsgUtils->message("S", "xcat.discovery.zzzdiscovery: ($req->{mtm}->[0]*$req->{serial}->[0]) Failed to be processed");
return;
}
xCAT::MsgUtils->message("S", __PACKAGE__.": This findme request had been processed by $req->{discoverymethod}->[0] module");
xCAT::MsgUtils->message("S", "xcat.discovery.zzzdiscovery: ($req->{mtm}->[0]*$req->{serial}->[0]) Successfully processed by $req->{discoverymethod}->[0] method");
return;
}
}

View File

@ -625,12 +625,13 @@ sub do_discovery_process {
$req->{'_xcat_clientport'}=$sport;
if (defined($cmd_handlers{"findme"}) and xCAT::NetworkUtils->nodeonmynet($clientip)) { # only discover from ips that appear to be on a managed network
xCAT::MsgUtils->message("S","xcatd: Processing discovery request from ".$req->{'_xcat_clientip'});
$req->{cacheonly}->[0] = 1;
# Using cacheonly will cause the discovery processing running 2 times, cacheonly seems useless for switch.pm, so remove it
#$req->{cacheonly}->[0] = 1;
#plugin_command($req,undef,\&build_response);
#if ($req->{cacheonly}->[0]) {
#delete $req->{cacheonly};
plugin_command($req,undef,\&build_response);
if ($req->{cacheonly}->[0]) {
delete $req->{cacheonly};
plugin_command($req,undef,\&build_response);
}
#}
} else {
xCAT::MsgUtils->message("S","xcatd: Skipping discovery from ".$client." because we either have no discovery plugins or the client address does not match an IP network that xCAT is managing");
}