mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-22 11:42:05 +00:00
refine hardware discovery framework, put mtms based hardware discovery to typemtms.pm module
This commit is contained in:
parent
439f227efc
commit
75bc7d91f4
@ -91,7 +91,9 @@ elif [ -r /proc/device-tree/model ]; then #POWER
|
||||
done
|
||||
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
|
||||
SERIAL=`cat /proc/device-tree/system-id -vT | sed -e 's/^.*,//' | sed -e 's/^[\t ]*//'| sed -e 's/[\t ]*\^@//'`
|
||||
UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /proc/sys/kernel/random/uuid`
|
||||
# For POWER servers, the /proc/sys/kernel/random/uuid is changing for each query, so use mtms + mac of first up nic as the UUID
|
||||
#UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /proc/sys/kernel/random/uuid`
|
||||
UUID=unknown
|
||||
|
||||
fi
|
||||
#CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l`
|
||||
@ -115,6 +117,7 @@ DISKSIZE=`cat /proc/partitions |grep -e "sd.\>" |awk -F' ' '{printf "%s:%.0fGB\n
|
||||
logger -t $log_label -p local4.info "Beginning echo infomation to discovery packet file..."
|
||||
echo '<xcatrequest>' > /tmp/discopacket
|
||||
echo "<command>findme</command>" >> /tmp/discopacket
|
||||
echo "<sequential>1</sequential>" >> /tmp/discopacket
|
||||
echo "<arch>$ARCH</arch>" >> /tmp/discopacket
|
||||
if [ "$IAMAVM" = 1 ]; then
|
||||
echo "<nodetype>virtual</nodetype>" >> /tmp/discopacket
|
||||
@ -166,6 +169,7 @@ if [ -f "/usr/sbin/dmidecode" ]; then
|
||||
fi
|
||||
done
|
||||
fi
|
||||
MAC_OF_FIRST_UP_NIC=unknown
|
||||
#TODO: downed nics, also examine /sys/bus/pci/*/ for more network class devices that might not have driver suppert
|
||||
for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v usb0`; do
|
||||
FIRMDESC=""
|
||||
@ -174,6 +178,9 @@ for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v
|
||||
PCI_SLOT=`grep PCI_SLOT_NAME /sys/class/net/$dev/device/uevent|awk -F= '{print $2}'`
|
||||
ADDRESS=`ip address show dev $dev|grep "inet "|grep global|awk '{print $2}'`
|
||||
MAC=`ip link show dev $dev|grep ether|awk '{print $2}'| tr /a-f/ /A-F/`
|
||||
if [ "$MAC_OF_FIRST_UP_NIC" == "unknown" ]; then
|
||||
MAC_OF_FIRST_UP_NIC=`echo $MAC | sed -e s/://g`
|
||||
fi
|
||||
if [[ ! -z "$PCI_SLOT" && -f "/usr/sbin/dmidecode" ]]; then
|
||||
SLOTNAME=`dmidecode -t 9|egrep '(Designation|Address)'|grep -B1 $PCI_SLOT|grep Designation|sed -e 's/.*Designation:[ ]*//'`
|
||||
if [ -z "$SLOTNAME" ]; then #check for on board device
|
||||
@ -234,6 +241,10 @@ for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://|grep -v
|
||||
|
||||
echo "</nic>" >> /tmp/discopacket
|
||||
done
|
||||
if [ "$UUID" == "unknown" ]; then
|
||||
UUID=`echo $MTM-$SERIAL-$MAC_OF_FIRST_UP_NIC | tr /A-Z/ /a-z/`
|
||||
echo "<uuid>$UUID</uuid>" >> /tmp/discopacket
|
||||
fi
|
||||
echo "<xcatpubkey>$PUBKEY</xcatpubkey>" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security
|
||||
echo "<sha512sig>" >> /tmp/discopacket
|
||||
echo "</sha512sig>" >> /tmp/discopacket
|
||||
|
@ -2135,44 +2135,7 @@ sub parse_args
|
||||
}
|
||||
|
||||
|
||||
sub findme {
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
my $subreq = shift;
|
||||
if (!defined $request->{'mtm'} or !defined $request->{'serial'}) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: 'mtm' or 'serial' not found.");
|
||||
return;
|
||||
}
|
||||
my @attr_array = ();
|
||||
my $mtms = $request->{'mtm'}->[0]."*".$request->{'serial'}->[0];
|
||||
my $tmp_nodes = $::XCATVPDHASH{$mtms};
|
||||
my @nodes = ();
|
||||
my $pbmc_node;
|
||||
foreach (@$tmp_nodes) {
|
||||
if ($::XCATMPHASH{$_}) {
|
||||
$pbmc_node = $_;
|
||||
} else {
|
||||
push @nodes, $_;
|
||||
}
|
||||
}
|
||||
my $nodenum = $#nodes;
|
||||
if ($nodenum < 0) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: Could not find any node.");
|
||||
return;
|
||||
} elsif ($nodenum > 0) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: More than one node were found.");
|
||||
return;
|
||||
}
|
||||
{
|
||||
my $req = {%$request};
|
||||
$req->{command} = ['discovered'];
|
||||
$req->{noderange} = [$nodes[0]];
|
||||
$req->{pbmc_node} = [$pbmc_node];
|
||||
$req->{discoverymethod} = ['mtms'];
|
||||
$subreq->($req);
|
||||
%{$req} = ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Process request from xCat daemon
|
||||
@ -2188,15 +2151,6 @@ sub process_request {
|
||||
# Get hwtype
|
||||
####################################
|
||||
$package =~ s/xCAT_plugin:://;
|
||||
|
||||
####################################
|
||||
# Deal with findme request
|
||||
####################################
|
||||
if ($req->{command}->[0] eq 'findme') {
|
||||
# Need to support both ppc64 and ppc64le, maybe also x86_64. Will be move out later.
|
||||
&findme($req, $callback, $subreq);
|
||||
return;
|
||||
}
|
||||
####################################
|
||||
# Build hash to pass around
|
||||
####################################
|
||||
|
38
xCAT-server/lib/xcat/plugins/aaadiscovery.pm
Normal file
38
xCAT-server/lib/xcat/plugins/aaadiscovery.pm
Normal file
@ -0,0 +1,38 @@
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
package xCAT_plugin::aaadiscovery;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use xCAT::DiscoveryUtils;
|
||||
|
||||
sub handled_commands {
|
||||
return {
|
||||
findme => 'aaadiscovery',
|
||||
};
|
||||
}
|
||||
|
||||
sub process_request {
|
||||
my $req = shift;
|
||||
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");
|
||||
$req->{discoverymethod}->[0] = 'undef';
|
||||
xCAT::DiscoveryUtils->update_discovery_data($req);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
@ -4359,6 +4359,15 @@ 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;
|
||||
}
|
||||
|
||||
my $mptab = xCAT::Table->new("mp");
|
||||
unless ($mptab) { return 2; }
|
||||
my @bladents = $mptab->getAllNodeAttribs([qw(node)]);
|
||||
|
@ -32,7 +32,6 @@ sub handled_commands {
|
||||
rscan => 'nodehm:mgt',
|
||||
getfspcon => 'nodehm:cons',
|
||||
getmulcon => 'fsp',
|
||||
findme => 'fsp',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -685,6 +685,15 @@ 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;
|
||||
}
|
||||
|
||||
my $mptab = xCAT::Table->new("mp");
|
||||
unless ($mptab) { return 2; }
|
||||
my @bladents = $mptab->getAllNodeAttribs([qw(node)]);
|
||||
|
@ -1816,6 +1816,14 @@ 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;
|
||||
}
|
||||
# re-initalize the global variable
|
||||
%args_dict = ();
|
||||
# Read DB to confirm the discover is started.
|
||||
|
@ -50,17 +50,27 @@ sub findme {
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
my $subreq = shift;
|
||||
|
||||
|
||||
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]) {
|
||||
#if ($PCMdiscover[0]) {
|
||||
#profile disocvery is running, then just return to make profile discovery to handle it
|
||||
return;
|
||||
}
|
||||
#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);
|
||||
#$request->{discoverymethod}->[0] = 'undef';
|
||||
#xCAT::DiscoveryUtils->update_discovery_data($request);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -375,16 +385,18 @@ sub findme {
|
||||
|
||||
# call the discovered command to update the discovery request to a node
|
||||
|
||||
$request->{command}=['discovered'];
|
||||
$request->{noderange} = [$node];
|
||||
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme request");
|
||||
$request->{discoverymethod} = ['sequential'];
|
||||
my $req = {%$request};
|
||||
$req->{command}=['discovered'];
|
||||
$req->{noderange} = [$node];
|
||||
if ($pbmc_node) {
|
||||
$request->{pbmc_node} = [$pbmc_node];
|
||||
}
|
||||
|
||||
$request->{discoverymethod} = ['sequential'];
|
||||
$request->{updateswitch} = ['yes'];
|
||||
$subreq->($request);
|
||||
%{$request}=();#Clear req structure, it's done..
|
||||
$req->{updateswitch} = ['yes'];
|
||||
$subreq->($req);
|
||||
%{$req}=();#Clear req structure, it's done..
|
||||
undef $mactab;
|
||||
} else {
|
||||
nodediscoverstop($callback, undef, "node names");
|
||||
|
@ -268,6 +268,15 @@ 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");
|
||||
my $ip = $req->{'_xcat_clientip'};
|
||||
if (defined $req->{nodetype} and $req->{nodetype}->[0] eq 'virtual') {
|
||||
#Don't attempt switch discovery of a VM Guest
|
||||
@ -317,22 +326,23 @@ sub process_request {
|
||||
}
|
||||
|
||||
if ($node) {
|
||||
my $mactab = xCAT::Table->new('mac',-create=>1);
|
||||
$mactab->setNodeAttribs($node,{mac=>$mac});
|
||||
$mactab->close();
|
||||
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme 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});
|
||||
# $mactab->close();
|
||||
#my %request = (
|
||||
# command => ['makedhcp'],
|
||||
# node => [$node]
|
||||
#);
|
||||
#$doreq->(\%request);
|
||||
$req->{command}=['discovered'];
|
||||
$req->{noderange} = [$node];
|
||||
if ($pbmc_node) {
|
||||
$req->{pbmc_node} = [$pbmc_node];
|
||||
}
|
||||
$req->{discoverymethod} = ['switch'];
|
||||
$doreq->($req);
|
||||
%{$req}=();#Clear req structure, it's done..
|
||||
$req->{discoverymethod}->[0] = 'switch';
|
||||
my $request = {%$req};
|
||||
$request->{command}=['discovered'];
|
||||
$request->{noderange} = [$node];
|
||||
$request->{pbmc_node} = [$pbmc_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?
|
||||
|
71
xCAT-server/lib/xcat/plugins/typemtms.pm
Normal file
71
xCAT-server/lib/xcat/plugins/typemtms.pm
Normal file
@ -0,0 +1,71 @@
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
package xCAT_plugin::typemtms;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
|
||||
sub handled_commands {
|
||||
return {
|
||||
findme => 'typemtms',
|
||||
};
|
||||
}
|
||||
sub findme {
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
my $subreq = shift;
|
||||
if (!defined $request->{'mtm'} or !defined $request->{'serial'}) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: 'mtm' or 'serial' not found.");
|
||||
return;
|
||||
}
|
||||
my @attr_array = ();
|
||||
my $mtms = $request->{'mtm'}->[0]."*".$request->{'serial'}->[0];
|
||||
my $tmp_nodes = $::XCATVPDHASH{$mtms};
|
||||
my @nodes = ();
|
||||
my $pbmc_node;
|
||||
foreach (@$tmp_nodes) {
|
||||
if ($::XCATMPHASH{$_}) {
|
||||
$pbmc_node = $_;
|
||||
} else {
|
||||
push @nodes, $_;
|
||||
}
|
||||
}
|
||||
my $nodenum = $#nodes;
|
||||
if ($nodenum < 0) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: Could not find any node.");
|
||||
return;
|
||||
} elsif ($nodenum > 0) {
|
||||
xCAT::MsgUtils->message("S", "Discovery Error: More than one node were found.");
|
||||
return;
|
||||
}
|
||||
{
|
||||
xCAT::MsgUtils->message("S", __PACKAGE__.": Find a node for the findme request");
|
||||
$request->{discoverymethod}->[0] = 'mtms';
|
||||
my $req = {%$request};
|
||||
$req->{command} = ['discovered'];
|
||||
$req->{noderange} = [$nodes[0]];
|
||||
$req->{pbmc_node} = [$pbmc_node];
|
||||
$subreq->($req);
|
||||
%{$req} = ();
|
||||
}
|
||||
}
|
||||
sub process_request {
|
||||
my $req = shift;
|
||||
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;
|
||||
}
|
||||
}
|
||||
1;
|
34
xCAT-server/lib/xcat/plugins/zzzdiscovery.pm
Normal file
34
xCAT-server/lib/xcat/plugins/zzzdiscovery.pm
Normal file
@ -0,0 +1,34 @@
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
package xCAT_plugin::zzzdiscovery;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
|
||||
sub handled_commands {
|
||||
return {
|
||||
findme => 'zzzdiscovery',
|
||||
};
|
||||
}
|
||||
sub process_request {
|
||||
my $req = shift;
|
||||
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");
|
||||
if (!defined($req->{discoverymethod}) or !defined($req->{discoverymethod}->[0])) {
|
||||
my $rsp = {};
|
||||
$rsp->{error}->[0] = "The findme request can not be processed";
|
||||
$cb->($rsp);
|
||||
return;
|
||||
}
|
||||
xCAT::MsgUtils->message("S", __PACKAGE__.": This findme request had been processed by $req->{discoverymethod}->[0] module");
|
||||
return;
|
||||
}
|
||||
}
|
||||
1;
|
Loading…
x
Reference in New Issue
Block a user