From 75bc7d91f43a07a64a1a34e3c6944f597f938043 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Fri, 24 Jun 2016 01:58:34 -0400 Subject: [PATCH] refine hardware discovery framework, put mtms based hardware discovery to typemtms.pm module --- xCAT-genesis-scripts/bin/dodiscovery | 13 +++- xCAT-server/lib/perl/xCAT/PPC.pm | 48 +------------ xCAT-server/lib/xcat/plugins/aaadiscovery.pm | 38 ++++++++++ xCAT-server/lib/xcat/plugins/blade.pm | 9 +++ xCAT-server/lib/xcat/plugins/fsp.pm | 1 - xCAT-server/lib/xcat/plugins/hpblade.pm | 9 +++ xCAT-server/lib/xcat/plugins/profilednodes.pm | 8 +++ xCAT-server/lib/xcat/plugins/seqdiscovery.pm | 36 ++++++---- xCAT-server/lib/xcat/plugins/switch.pm | 32 ++++++--- xCAT-server/lib/xcat/plugins/typemtms.pm | 71 +++++++++++++++++++ xCAT-server/lib/xcat/plugins/zzzdiscovery.pm | 34 +++++++++ 11 files changed, 227 insertions(+), 72 deletions(-) create mode 100644 xCAT-server/lib/xcat/plugins/aaadiscovery.pm create mode 100644 xCAT-server/lib/xcat/plugins/typemtms.pm create mode 100644 xCAT-server/lib/xcat/plugins/zzzdiscovery.pm diff --git a/xCAT-genesis-scripts/bin/dodiscovery b/xCAT-genesis-scripts/bin/dodiscovery index 3d5e3c522..5148e1dab 100755 --- a/xCAT-genesis-scripts/bin/dodiscovery +++ b/xCAT-genesis-scripts/bin/dodiscovery @@ -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 '' > /tmp/discopacket echo "findme" >> /tmp/discopacket +echo "1" >> /tmp/discopacket echo "$ARCH" >> /tmp/discopacket if [ "$IAMAVM" = 1 ]; then echo "virtual" >> /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 "" >> /tmp/discopacket done +if [ "$UUID" == "unknown" ]; then + UUID=`echo $MTM-$SERIAL-$MAC_OF_FIRST_UP_NIC | tr /A-Z/ /a-z/` + echo "$UUID" >> /tmp/discopacket +fi echo "$PUBKEY" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security echo "" >> /tmp/discopacket echo "" >> /tmp/discopacket diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index 9c7c3ba52..afd458a39 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -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 #################################### diff --git a/xCAT-server/lib/xcat/plugins/aaadiscovery.pm b/xCAT-server/lib/xcat/plugins/aaadiscovery.pm new file mode 100644 index 000000000..23a74091b --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/aaadiscovery.pm @@ -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; diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index b34da65aa..bca8d4cb4 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -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)]); diff --git a/xCAT-server/lib/xcat/plugins/fsp.pm b/xCAT-server/lib/xcat/plugins/fsp.pm index 9726685b6..53708d120 100644 --- a/xCAT-server/lib/xcat/plugins/fsp.pm +++ b/xCAT-server/lib/xcat/plugins/fsp.pm @@ -32,7 +32,6 @@ sub handled_commands { rscan => 'nodehm:mgt', getfspcon => 'nodehm:cons', getmulcon => 'fsp', - findme => 'fsp', }; } diff --git a/xCAT-server/lib/xcat/plugins/hpblade.pm b/xCAT-server/lib/xcat/plugins/hpblade.pm index 156de8071..76b257abc 100755 --- a/xCAT-server/lib/xcat/plugins/hpblade.pm +++ b/xCAT-server/lib/xcat/plugins/hpblade.pm @@ -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)]); diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm index 69067866a..818da4c21 100644 --- a/xCAT-server/lib/xcat/plugins/profilednodes.pm +++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm @@ -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. diff --git a/xCAT-server/lib/xcat/plugins/seqdiscovery.pm b/xCAT-server/lib/xcat/plugins/seqdiscovery.pm index dad597b05..64a0e8138 100755 --- a/xCAT-server/lib/xcat/plugins/seqdiscovery.pm +++ b/xCAT-server/lib/xcat/plugins/seqdiscovery.pm @@ -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"); diff --git a/xCAT-server/lib/xcat/plugins/switch.pm b/xCAT-server/lib/xcat/plugins/switch.pm index 1ae78f71a..ce47596be 100644 --- a/xCAT-server/lib/xcat/plugins/switch.pm +++ b/xCAT-server/lib/xcat/plugins/switch.pm @@ -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? diff --git a/xCAT-server/lib/xcat/plugins/typemtms.pm b/xCAT-server/lib/xcat/plugins/typemtms.pm new file mode 100644 index 000000000..63c69b492 --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/typemtms.pm @@ -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; diff --git a/xCAT-server/lib/xcat/plugins/zzzdiscovery.pm b/xCAT-server/lib/xcat/plugins/zzzdiscovery.pm new file mode 100644 index 000000000..8de0e5eaa --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/zzzdiscovery.pm @@ -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;