diff --git a/xCAT-genesis-scripts/bin/dodiscovery b/xCAT-genesis-scripts/bin/dodiscovery
index 41ecb8c05..e870783fb 100755
--- a/xCAT-genesis-scripts/bin/dodiscovery
+++ b/xCAT-genesis-scripts/bin/dodiscovery
@@ -141,10 +141,12 @@ if [ "$UUID" != "unknown" ]; then
echo "$UUID" >> /tmp/discopacket
fi
-if [ "$MTM" != "unknown" ]; then
+flag_mtm=`echo '$MTM' | sed 's/0//g'`
+if [ $flag_mtm ] && [ "$MTM" != "unknown" ]; then
echo "$MTM" >> /tmp/discopacket
fi
-if [ "$SERIAL" != "unknown" ]; then
+flag_serial=`echo '$SERIAL' | sed 's/0//g'`
+if [ $flag_serial ] && [ "$SERIAL" != "unknown" ]; then
echo "$SERIAL" >> /tmp/discopacket
fi
if [ "$PLATFORM" != "unknown" ]; then
@@ -159,6 +161,11 @@ if [ "$IsStatic" ]; then
fi
fi
+BMCMAC=`ipmitool lan print 1 | grep 'MAC Address' | cut -d ":" -f2-7 | sed 's/ //'`
+if [ "$BMCMAC" ]; then
+ echo "$BMCMAC" >> /tmp/discopacket
+fi
+
# Check whether the hardware support in-band BMC configuration with the IPMI device
if [ -r /dev/ipmi0 -o -r /dev/ipmi/0 -o -r /dev/ipmidev/0 ]; then
echo "1" >> /tmp/discopacket
diff --git a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm
index e29059be1..b0406a037 100644
--- a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm
+++ b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm
@@ -35,6 +35,7 @@ use HTTP::Response;
use JSON;
my $nmap_path;
+my %ipmac = ();
my $debianflag = 0;
my $tempstring = xCAT::Utils->osver();
@@ -508,43 +509,56 @@ sub scan_process {
# Handle commas in $range for nmap
$range =~ tr/,/ /;
- my $ip_list;
############################################################
# get live ip list
###########################################################
- if ($method eq "nmap") {
-
- #check nmap version first
- my $nmap_version = xCAT::Utils->get_nmapversion();
-
- # the output of nmap is different for version under 5.10
- if (xCAT::Utils->version_cmp($nmap_version, "5.10") < 0) {
- $bcmd = join(" ", $nmap_path, " -sP -n $range | grep \"appears to be up\" |cut -d ' ' -f2 |tr -s '\n' ' ' ");
- } else {
- $bcmd = join(" ", $nmap_path, " -sn -n $range | grep -B1 up | grep \"Nmap scan report\" |cut -d ' ' -f5 |tr -s '\n' ' ' ");
- }
-
- $ip_list = xCAT::Utils->runcmd("$bcmd", -1);
- if ($::RUNCMD_RC != 0) {
- my $rsp = {};
- push @{ $rsp->{data} }, "Nmap scan is failed.\n";
- xCAT::MsgUtils->message("E", $rsp, $::CALLBACK);
- return 2;
- }
-
- }
- else
- {
+ if ($method ne "nmap") {
my $rsp = {};
push @{ $rsp->{data} }, "The bmcdiscover method should be nmap.\n";
xCAT::MsgUtils->message("E", $rsp, $::CALLBACK);
return 2;
}
- my $live_ip = split_comma_delim_str($ip_list);
+ #check nmap version first
+ my $nmap_version = xCAT::Utils->get_nmapversion();
+ my $ip_info_list;
+
+ # the output of nmap is different for version under 5.10
+ if (xCAT::Utils->version_cmp($nmap_version, "5.10") < 0) {
+ $bcmd = join(" ", $nmap_path, " -sP -n $range");
+ } else {
+ $bcmd = join(" ", $nmap_path, " -sn -n $range");
+ }
+
+ $ip_info_list = xCAT::Utils->runcmd("$bcmd", -1);
+ if ($::RUNCMD_RC != 0) {
+ my $rsp = {};
+ push @{ $rsp->{data} }, "Nmap scan is failed.\n";
+ xCAT::MsgUtils->message("E", $rsp, $::CALLBACK);
+ return 2;
+ }
+
+ my $ip_list;
+ my $mac_list;
+ if (xCAT::Utils->version_cmp($nmap_version, "5.10") < 0) {
+ $ip_list = `echo -e "$ip_info_list" | grep \"appears to be up\" |cut -d ' ' -f2 |tr -s '\n' ' '`;
+ $mac_list = `echo -e "$ip_info_list" | grep -A1 up | grep "MAC Address" | cut -d ' ' -f3 | tr -s '\n' ' '`;
+ } else {
+ $ip_list = `echo -e "$ip_info_list" | grep -B1 up | grep "Nmap scan report" |cut -d ' ' -f5 | tr -s '\n' ' '`;
+ $mac_list = `echo -e "$ip_info_list" | grep -A1 up | grep "MAC Address" | cut -d ' ' -f3 | tr -s '\n' ' '`;
+ }
+
+ my $live_ip = split_comma_delim_str($ip_list);
+ my $live_mac = split_comma_delim_str($mac_list);
+
+ if (scalar(@{$live_ip}) > 0) {
+
+ foreach (@{$live_ip}) {
+ my $new_mac = lc(shift @{$live_mac});
+ $new_mac =~ s/\://g;
+ $ipmac{$_} = $new_mac;
+ }
- if (scalar(@{$live_ip}) > 0)
- {
###############################
# Set the signal handler for ^c
###############################
@@ -984,8 +998,12 @@ sub bmcdiscovery_ipmi {
}
}
- if ($mtm eq '' or $serial eq '') {
- xCAT::MsgUtils->message("W", { data => ["BMC Type/Model and/or Serial is unavailable for $ip"] }, $::CALLBACK);
+
+ $mtm = '' if ($mtm =~ /^0+$/);
+ $serial = '' if ($serial =~ /^0+$/);
+
+ unless (($mtm or $serial) or $ipmac{$ip}) {
+ xCAT::MsgUtils->message("W", { data => ["BMC Type/Model and/or Serial and MAC Address is unavailable for $ip"] }, $::CALLBACK);
return;
}
@@ -1005,6 +1023,8 @@ sub bmcdiscovery_ipmi {
$node = "node-$mtm-$serial";
$node =~ s/(.*)/\L$1/g;
$node =~ s/[\s:\._]/-/g;
+ } else {
+ $node = "node-$ipmac{$ip}";
}
} elsif ($output =~ /error : unauthorized name/) {
xCAT::MsgUtils->message("W", { data => ["BMC username is incorrect for $ip"] }, $::CALLBACK);
@@ -1093,9 +1113,6 @@ sub bmcdiscovery_openbmc{
$mtm = "";
}
$serial = $response->{data}->{SerialNumber};
- } else {
- xCAT::MsgUtils->message("W", { data => ["Could not obtain Model Type and/or Serial Number for BMC at $ip"] }, $::CALLBACK);
- return;
}
} else {
@@ -1107,6 +1124,14 @@ sub bmcdiscovery_openbmc{
$mtm =~ s/^\s+|\s+$//g;
$serial =~ s/^\s+|\s+$//g;
+ $mtm = '' if ($mtm =~ /^0+$/);
+ $serial = '' if ($serial =~ /^0+$/);
+
+ unless (($mtm or $serial) or $ipmac{$ip}) {
+ xCAT::MsgUtils->message("W", { data => ["Could not obtain Valid Model Type and/or Serial Number and MAC Address for BMC at $ip"] }, $::CALLBACK);
+ return;
+ }
+
# format info string for format_stanza function
$node_data .= ",$mtm";
$node_data .= ",$serial";
@@ -1124,6 +1149,8 @@ sub bmcdiscovery_openbmc{
$node = "node-$mtm-$serial";
$node =~ s/(.*)/\L$1/g;
$node =~ s/[\s:\._]/-/g;
+ } else {
+ $node = "node-$ipmac{$ip}";
}
} else {
if ($login_response->status_line =~ /401 Unauthorized/) {
diff --git a/xCAT-server/lib/xcat/plugins/seqdiscovery.pm b/xCAT-server/lib/xcat/plugins/seqdiscovery.pm
index 3bc482215..ea114681f 100755
--- a/xCAT-server/lib/xcat/plugins/seqdiscovery.pm
+++ b/xCAT-server/lib/xcat/plugins/seqdiscovery.pm
@@ -141,6 +141,14 @@ sub findme {
}
}
+ unless ($bmc_node) {
+ if ($request->{'bmcmac'}->[0]) {
+ my $bmcmac = lc($request->{'bmcmac'}->[0]);
+ $bmcmac =~ s/\://g;
+ my $tmp_node = "node-$bmcmac";
+ $bmc_node = $tmp_node if ($::XCATMPHASH{$tmp_node});
+ }
+ }
if ($node) {
my $skiphostip;
diff --git a/xCAT-server/lib/xcat/plugins/switch.pm b/xCAT-server/lib/xcat/plugins/switch.pm
index 09e4052d9..dff93d270 100644
--- a/xCAT-server/lib/xcat/plugins/switch.pm
+++ b/xCAT-server/lib/xcat/plugins/switch.pm
@@ -346,6 +346,15 @@ sub process_request {
}
}
+ unless ($bmc_node) {
+ if ($req->{'bmcmac'}->[0]) {
+ my $bmcmac = lc($req->{'bmcmac'}->[0]);
+ $bmcmac =~ s/\://g;
+ my $tmp_node = "node-$bmcmac";
+ $bmc_node = $tmp_node if ($::XCATMPHASH{$tmp_node});
+ }
+ }
+
if ($node) {
xCAT::MsgUtils->message("S", "xcat.discovery.switch: ($req->{_xcat_clientmac}->[0]) Found node: $node");
diff --git a/xCAT-server/lib/xcat/plugins/typemtms.pm b/xCAT-server/lib/xcat/plugins/typemtms.pm
index bd30c9503..b6bcb9817 100644
--- a/xCAT-server/lib/xcat/plugins/typemtms.pm
+++ b/xCAT-server/lib/xcat/plugins/typemtms.pm
@@ -34,6 +34,16 @@ sub findme {
push @nodes, $_;
}
}
+
+ unless ($bmc_node) {
+ if ($request->{'bmcmac'}->[0]) {
+ my $bmcmac = lc($request->{'bmcmac'}->[0]);
+ $bmcmac =~ s/\://g;
+ my $tmp_node = "node-$bmcmac";
+ $bmc_node = $tmp_node if ($::XCATMPHASH{$tmp_node});
+ }
+ }
+
my $nodenum = $#nodes;
if ($nodenum < 0) {
xCAT::MsgUtils->message("S", "xcat.discovery.mtms: ($request->{_xcat_clientmac}->[0]) Warning: Could not find any node for $mtms using mtms-based discovery");