From 2729ec1ec9ccde183d0c0d822f28c32ba91306e4 Mon Sep 17 00:00:00 2001 From: huweihua Date: Sun, 22 Nov 2015 03:37:10 -0500 Subject: [PATCH 01/19] used for support getadapters command --- xCAT-genesis-scripts/bin/getadapter | 113 ++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 xCAT-genesis-scripts/bin/getadapter diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter new file mode 100644 index 000000000..5677a8919 --- /dev/null +++ b/xCAT-genesis-scripts/bin/getadapter @@ -0,0 +1,113 @@ +#!/bin/bash +#set -x + +XCATPORT=3001 +export XCATPORT + +#XCATMASTER="10.3.5.21" +ADAPTERFILE="/tmp/adapterinfo" +SCANNICLOG="/tmp/adapterscan.log" + +if [ -f "$SCANNICLOG" ]; then + rm -f "$SCANNICLOG" 2>&1 >/dev/null +fi + +if [ -f "$ADAPTERFILE" ]; then + echo "rm -f $ADAPTERFILE" > "$SCANNICLOG" + rm -f "$ADAPTERFILE" 2>&1 >> "$SCANNICLOG" +fi + + +echo '' > "$ADAPTERFILE" +echo "findadapter" >> "$ADAPTERFILE" +echo "cli" >> "$ADAPTERFILE" +echo "$HOSTNAME" >> "$ADAPTERFILE" + +#scan adapters have recognized by operating system +for nic in `ls /sys/class/net/`; do + if [ "$nic" == "lo" ]; then + continue + else + echo '' >> "$ADAPTERFILE" + tmp=`udevadm info /sys/class/net/"$nic" | grep " INTERFACE" | awk -F '=' '{print $2}'` + if [ ! -z "$tmp" ]; then + echo "$tmp" >> "$ADAPTERFILE" + fi + tmp=`udevadm info /sys/class/net/"$nic" | grep ID_NET_NAME | awk -F '=' '{print $2}'|sort -u| tr -s "\n" "," | sed "s/,$//g"` + if [ ! -z "$tmp" ]; then + echo "$tmp" >> "$ADAPTERFILE" + fi + tmp=`udevadm info /sys/class/net/"$nic" | grep DEVPATH | awk -F 'devices' '{print $2}'` + if [ ! -z "$tmp" ]; then + echo "${tmp%/net*}" >> "$ADAPTERFILE" + fi + tmp=`udevadm info /sys/class/net/"$nic" | grep ID_NET_NAME_MAC | awk -F '=' '{print $2}'` + if [ ! -z "$tmp" ]; then + echo "${tmp##*enx}" >> "$ADAPTERFILE" + fi + tmp=`udevadm info /sys/class/net/"$nic" | grep ID_VENDOR_FROM_DATABASE | awk -F '=' '{print $2}' | tr -s "\n" "," | sed "s/,$//g"` + if [ ! -z "$tmp" ]; then + echo "$tmp" >> "$ADAPTERFILE" + fi + tmp=`udevadm info /sys/class/net/"$nic" | grep ID_MODEL_FROM_DATABASE | awk -F '=' '{print $2}'` + if [ ! -z "$tmp" ]; then + echo "$tmp" >> "$ADAPTERFILE" + fi + echo '' >> "$ADAPTERFILE" + fi +done + +for pci in `lspci |grep Ethernet |awk '{print $1}' `; do + if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then + tmp=`lspci |grep "$pci"` + echo '' >> "$ADAPTERFILE" + echo "$pci" >> "$ADAPTERFILE" + echo "${tmp##*:}" >> "$ADAPTERFILE" + echo '' >> "$ADAPTERFILE" + fi +done + +for pci in `lspci |grep Network |awk '{print $1}' `; do + if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then + tmp=`lspci |grep "$pci"` + echo '' >> "$ADAPTERFILE" + echo "$pci" >> "$ADAPTERFILE" + echo "${tmp##*: }" >> "$ADAPTERFILE" + echo '' >> "$ADAPTERFILE" + fi +done + +for pci in `lspci |grep Mellanox |awk '{print $1}' `; do + if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then + tmp=`lspci |grep "$pci"` + echo '' >> "$ADAPTERFILE" + echo "$pci" >> "$ADAPTERFILE" + echo "${tmp##*: }" >> "$ADAPTERFILE" + echo '' >> "$ADAPTERFILE" + fi +done + +echo "" >> "$ADAPTERFILE" + +#cat "$ADAPTERFILE" + +if [ ! -z "$XCATMASTER" ]; then + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available + echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" + else + echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" + fi +else + for dhcps in `cat /var/lib/dhclient/dhclient.leases |grep dhcp-server|awk '{print $3}'|uniq|sed "s/;$//g"`; do + echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available + cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT 2>&1 >>"$SCANNICLOG" + else + echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT 2>&1 >>"$SCANNICLOG" + fi + done +fi + From 98da02d63182514f94eb78ae7ec1f0b10c4e80a5 Mon Sep 17 00:00:00 2001 From: huweihua Date: Sun, 22 Nov 2015 03:38:20 -0500 Subject: [PATCH 02/19] used for support getadapters command --- xCAT-server/lib/xcat/plugins/getadapter.pm | 450 +++++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 xCAT-server/lib/xcat/plugins/getadapter.pm diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm new file mode 100644 index 000000000..b01c4a42b --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -0,0 +1,450 @@ +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- + +=head1 + xCAT plugin package to handle getadapters management + + Supported command: + getadapters->getadapters + findadapter->getadapters + +=cut + +#------------------------------------------------------- +package xCAT_plugin::getadapter; + +BEGIN{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; +} +use lib "$::XCATROOT/lib/perl"; + +use xCAT::Table; +use xCAT::Utils; +use xCAT::MsgUtils; +use Data::Dumper; +use Getopt::Long; +use IO::Select; +use Term::ANSIColor; +use Time::Local; + +my %usage = ( + "getadapters" => "Usage:\n\tgetadapters [-h|--help|-v|--version|V]\n\tgetadapters [-f]", +); + +my $inforootdir = "/var/lib/xcat/adapters/"; +my $VERBOSE=0; +#------------------------------------------------------- + +=head3 handled_commands + +Return list of commands handled by this plugin + +=cut + +#------------------------------------------------------- + +sub handled_commands +{ + return { + getadapters => "getadapter", + findadapter => "getadapter", + }; +} + +#------------------------------------------------------- + +=head3 process_request + + Process the command + +=cut + +#------------------------------------------------------- +sub process_request +{ + my $request = shift; + my $callback = shift; + my $subreq = shift; + my $command = $request->{command}->[0]; + + if ($command eq "getadapters"){ + &handle_getadapters($request, $callback, $subreq); + } + + if ($command eq "findadapter"){ + &handle_findadapter($request, $callback); + } + + return; +} + +sub handle_getadapters{ + my $request = shift; + my $callback = shift; + my $subreq = shift; + my $command = $request->{command}->[0]; + + my @args=(); + my $HELP; + my $VERSION; + my $FORCE; + if (ref($request->{arg})) { + @args=@{$request->{arg}}; + } else { + @args=($request->{arg}); + } + @ARGV = @args; + Getopt::Long::Configure("bundling"); + Getopt::Long::Configure("no_pass_through"); + if (!GetOptions("h|help" => \$HELP, + "v|version" => \$VERSION, + "f" => \$FORCE, + "V" => \$VERBOSE + ) ) { + if($usage{$command}) { + my $rsp = {}; + $rsp->{error}->[0] = $usage{$command}; + $rsp->{errorcode}->[0] = 1; + $callback->($rsp); + } + return; + } + + if ($HELP) { + if($usage{$command}) { + my %rsp; + $rsp{data}->[0]=$usage{$command}; + $callback->(\%rsp); + } + return; + } + + if ($VERSION) { + my $ver = xCAT::Utils->Version(); + my %rsp; + $rsp{data}->[0]="$ver"; + $callback->(\%rsp); + return; + } + + my $tmpnodes = join(",", @{$request->{node}}); + my $tmpargs = join(",", @args); + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: handling command <$command $tmpnodes $tmpargs>"); + + if($FORCE || ! -d $inforootdir) { + my @tmpnodes = @{$request->{node}}; + $request->{missnode} = \@tmpnodes; + &scan_adapters($request, $callback, $subreq); + }else{ + my @nodes = @{$request->{node}}; + my $node; + my @missnodes = (); + foreach $node (@nodes){ + if ( ! -e "$inforootdir/$node.info" || -z "$inforootdir/$node.info"){ + push @missnodes,$node; + } + } + + if(scalar(@missnodes) != 0){ + $request->{missnode} = \@missnodes; + &scan_adapters($request, $callback, $subreq); + } + } + + &get_info_from_loacal($request, $callback); + return; + +} + +sub handle_findadapter{ + + my $request = shift; + my $callback = shift; + my $hostname = $request->{hostname}->[0]; + + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: receiving a findadapter response from $hostname"); + + my $nicnum = scalar @{$request->{nic}}; + my $content = ""; + #print "-----------nicnum = $nicnum----------------\n"; + for (my $i = 1; $i <= $nicnum; $i++) { + $content .= "$i:"; + if(exists($request->{nic}->[$i-1]->{interface})){ + $content .= "hitn=".$request->{nic}->[$i-1]->{interface}->[0]."|"; + } + if(exists($request->{nic}->[$i-1]->{pcilocation})){ + $content .= "pci=".$request->{nic}->[$i-1]->{pcilocation}->[0]."|"; + } + if(exists($request->{nic}->[$i-1]->{mac})){ + $content .= "mac=".$request->{nic}->[$i-1]->{mac}->[0]."|"; + } + if(exists($request->{nic}->[$i-1]->{predictablename})){ + $content .= "prdn=".$request->{nic}->[$i-1]->{predictablename}->[0]."|"; + } + if(exists($request->{nic}->[$i-1]->{vendor})){ + $content .= "vnd=".$request->{nic}->[$i-1]->{vendor}->[0]; + } + if(exists($request->{nic}->[$i-1]->{model})){ + $content .= "mod=".$request->{nic}->[$i-1]->{model}->[0]; + } + $content .= "\n"; + } + $content =~ s/\n$//g; + xCAT::Utils->runcmd("echo '$content' > $inforootdir/$hostname.info"); + return; +} + +sub scan_adapters{ + my $request = shift; + my $callback = shift; + my $subreq = shift; + my @targetscannodes = @{$request->{missnode}}; + + if (scalar(@{$request->{node}}) == 0){ + return 1; + } + + my $tmptargetnodes = join(",", @targetscannodes); + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: issue new scaning for $tmptargetnodes"); + + my %autorsp; + $autorsp{data}->[0]="-->Starting scan for: $tmptargetnodes"; + $callback->(\%autorsp); + + if ( ! -d $inforootdir){ + xCAT::Utils->runcmd("mkdir -p $inforootdir"); + } + + my $node; + foreach $node (@targetscannodes){ + if ( -e "$inforootdir/$node.info"){ + xCAT::Utils->runcmd("mv $inforootdir/$node.info $inforootdir/$node.info.bak"); + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: move $inforootdir/$node.info to $inforootdir/$node.info.bak"); + } + } + + #do scan stuff + my $pid; + my $forkcount = 0; + my %pidrecord; + foreach $node (@targetscannodes){ + + $pid = xCAT::Utils->xfork(); + if (!defined($pid)){ + $autorsp{info}->[0]="failed to fork process to restart $node"; + $callback->(\%autorsp); + deletenode($request->{missnode}, "$node"); + last; + }elsif ($pid == 0){ + # Child process + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: fork new process $$ to start scaning $node"); + + my $outref = xCAT::Utils->runxcmd( + { + command => ['nodeset'], + node => ["$node"], + arg => ['runcmd=getadapter'], + }, + ,$subreq, 0, 1); + if($::RUNCMD_RC != 0){ + my $tmp = join(" ", @$outref); + $autorsp{data}->[0]="$tmp"; + $callback->(\%autorsp); + exit(1); + } + + my $tab = xCAT::Table->new("nodetype"); + my $nthash = $tab->getNodeAttribs(["$node"], ['arch']); + $tab->close(); + + if ($nthash->{arch} ne "ppc64"){ + $outref = xCAT::Utils->runxcmd( + { + command => ["rsetboot"], + node => ["$node"], + arg => ['net'], + }, + ,$subreq, 0, 1); + if($::RUNCMD_RC != 0){ + my $tmp = join(" ", @$outref); + $autorsp{data}->[0]="$tmp"; + $callback->(\%autorsp); + exit(1); + } + + $outref = xCAT::Utils->runxcmd( + { + command => ['rpower'], + node => ["$node"], + arg => ['reset'], + }, + ,$subreq, 0, 1); + if($::RUNCMD_RC != 0){ + my $tmp = join(" ", @$outref); + $autorsp{data}->[0]="$tmp"; + $callback->(\%autorsp); + exit(1); + } + }else{ + $outref = xCAT::Utils->runxcmd( + { + command => ["rnetboot"], + node => ["$node"], + }, + ,$subreq, 0, 1); + if($::RUNCMD_RC != 0){ + my $tmp = join(" ", @$outref); + $autorsp{data}->[0]="$tmp"; + $callback->(\%autorsp); + exit(1); + } + } + # Exit process + exit(0); + } + # Parent process + $forkcount++; + $pidrecord{$node} = $pid; + } + + # Wait for all processes to end + if($forkcount == 0){ + return 1; + }else{ + my $cpid; + while (($cpid=waitpid(-1,WNOHANG)) > 0) { + my $cpr=$?; + while(my($k,$v) = each %pidrecord){ + if($v == $cpid){ + if($cpr>0){ + deletenode($request->{missnode}, "$k"); + } + } + } + } + } + return 0; +} + +sub get_info_from_loacal{ + my $request = shift; + my $callback = shift; + my $retry = 60; + my $rsp = {}; + + push @{$rsp->{data}}, "\nThe whole scan result:"; + + if (scalar(@{$request->{node}}) == 0){ + $callback->({ + error=>[qq{Please indicate the nodes which are needed to scan}], + errorcode=>[1]}); + return 1; + } + + if (exists($request->{missnode}) && (scalar(@{$request->{missnode}}) > 0)){ + my $nodenum = scalar @{$request->{missnode}}; + my $backnum = 0; + while($retry && $backnum != $nodenum){ + xCAT::Utils->runcmd("sleep 10"); + $retry--; + $backnum = 0; + foreach $backnode (@{$request->{missnode}}){ + if( -e "$inforootdir/$backnode.info" ){ + $backnum++; + deletenode($request->{missnode}, "$backnode"); + } + } + } + } + + if($retry == 0){ + my $tmpnode = join(",", @{$request->{missnode}}); + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: waiting scan result time out"); + push @{$rsp->{data}}, "waiting scan result for $tmpnode time out"; + } + + my $node; + foreach $node (@{$request->{node}}){ + push @{$rsp->{data}}, "--------------------------------------"; + if ( ! -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ + + #scan failed, but without old file + push @{$rsp->{data}}, "[$node] Scan failed and without old data. there isn't data to show"; + + }elsif( ! -e "$inforootdir/$node.info" && -e "$inforootdir/$node.info.bak" ){ + + #scan failed, using old file + xCAT::Utils->runcmd("mv $inforootdir/$node.info.bak $inforootdir/$node.info"); + push @{$rsp->{data}}, "[$node] Scan failed but old data exist, using the old data:"; + if( -z "$inforootdir/$node.info"){ + push @{$rsp->{data}}, "[$node] the old file is empty, nothing to show"; + }else{ + if (open($myfile, "$inforootdir/$node.info")) { + while ($line = <$myfile>) { + push @{$rsp->{data}}, "$node:$line"; + } + close($myfile); + }else{ + push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info "; + } + } + + }elsif( -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ + + push @{$rsp->{data}}, "[$node] with no need for scan due to old data exist, using the old data:"; + if( -z "$inforootdir/$node.info"){ + push @{$rsp->{data}}, "[$node] the old file is empty, nothing to show"; + }else{ + if (open($myfile, "$inforootdir/$node.info")) { + while ($line = <$myfile>) { + push @{$rsp->{data}}, "$node:$line"; + } + close($myfile); + }else{ + push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info"; + } + } + }else{ + xCAT::Utils->runcmd("rm -f $inforootdir/$node.info.bak"); + push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; + #scan successfully, using new file + if (open($myfile, "$inforootdir/$node.info")) { + while ($line = <$myfile>) { + push @{$rsp->{data}}, "$node:$line"; + } + close($myfile); + }else{ + push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info"; + } + } + } + $callback->($rsp); + + return; +} + +sub deletenode{ + my $arrref = shift; + my $targetnode = shift; + my $arrlong = scalar @$arrref; + my $targetindex=0; + + if( "$targetnode" ne "all" ){ + for (my $i = 0; $i < $arrlong; $i++){ + if ("$arrref->[$i]" eq "$targetnode"){ + $targetindex = $i; + last; + } + } + for (my $i = $targetindex; $i < $arrlong-1; $i++){ + $arrref->[$i] = $arrref->[$i+1] ; + } + pop @$arrref; + }else{ + for (my $i = 0; $i < $arrlong; $i++){ + pop @$arrref; + } + } +} + +1; From d2760b6e7503c84ccdd6ae7abe4602a4d3d3ed5e Mon Sep 17 00:00:00 2001 From: huweihua Date: Sun, 22 Nov 2015 03:41:42 -0500 Subject: [PATCH 03/19] used for support getadapters command --- xCAT-client/pods/man1/getadapters.1.pod | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 xCAT-client/pods/man1/getadapters.1.pod diff --git a/xCAT-client/pods/man1/getadapters.1.pod b/xCAT-client/pods/man1/getadapters.1.pod new file mode 100644 index 000000000..1ab4317f1 --- /dev/null +++ b/xCAT-client/pods/man1/getadapters.1.pod @@ -0,0 +1,85 @@ +=head1 NAME + +B - Obtain all network adapters's predictable name and some other information before provision or network configuration. + +=head1 SYNOPSIS + +B I [B<-f>] + +B [B<-h>|B<--help>|B<-v>|B<--version>|B<-V>] + +=head1 DESCRIPTION + +Traditionally, network interfaces in Linux are enumerated as eth[0123…], but these names do not necessarily correspond to actual labels on the chassis. B help customer to get predictable network device name and some other network adapter information before provision or network configuration. + +B use genesis to collect network adapters information, so that mean it need to restart the target node. + +B follows below scheme: + +If the target node is scaned for the first time, B will trigger genesis to collect information then save the information at local. +If the target node has ever been scaned, i.e. this node has network device information in local, B use the local information first. +If user doesn't want to use local information, can use B<-f> option to force to trigger new round scan process. +if part nodes of I don't have network device information in local and the rest have, B only trigger real scan process for these nodes which don't have local information, the nodes have network device information in local, B still use the local information first. + +B tries to collect more information for the target network device, but doesn't guarantee collect same much information for every network device. + +Below are the possible information can be collect up to now: +B: the consistent name which can be used by confignic directly in operating system which follow the same naming scheme with rhels7 +B: the pci location +B: the MAC address +B: All the names which satisfy predictable network device naming scheme. I<(if xcat enhance confignic command later, user can use these names to configure their network adapter, even customize their name)> +B: the vender of network device +B: the modle of network device + +=head1 OPTIONS + +B<-h> + +Display usage message. + +B<-v> + +Command Version. + +B<-V> + +Display verbose message. + +B<-f> + +Force to trigger new round scan. ignore the data collected before. + + +=head1 EXAMPLES + +1. To collect node[1-3]'s network device information, enter: + + getadapters node[1-2] + +Output is similar to: + +-->Starting scan for: node1,node2 +The whole scan result: +-------------------------------------- +[node1] with no need for scan due to old data exist, using the old data: +node1:1:mac=98be9459ea24|pci=/0003:03:00.0|prdn=enx98be9459ea24|vnd=Broadcom Corporation +node1:2:mac=98be9459ea25|pci=/0003:03:00.1|prdn=enx98be9459ea25|vnd=Broadcom Corporation +-------------------------------------- +[node2] scan successfully, below are the latest data +node2:1:mac=98be9459ea34|pci=/0003:03:00.0|prdn=enx98be9459ea34|vnd=Broadcom Corporation +node2:2:mac=98be9459ea35|pci=/0003:03:00.1|prdn=enx98be9459ea35|vnd=Broadcom Corporation + +Every node gets a separate section to display its all network adapters information, every network adapter owns single line which start as node name and followed by index and other information. + + +2. Force to trigger new round scan + + getadatpers node -f + + + +=head1 SEE ALSO + +L + + From 939773081c01321152624d200eea10ed9ead804b Mon Sep 17 00:00:00 2001 From: huweihua Date: Sun, 22 Nov 2015 03:45:36 -0500 Subject: [PATCH 04/19] used for support getadapters command --- docs/source/advanced/networks/getadapters.rst | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 docs/source/advanced/networks/getadapters.rst diff --git a/docs/source/advanced/networks/getadapters.rst b/docs/source/advanced/networks/getadapters.rst new file mode 100755 index 000000000..8f81fc65f --- /dev/null +++ b/docs/source/advanced/networks/getadapters.rst @@ -0,0 +1,53 @@ +Predict network adapter name before deployment +============================================== + + + +Traditionally, network interfaces in Linux are enumerated as eth[0123…], but these names do not necessarily correspond to actual labels on the chassis. customer need a methods to get consistent and predictable network device name before provision or network configuration. xCAT provide a tool ``getadapters`` to help customer to resolve this problem. + + +**[Note]** : This feature needs to restart your target sever which you want to obtain network adapter from. + +How to use get adapters +----------------------- + + +Using below command to obtain the network adapters information :: + + getadapters + +Then will get output like below :: + + + The whole scan result: + -------------------------------------- + node1:1:hitn=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|prdn=enP3p3s0f0,enx98be9459ea24|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:2:hitn=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|prdn=enP3p3s0f1,enx98be9459ea25|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:3:hitn=enP3p3s0f2|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.2|mac=98be9459ea26|prdn=enP3p3s0f2,enx98be9459ea26|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:4:hitn=enP3p3s0f3|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.3|mac=98be9459ea27|prdn=enP3p3s0f3,enx98be9459ea27|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:5:pci=0001:01:00.0|mod=Mellanox Technologies MT27600 [Connect-IB] + -------------------------------------- + node2:1:hitn=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|prdn=enP3p3s0f0,enx98be9459ea24|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node2:2:hitn=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|prdn=enP3p3s0f1,enx98be9459ea25|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + + +Every node gets a separate section to display its all network adapters information, every network adapter owns single line which start as node name and followed by index and other information. + +xCAT try its best to collect more information for each network adapter, but can’t guarantee collect same much information for every one. If a network adapter can be derived by xcat genesis, this adapter will have a predictable name, if it can’t be, it only has the information xcat can obtain. + +below are the possible information: + +* **hitn**: the consistent name which can be used in ``confignic`` derectly in operating system which follow the same naming scheme with rhels7. (``confignic`` doesn’t need to do more work) + +* **pci**: the pci location + +* **mac**: the MAC address + +* **prdn**: All the names which satisfy predictable network device naming scheme, if customer needs to customize their network adapter name, they can choose one of them. (``confignic`` needs to do more work to support this. if customer want to use their own name, xcat should offer a interface to get customer’s input and change this column) + +* **vnd**: the vender of network device + +* **mod**: the modle of network device + + + From cb01dac7aed02d01bd5275a0200bf5d305754fe3 Mon Sep 17 00:00:00 2001 From: huweihua Date: Mon, 23 Nov 2015 23:18:07 -0500 Subject: [PATCH 05/19] modify depending on the comment --- xCAT-genesis-scripts/bin/getadapter | 41 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 21 deletions(-) mode change 100644 => 100755 xCAT-genesis-scripts/bin/getadapter diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter old mode 100644 new mode 100755 index 5677a8919..8d2fe5af0 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -8,13 +8,11 @@ export XCATPORT ADAPTERFILE="/tmp/adapterinfo" SCANNICLOG="/tmp/adapterscan.log" -if [ -f "$SCANNICLOG" ]; then - rm -f "$SCANNICLOG" 2>&1 >/dev/null -fi +rm -f "$SCANNICLOG" >/dev/null 2>&1 if [ -f "$ADAPTERFILE" ]; then echo "rm -f $ADAPTERFILE" > "$SCANNICLOG" - rm -f "$ADAPTERFILE" 2>&1 >> "$SCANNICLOG" + rm -f "$ADAPTERFILE" >> "$SCANNICLOG" 2>&1 fi @@ -24,41 +22,42 @@ echo "cli" >> "$ADAPTERFILE" echo "$HOSTNAME" >> "$ADAPTERFILE" #scan adapters have recognized by operating system -for nic in `ls /sys/class/net/`; do +for n in /sys/class/net/*; do + nic=${n##/sys/class/net/} if [ "$nic" == "lo" ]; then continue else echo '' >> "$ADAPTERFILE" tmp=`udevadm info /sys/class/net/"$nic" | grep " INTERFACE" | awk -F '=' '{print $2}'` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi tmp=`udevadm info /sys/class/net/"$nic" | grep ID_NET_NAME | awk -F '=' '{print $2}'|sort -u| tr -s "\n" "," | sed "s/,$//g"` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi tmp=`udevadm info /sys/class/net/"$nic" | grep DEVPATH | awk -F 'devices' '{print $2}'` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "${tmp%/net*}" >> "$ADAPTERFILE" fi tmp=`udevadm info /sys/class/net/"$nic" | grep ID_NET_NAME_MAC | awk -F '=' '{print $2}'` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "${tmp##*enx}" >> "$ADAPTERFILE" - fi + fi tmp=`udevadm info /sys/class/net/"$nic" | grep ID_VENDOR_FROM_DATABASE | awk -F '=' '{print $2}' | tr -s "\n" "," | sed "s/,$//g"` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" - fi + fi tmp=`udevadm info /sys/class/net/"$nic" | grep ID_MODEL_FROM_DATABASE | awk -F '=' '{print $2}'` - if [ ! -z "$tmp" ]; then + if [ -n "$tmp" ]; then echo "$tmp" >> "$ADAPTERFILE" fi echo '' >> "$ADAPTERFILE" fi done -for pci in `lspci |grep Ethernet |awk '{print $1}' `; do - if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then +for pci in `lspci |awk '/Ethernet/ {print $1}' `; do + if ! grep -q "$pci" "$ADAPTERFILE" 2 >/dev/null; then tmp=`lspci |grep "$pci"` echo '' >> "$ADAPTERFILE" echo "$pci" >> "$ADAPTERFILE" @@ -67,8 +66,8 @@ for pci in `lspci |grep Ethernet |awk '{print $1}' `; do fi done -for pci in `lspci |grep Network |awk '{print $1}' `; do - if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then +for pci in `lspci |awk '/Network/ {print $1}' `; do + if ! grep -q "$pci" "$ADAPTERFILE" 2 >/dev/null; then tmp=`lspci |grep "$pci"` echo '' >> "$ADAPTERFILE" echo "$pci" >> "$ADAPTERFILE" @@ -77,8 +76,8 @@ for pci in `lspci |grep Network |awk '{print $1}' `; do fi done -for pci in `lspci |grep Mellanox |awk '{print $1}' `; do - if ! cat "$ADAPTERFILE" |grep "$pci" >/dev/null; then +for pci in `lspci |awk '/Mellanox/ {print $1}' `; do + if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then tmp=`lspci |grep "$pci"` echo '' >> "$ADAPTERFILE" echo "$pci" >> "$ADAPTERFILE" @@ -89,7 +88,7 @@ done echo "" >> "$ADAPTERFILE" -#cat "$ADAPTERFILE" +cat "$ADAPTERFILE" if [ ! -z "$XCATMASTER" ]; then if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available @@ -97,7 +96,7 @@ if [ ! -z "$XCATMASTER" ]; then cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" else echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" fi else for dhcps in `cat /var/lib/dhclient/dhclient.leases |grep dhcp-server|awk '{print $3}'|uniq|sed "s/;$//g"`; do From a381f2ee06a2dbb4a037f495e9b08d5477ef3264 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 01:44:59 -0500 Subject: [PATCH 06/19] modify depending on gongjie's new comment --- xCAT-genesis-scripts/bin/getadapter | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter index 8d2fe5af0..ec2cdd6f9 100755 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -57,7 +57,7 @@ for n in /sys/class/net/*; do done for pci in `lspci |awk '/Ethernet/ {print $1}' `; do - if ! grep -q "$pci" "$ADAPTERFILE" 2 >/dev/null; then + if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then tmp=`lspci |grep "$pci"` echo '' >> "$ADAPTERFILE" echo "$pci" >> "$ADAPTERFILE" @@ -67,7 +67,7 @@ for pci in `lspci |awk '/Ethernet/ {print $1}' `; do done for pci in `lspci |awk '/Network/ {print $1}' `; do - if ! grep -q "$pci" "$ADAPTERFILE" 2 >/dev/null; then + if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then tmp=`lspci |grep "$pci"` echo '' >> "$ADAPTERFILE" echo "$pci" >> "$ADAPTERFILE" @@ -90,23 +90,22 @@ echo "" >> "$ADAPTERFILE" cat "$ADAPTERFILE" -if [ ! -z "$XCATMASTER" ]; then +if [ -n "$XCATMASTER" ]; then if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT >>"$SCANNICLOG" 2>&1 else echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT 2>&1 >>"$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT >>"$SCANNICLOG" 2>&1 fi else - for dhcps in `cat /var/lib/dhclient/dhclient.leases |grep dhcp-server|awk '{print $3}'|uniq|sed "s/;$//g"`; do + dhcps=`awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1` + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT 2>&1 >>"$SCANNICLOG" - else - echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT 2>&1 >>"$SCANNICLOG" - fi - done + cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + else + echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + fi fi From 0c74d0683512b73e16987dd47193fd4208c40ed4 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 01:47:24 -0500 Subject: [PATCH 07/19] remove debug info --- xCAT-genesis-scripts/bin/getadapter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter index ec2cdd6f9..390d68c57 100755 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -88,7 +88,7 @@ done echo "" >> "$ADAPTERFILE" -cat "$ADAPTERFILE" +#cat "$ADAPTERFILE" if [ -n "$XCATMASTER" ]; then if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available From b30037e48505349e65803e6d31e02576f14186de Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 03:14:35 -0500 Subject: [PATCH 08/19] modify depending on comments --- xCAT-server/lib/xcat/plugins/getadapter.pm | 123 +++++++++++---------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index b01c4a42b..a65c80d44 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -23,6 +23,7 @@ use xCAT::Utils; use xCAT::MsgUtils; use Data::Dumper; use Getopt::Long; +use File::Path; use IO::Select; use Term::ANSIColor; use Time::Local; @@ -66,7 +67,7 @@ sub process_request my $callback = shift; my $subreq = shift; my $command = $request->{command}->[0]; - + if ($command eq "getadapters"){ &handle_getadapters($request, $callback, $subreq); } @@ -74,7 +75,7 @@ sub process_request if ($command eq "findadapter"){ &handle_findadapter($request, $callback); } - + return; } @@ -83,7 +84,7 @@ sub handle_getadapters{ my $callback = shift; my $subreq = shift; my $command = $request->{command}->[0]; - + my @args=(); my $HELP; my $VERSION; @@ -95,11 +96,11 @@ sub handle_getadapters{ } @ARGV = @args; Getopt::Long::Configure("bundling"); - Getopt::Long::Configure("no_pass_through"); + Getopt::Long::Configure("no_pass_through"); if (!GetOptions("h|help" => \$HELP, - "v|version" => \$VERSION, - "f" => \$FORCE, - "V" => \$VERBOSE + "v|version" => \$VERSION, + "f" => \$FORCE, + "V" => \$VERBOSE ) ) { if($usage{$command}) { my $rsp = {}; @@ -117,8 +118,8 @@ sub handle_getadapters{ $callback->(\%rsp); } return; - } - + } + if ($VERSION) { my $ver = xCAT::Utils->Version(); my %rsp; @@ -126,7 +127,7 @@ sub handle_getadapters{ $callback->(\%rsp); return; } - + my $tmpnodes = join(",", @{$request->{node}}); my $tmpargs = join(",", @args); xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: handling command <$command $tmpnodes $tmpargs>"); @@ -134,7 +135,7 @@ sub handle_getadapters{ if($FORCE || ! -d $inforootdir) { my @tmpnodes = @{$request->{node}}; $request->{missnode} = \@tmpnodes; - &scan_adapters($request, $callback, $subreq); + &scan_adapters($request, $callback, $subreq); }else{ my @nodes = @{$request->{node}}; my $node; @@ -144,7 +145,7 @@ sub handle_getadapters{ push @missnodes,$node; } } - + if(scalar(@missnodes) != 0){ $request->{missnode} = \@missnodes; &scan_adapters($request, $callback, $subreq); @@ -161,16 +162,16 @@ sub handle_findadapter{ my $request = shift; my $callback = shift; my $hostname = $request->{hostname}->[0]; - - xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: receiving a findadapter response from $hostname"); + + xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: receiving a findadapter response from $hostname"); my $nicnum = scalar @{$request->{nic}}; my $content = ""; - #print "-----------nicnum = $nicnum----------------\n"; + #print "-----------nicnum = $nicnum----------------\n"; for (my $i = 1; $i <= $nicnum; $i++) { $content .= "$i:"; if(exists($request->{nic}->[$i-1]->{interface})){ - $content .= "hitn=".$request->{nic}->[$i-1]->{interface}->[0]."|"; + $content .= "hitname=".$request->{nic}->[$i-1]->{interface}->[0]."|"; } if(exists($request->{nic}->[$i-1]->{pcilocation})){ $content .= "pci=".$request->{nic}->[$i-1]->{pcilocation}->[0]."|"; @@ -179,13 +180,13 @@ sub handle_findadapter{ $content .= "mac=".$request->{nic}->[$i-1]->{mac}->[0]."|"; } if(exists($request->{nic}->[$i-1]->{predictablename})){ - $content .= "prdn=".$request->{nic}->[$i-1]->{predictablename}->[0]."|"; + $content .= "candidatename=".$request->{nic}->[$i-1]->{predictablename}->[0]."|"; } if(exists($request->{nic}->[$i-1]->{vendor})){ - $content .= "vnd=".$request->{nic}->[$i-1]->{vendor}->[0]; + $content .= "vendor=".$request->{nic}->[$i-1]->{vendor}->[0]."|"; } if(exists($request->{nic}->[$i-1]->{model})){ - $content .= "mod=".$request->{nic}->[$i-1]->{model}->[0]; + $content .= "modle=".$request->{nic}->[$i-1]->{model}->[0]; } $content .= "\n"; } @@ -203,18 +204,18 @@ sub scan_adapters{ if (scalar(@{$request->{node}}) == 0){ return 1; } - + my $tmptargetnodes = join(",", @targetscannodes); xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: issue new scaning for $tmptargetnodes"); - + my %autorsp; $autorsp{data}->[0]="-->Starting scan for: $tmptargetnodes"; - $callback->(\%autorsp); - + $callback->(\%autorsp); + if ( ! -d $inforootdir){ - xCAT::Utils->runcmd("mkdir -p $inforootdir"); + mkpath("$inforootdir"); } - + my $node; foreach $node (@targetscannodes){ if ( -e "$inforootdir/$node.info"){ @@ -228,7 +229,7 @@ sub scan_adapters{ my $forkcount = 0; my %pidrecord; foreach $node (@targetscannodes){ - + $pid = xCAT::Utils->xfork(); if (!defined($pid)){ $autorsp{info}->[0]="failed to fork process to restart $node"; @@ -250,14 +251,14 @@ sub scan_adapters{ my $tmp = join(" ", @$outref); $autorsp{data}->[0]="$tmp"; $callback->(\%autorsp); - exit(1); + exit(1); } - - my $tab = xCAT::Table->new("nodetype"); - my $nthash = $tab->getNodeAttribs(["$node"], ['arch']); + + my $tab = xCAT::Table->new("nodehm"); + my $hmhash = $tab->getNodeAttribs(["$node"], ['mgt']); $tab->close(); - - if ($nthash->{arch} ne "ppc64"){ + + if ($hmhash->{mgt} eq "ipmi"){ $outref = xCAT::Utils->runxcmd( { command => ["rsetboot"], @@ -269,9 +270,9 @@ sub scan_adapters{ my $tmp = join(" ", @$outref); $autorsp{data}->[0]="$tmp"; $callback->(\%autorsp); - exit(1); + exit(1); } - + $outref = xCAT::Utils->runxcmd( { command => ['rpower'], @@ -283,7 +284,7 @@ sub scan_adapters{ my $tmp = join(" ", @$outref); $autorsp{data}->[0]="$tmp"; $callback->(\%autorsp); - exit(1); + exit(1); } }else{ $outref = xCAT::Utils->runxcmd( @@ -296,9 +297,9 @@ sub scan_adapters{ my $tmp = join(" ", @$outref); $autorsp{data}->[0]="$tmp"; $callback->(\%autorsp); - exit(1); - } - } + exit(1); + } + } # Exit process exit(0); } @@ -331,7 +332,7 @@ sub get_info_from_loacal{ my $callback = shift; my $retry = 60; my $rsp = {}; - + push @{$rsp->{data}}, "\nThe whole scan result:"; if (scalar(@{$request->{node}}) == 0){ @@ -339,21 +340,21 @@ sub get_info_from_loacal{ error=>[qq{Please indicate the nodes which are needed to scan}], errorcode=>[1]}); return 1; - } + } if (exists($request->{missnode}) && (scalar(@{$request->{missnode}}) > 0)){ my $nodenum = scalar @{$request->{missnode}}; my $backnum = 0; while($retry && $backnum != $nodenum){ - xCAT::Utils->runcmd("sleep 10"); + sleep 10; $retry--; $backnum = 0; foreach $backnode (@{$request->{missnode}}){ if( -e "$inforootdir/$backnode.info" ){ $backnum++; deletenode($request->{missnode}, "$backnode"); - } - } + } + } } } @@ -361,18 +362,18 @@ sub get_info_from_loacal{ my $tmpnode = join(",", @{$request->{missnode}}); xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: waiting scan result time out"); push @{$rsp->{data}}, "waiting scan result for $tmpnode time out"; - } - + } + my $node; foreach $node (@{$request->{node}}){ push @{$rsp->{data}}, "--------------------------------------"; if ( ! -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ - + #scan failed, but without old file push @{$rsp->{data}}, "[$node] Scan failed and without old data. there isn't data to show"; }elsif( ! -e "$inforootdir/$node.info" && -e "$inforootdir/$node.info.bak" ){ - + #scan failed, using old file xCAT::Utils->runcmd("mv $inforootdir/$node.info.bak $inforootdir/$node.info"); push @{$rsp->{data}}, "[$node] Scan failed but old data exist, using the old data:"; @@ -388,9 +389,9 @@ sub get_info_from_loacal{ push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info "; } } - + }elsif( -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ - + push @{$rsp->{data}}, "[$node] with no need for scan due to old data exist, using the old data:"; if( -z "$inforootdir/$node.info"){ push @{$rsp->{data}}, "[$node] the old file is empty, nothing to show"; @@ -405,7 +406,7 @@ sub get_info_from_loacal{ } } }else{ - xCAT::Utils->runcmd("rm -f $inforootdir/$node.info.bak"); + xCAT::Utils->runcmd("rm -f $inforootdir/$node.info.bak"); push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; #scan successfully, using new file if (open($myfile, "$inforootdir/$node.info")) { @@ -415,34 +416,34 @@ sub get_info_from_loacal{ close($myfile); }else{ push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info"; - } - } - } - $callback->($rsp); - + } + } + } + $callback->($rsp); + return; } sub deletenode{ my $arrref = shift; my $targetnode = shift; - my $arrlong = scalar @$arrref; + my $arrcount = scalar @$arrref; my $targetindex=0; - + if( "$targetnode" ne "all" ){ - for (my $i = 0; $i < $arrlong; $i++){ + for (my $i = 0; $i < $arrcount; $i++){ if ("$arrref->[$i]" eq "$targetnode"){ $targetindex = $i; last; } } - for (my $i = $targetindex; $i < $arrlong-1; $i++){ + for (my $i = $targetindex; $i < $arrcount-1; $i++){ $arrref->[$i] = $arrref->[$i+1] ; } pop @$arrref; }else{ - for (my $i = 0; $i < $arrlong; $i++){ - pop @$arrref; + for (my $i = 0; $i < $arrcount; $i++){ + pop @$arrref; } } } From acd85703241a28f395a0641d2a1ab3e15c25be07 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 03:20:10 -0500 Subject: [PATCH 09/19] modify depending on gongjie's comment --- xCAT-genesis-scripts/bin/getadapter | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter index 390d68c57..a19d1138d 100755 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -100,12 +100,14 @@ if [ -n "$XCATMASTER" ]; then fi else dhcps=`awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1` - if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 - else - echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + if [ -n "$dhcps" ]; then + if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available + echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + else + echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" + cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + fi fi fi From 9fae29ec7af824fe233b8b67b0b65609de56e5b9 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 03:30:53 -0500 Subject: [PATCH 10/19] modify in accordance with code changing --- docs/source/advanced/networks/getadapters.rst | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/advanced/networks/getadapters.rst b/docs/source/advanced/networks/getadapters.rst index 8f81fc65f..16cb6a06b 100755 --- a/docs/source/advanced/networks/getadapters.rst +++ b/docs/source/advanced/networks/getadapters.rst @@ -21,14 +21,14 @@ Then will get output like below :: The whole scan result: -------------------------------------- - node1:1:hitn=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|prdn=enP3p3s0f0,enx98be9459ea24|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet - node1:2:hitn=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|prdn=enP3p3s0f1,enx98be9459ea25|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet - node1:3:hitn=enP3p3s0f2|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.2|mac=98be9459ea26|prdn=enP3p3s0f2,enx98be9459ea26|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet - node1:4:hitn=enP3p3s0f3|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.3|mac=98be9459ea27|prdn=enP3p3s0f3,enx98be9459ea27|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet - node1:5:pci=0001:01:00.0|mod=Mellanox Technologies MT27600 [Connect-IB] + node1:1:hitname=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|candidatename=enP3p3s0f0,enx98be9459ea24|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:2:hitname=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|candidatename=enP3p3s0f1,enx98be9459ea25|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:3:hitname=enP3p3s0f2|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.2|mac=98be9459ea26|candidatename=enP3p3s0f2,enx98be9459ea26|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:4:hitname=enP3p3s0f3|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.3|mac=98be9459ea27|candidatename=enP3p3s0f3,enx98be9459ea27|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node1:5:pci=0001:01:00.0|modle=Mellanox Technologies MT27600 [Connect-IB] -------------------------------------- - node2:1:hitn=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|prdn=enP3p3s0f0,enx98be9459ea24|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet - node2:2:hitn=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|prdn=enP3p3s0f1,enx98be9459ea25|vnd=Broadcom Corporationmod=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node2:1:hitname=enP3p3s0f0|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.0|mac=98be9459ea24|candidatename=enP3p3s0f0,enx98be9459ea24|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet + node2:2:hitname=enP3p3s0f1|pci=/pci0003:00/0003:00:00.0/0003:01:00.0/0003:02:01.0/0003:03:00.1|mac=98be9459ea25|candidatename=enP3p3s0f1,enx98be9459ea25|vendor=Broadcom Corporation|modle=NetXtreme II BCM57800 1/10 Gigabit Ethernet Every node gets a separate section to display its all network adapters information, every network adapter owns single line which start as node name and followed by index and other information. @@ -37,17 +37,17 @@ xCAT try its best to collect more information for each network adapter, but can below are the possible information: -* **hitn**: the consistent name which can be used in ``confignic`` derectly in operating system which follow the same naming scheme with rhels7. (``confignic`` doesn’t need to do more work) +* **hitname**: the consistent name which can be used in ``confignic`` derectly in operating system which follow the same naming scheme with rhels7. (``confignic`` doesn’t need to do more work) * **pci**: the pci location * **mac**: the MAC address -* **prdn**: All the names which satisfy predictable network device naming scheme, if customer needs to customize their network adapter name, they can choose one of them. (``confignic`` needs to do more work to support this. if customer want to use their own name, xcat should offer a interface to get customer’s input and change this column) +* **candidatename**: All the names which satisfy predictable network device naming scheme, if customer needs to customize their network adapter name, they can choose one of them. (``confignic`` needs to do more work to support this. if customer want to use their own name, xcat should offer a interface to get customer’s input and change this column) -* **vnd**: the vender of network device +* **vendor**: the vender of network device -* **mod**: the modle of network device +* **modle**: the modle of network device From 33aea210cfda4a402bd745d91b64cad6d0cd8ef9 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 03:38:19 -0500 Subject: [PATCH 11/19] modify in accordance with code changing --- xCAT-client/pods/man1/getadapters.1.pod | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xCAT-client/pods/man1/getadapters.1.pod b/xCAT-client/pods/man1/getadapters.1.pod index 1ab4317f1..13f352a59 100644 --- a/xCAT-client/pods/man1/getadapters.1.pod +++ b/xCAT-client/pods/man1/getadapters.1.pod @@ -24,12 +24,12 @@ if part nodes of I don't have network device information in local and B tries to collect more information for the target network device, but doesn't guarantee collect same much information for every network device. Below are the possible information can be collect up to now: -B: the consistent name which can be used by confignic directly in operating system which follow the same naming scheme with rhels7 +B: the consistent name which can be used by confignic directly in operating system which follow the same naming scheme with rhels7 B: the pci location B: the MAC address -B: All the names which satisfy predictable network device naming scheme. I<(if xcat enhance confignic command later, user can use these names to configure their network adapter, even customize their name)> -B: the vender of network device -B: the modle of network device +B: All the names which satisfy predictable network device naming scheme. I<(if xcat enhance confignic command later, user can use these names to configure their network adapter, even customize their name)> +B: the vender of network device +B: the modle of network device =head1 OPTIONS @@ -62,12 +62,12 @@ Output is similar to: The whole scan result: -------------------------------------- [node1] with no need for scan due to old data exist, using the old data: -node1:1:mac=98be9459ea24|pci=/0003:03:00.0|prdn=enx98be9459ea24|vnd=Broadcom Corporation -node1:2:mac=98be9459ea25|pci=/0003:03:00.1|prdn=enx98be9459ea25|vnd=Broadcom Corporation +node1:1:mac=98be9459ea24|pci=/0003:03:00.0|candidatename=enx98be9459ea24|vender=Broadcom Corporation +node1:2:mac=98be9459ea25|pci=/0003:03:00.1|candidatename=enx98be9459ea25|vender=Broadcom Corporation -------------------------------------- [node2] scan successfully, below are the latest data -node2:1:mac=98be9459ea34|pci=/0003:03:00.0|prdn=enx98be9459ea34|vnd=Broadcom Corporation -node2:2:mac=98be9459ea35|pci=/0003:03:00.1|prdn=enx98be9459ea35|vnd=Broadcom Corporation +node2:1:mac=98be9459ea34|pci=/0003:03:00.0|candidatename=enx98be9459ea34|vender=Broadcom Corporation +node2:2:mac=98be9459ea35|pci=/0003:03:00.1|candidatename=enx98be9459ea35|vender=Broadcom Corporation Every node gets a separate section to display its all network adapters information, every network adapter owns single line which start as node name and followed by index and other information. From bf18e2ab5e463ef5f6bd9321882f964bf24f0326 Mon Sep 17 00:00:00 2001 From: huweihua Date: Tue, 24 Nov 2015 03:52:23 -0500 Subject: [PATCH 12/19] modiy typo --- xCAT-client/pods/man1/getadapters.1.pod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-client/pods/man1/getadapters.1.pod b/xCAT-client/pods/man1/getadapters.1.pod index 13f352a59..99b4ad479 100644 --- a/xCAT-client/pods/man1/getadapters.1.pod +++ b/xCAT-client/pods/man1/getadapters.1.pod @@ -29,7 +29,7 @@ B: the pci location B: the MAC address B: All the names which satisfy predictable network device naming scheme. I<(if xcat enhance confignic command later, user can use these names to configure their network adapter, even customize their name)> B: the vender of network device -B: the modle of network device +B: the model of network device =head1 OPTIONS From 1f19b92529fba85871c72dbdaeefd1fabc7d3185 Mon Sep 17 00:00:00 2001 From: huweihua Date: Wed, 25 Nov 2015 05:19:33 -0500 Subject: [PATCH 13/19] modify depending on gongjie and chenglong 's comment --- xCAT-server/lib/xcat/plugins/getadapter.pm | 163 ++++++++++----------- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index a65c80d44..2456a699a 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -68,6 +68,8 @@ sub process_request my $subreq = shift; my $command = $request->{command}->[0]; + $SIG{CHLD}='DEFAULT'; + if ($command eq "getadapters"){ &handle_getadapters($request, $callback, $subreq); } @@ -152,7 +154,7 @@ sub handle_getadapters{ } } - &get_info_from_loacal($request, $callback); + &get_info_from_local($request, $callback); return; } @@ -168,30 +170,38 @@ sub handle_findadapter{ my $nicnum = scalar @{$request->{nic}}; my $content = ""; #print "-----------nicnum = $nicnum----------------\n"; - for (my $i = 1; $i <= $nicnum; $i++) { + for (my $i = 0; $i < $nicnum; $i++) { $content .= "$i:"; - if(exists($request->{nic}->[$i-1]->{interface})){ - $content .= "hitname=".$request->{nic}->[$i-1]->{interface}->[0]."|"; + if(exists($request->{nic}->[$i]->{interface})){ + $content .= "hitname=".$request->{nic}->[$i]->{interface}->[0]."|"; } - if(exists($request->{nic}->[$i-1]->{pcilocation})){ - $content .= "pci=".$request->{nic}->[$i-1]->{pcilocation}->[0]."|"; + if(exists($request->{nic}->[$i]->{pcilocation})){ + $content .= "pci=".$request->{nic}->[$i]->{pcilocation}->[0]."|"; } - if(exists($request->{nic}->[$i-1]->{mac})){ - $content .= "mac=".$request->{nic}->[$i-1]->{mac}->[0]."|"; + if(exists($request->{nic}->[$i]->{mac})){ + $content .= "mac=".$request->{nic}->[$i]->{mac}->[0]."|"; } - if(exists($request->{nic}->[$i-1]->{predictablename})){ - $content .= "candidatename=".$request->{nic}->[$i-1]->{predictablename}->[0]."|"; + if(exists($request->{nic}->[$i]->{predictablename})){ + $content .= "candidatename=".$request->{nic}->[$i]->{predictablename}->[0]."|"; } - if(exists($request->{nic}->[$i-1]->{vendor})){ - $content .= "vendor=".$request->{nic}->[$i-1]->{vendor}->[0]."|"; + if(exists($request->{nic}->[$i]->{vendor})){ + $content .= "vendor=".$request->{nic}->[$i]->{vendor}->[0]."|"; } - if(exists($request->{nic}->[$i-1]->{model})){ - $content .= "modle=".$request->{nic}->[$i-1]->{model}->[0]; + if(exists($request->{nic}->[$i]->{model})){ + $content .= "modle=".$request->{nic}->[$i]->{model}->[0]; } $content .= "\n"; } - $content =~ s/\n$//g; - xCAT::Utils->runcmd("echo '$content' > $inforootdir/$hostname.info"); + $content =~ s/\n$//; + + my $fd; + if(!open($fd,">$inforootdir/$hostname.info")) { + xCAT::MsgUtils->trace($VERBOSE,"d","findadapter: can't open $inforootdir/$hostname.info to record adapter info"); + }else{ + print $fd, "$content"; + close($fd); + } + return; } @@ -219,7 +229,7 @@ sub scan_adapters{ my $node; foreach $node (@targetscannodes){ if ( -e "$inforootdir/$node.info"){ - xCAT::Utils->runcmd("mv $inforootdir/$node.info $inforootdir/$node.info.bak"); + rename("$inforootdir/$node.infoi", "$inforootdir/$node.info.bak"); xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: move $inforootdir/$node.info to $inforootdir/$node.info.bak"); } } @@ -305,29 +315,60 @@ sub scan_adapters{ } # Parent process $forkcount++; - $pidrecord{$node} = $pid; + $pidrecord{$pid} = $node; } # Wait for all processes to end if($forkcount == 0){ + deletenode($request->{missnode}, "all"); return 1; }else{ - my $cpid; - while (($cpid=waitpid(-1,WNOHANG)) > 0) { - my $cpr=$?; - while(my($k,$v) = each %pidrecord){ - if($v == $cpid){ - if($cpr>0){ - deletenode($request->{missnode}, "$k"); - } + while($forkcount){ + my $cpid; + while (($cpid=waitpid(-1,WNOHANG)) > 0) { + my $cpr=$?; + if($cpr>0){ + deletenode($request->{missnode}, "$pidreord{$cpid}"); + } + $forkcount--; + } + } + } + + check_scan_result($request, $callback); + return 0; +} + +sub check_scan_result{ + my $request = shift; + my $callback = shift; + my $retry =60; + my $rsp = {}; + my $nodenum = scalar @{$request->{missnode}}; + my $backnum = 0; + + if (exists($request->{missnode}) && (scalar(@{$request->{missnode}}) > 0)){ + while($retry && $backnum != $nodenum){ + sleep 10; + $retry--; + foreach $backnode (@{$request->{missnode}}){ + if( -e "$inforootdir/$backnode.info" ){ + $backnum++; + deletenode($request->{missnode}, "$backnode"); } } } } - return 0; + + if($retry == 0 && $backnum != $nodenum){ + my $tmpnode = join(",", @{$request->{missnode}}); + push @{$rsp->{data}}, "waiting scan result for $tmpnode time out"; + $callback->($rsp); + } } -sub get_info_from_loacal{ + +sub get_info_from_local{ my $request = shift; my $callback = shift; my $retry = 60; @@ -342,81 +383,35 @@ sub get_info_from_loacal{ return 1; } - if (exists($request->{missnode}) && (scalar(@{$request->{missnode}}) > 0)){ - my $nodenum = scalar @{$request->{missnode}}; - my $backnum = 0; - while($retry && $backnum != $nodenum){ - sleep 10; - $retry--; - $backnum = 0; - foreach $backnode (@{$request->{missnode}}){ - if( -e "$inforootdir/$backnode.info" ){ - $backnum++; - deletenode($request->{missnode}, "$backnode"); - } - } - } - } - - if($retry == 0){ - my $tmpnode = join(",", @{$request->{missnode}}); - xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: waiting scan result time out"); - push @{$rsp->{data}}, "waiting scan result for $tmpnode time out"; - } - my $node; foreach $node (@{$request->{node}}){ + my $readfile=1; push @{$rsp->{data}}, "--------------------------------------"; if ( ! -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ - - #scan failed, but without old file push @{$rsp->{data}}, "[$node] Scan failed and without old data. there isn't data to show"; - + $readfile=0; }elsif( ! -e "$inforootdir/$node.info" && -e "$inforootdir/$node.info.bak" ){ - - #scan failed, using old file - xCAT::Utils->runcmd("mv $inforootdir/$node.info.bak $inforootdir/$node.info"); + rename("$inforootdir/$node.info.bak","$inforootdir/$node.info"); push @{$rsp->{data}}, "[$node] Scan failed but old data exist, using the old data:"; - if( -z "$inforootdir/$node.info"){ - push @{$rsp->{data}}, "[$node] the old file is empty, nothing to show"; - }else{ - if (open($myfile, "$inforootdir/$node.info")) { - while ($line = <$myfile>) { - push @{$rsp->{data}}, "$node:$line"; - } - close($myfile); - }else{ - push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info "; - } - } - }elsif( -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ - push @{$rsp->{data}}, "[$node] with no need for scan due to old data exist, using the old data:"; + }else{ + unlink "$inforootdir/$node.info.bak"; + push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; + } + if($readfile){ if( -z "$inforootdir/$node.info"){ - push @{$rsp->{data}}, "[$node] the old file is empty, nothing to show"; + push @{$rsp->{data}}, "[$node] the file is empty, nothing to show"; }else{ if (open($myfile, "$inforootdir/$node.info")) { while ($line = <$myfile>) { push @{$rsp->{data}}, "$node:$line"; } - close($myfile); + close($myfile); }else{ push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info"; } } - }else{ - xCAT::Utils->runcmd("rm -f $inforootdir/$node.info.bak"); - push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; - #scan successfully, using new file - if (open($myfile, "$inforootdir/$node.info")) { - while ($line = <$myfile>) { - push @{$rsp->{data}}, "$node:$line"; - } - close($myfile); - }else{ - push @{$rsp->{data}}, "[$node] Can't open $inforootdir/$node.info"; - } } } $callback->($rsp); From 1aab9c622787c94a7cd43654500658a1101df500 Mon Sep 17 00:00:00 2001 From: huweihua Date: Wed, 25 Nov 2015 05:25:24 -0500 Subject: [PATCH 14/19] modify depending on gongjie's comment --- xCAT-genesis-scripts/bin/getadapter | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter index a19d1138d..9f1eb002a 100755 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -93,20 +93,20 @@ echo "" >> "$ADAPTERFILE" if [ -n "$XCATMASTER" ]; then if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT >>"$SCANNICLOG" 2>&1 + openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 else echo "transmit scan result without customer certificate to $XCATMASTER" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $XCATMASTER:$XCATPORT >>"$SCANNICLOG" 2>&1 + openssl s_client -connect $XCATMASTER:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 fi else dhcps=`awk -F ' |;' '/dhcp-server/ { print $(NF-1) }' /var/lib/dhclient/dhclient.leases | tail -n 1` if [ -n "$dhcps" ]; then if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then #use client cert if available - echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $dhcps" >> "$SCANNICLOG" + openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 else echo "transmit scan result without customer certificate to $dhcps" >> "$SCANNICLOG" - cat "$ADAPTERFILE" | openssl s_client -connect $dhcps:$XCATPORT >>"$SCANNICLOG" 2>&1 + openssl s_client -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1 fi fi fi From b0bf7931acf774d28317c9b96d1ded55354b178f Mon Sep 17 00:00:00 2001 From: huweihua Date: Fri, 27 Nov 2015 03:02:02 -0500 Subject: [PATCH 15/19] modify depending on samveen 's comment --- xCAT-genesis-scripts/bin/getadapter | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xCAT-genesis-scripts/bin/getadapter b/xCAT-genesis-scripts/bin/getadapter index 9f1eb002a..1f907230e 100755 --- a/xCAT-genesis-scripts/bin/getadapter +++ b/xCAT-genesis-scripts/bin/getadapter @@ -15,11 +15,10 @@ if [ -f "$ADAPTERFILE" ]; then rm -f "$ADAPTERFILE" >> "$SCANNICLOG" 2>&1 fi - -echo '' > "$ADAPTERFILE" -echo "findadapter" >> "$ADAPTERFILE" -echo "cli" >> "$ADAPTERFILE" -echo "$HOSTNAME" >> "$ADAPTERFILE" +echo " +findadapter +cli +$HOSTNAME" >> "$ADAPTERFILE" #scan adapters have recognized by operating system for n in /sys/class/net/*; do From c8685b21ab29ba772ce8f979c6849917e53cef60 Mon Sep 17 00:00:00 2001 From: huweihua Date: Fri, 27 Nov 2015 03:04:41 -0500 Subject: [PATCH 16/19] modify write file error --- xCAT-server/lib/xcat/plugins/getadapter.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index 2456a699a..6b071cbe2 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -188,7 +188,7 @@ sub handle_findadapter{ $content .= "vendor=".$request->{nic}->[$i]->{vendor}->[0]."|"; } if(exists($request->{nic}->[$i]->{model})){ - $content .= "modle=".$request->{nic}->[$i]->{model}->[0]; + $content .= "model=".$request->{nic}->[$i]->{model}->[0]; } $content .= "\n"; } @@ -198,7 +198,7 @@ sub handle_findadapter{ if(!open($fd,">$inforootdir/$hostname.info")) { xCAT::MsgUtils->trace($VERBOSE,"d","findadapter: can't open $inforootdir/$hostname.info to record adapter info"); }else{ - print $fd, "$content"; + print $fd "$content"; close($fd); } From cac6a5c8afd96e0f180924b0835cf0c1201ee3fd Mon Sep 17 00:00:00 2001 From: huweihua Date: Fri, 27 Nov 2015 03:16:02 -0500 Subject: [PATCH 17/19] add sleep when waitpid --- xCAT-server/lib/xcat/plugins/getadapter.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index 6b071cbe2..6adbcf745 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -331,6 +331,7 @@ sub scan_adapters{ deletenode($request->{missnode}, "$pidreord{$cpid}"); } $forkcount--; + sleep 0.1; } } } From a04f074c080e7b9eb0e35d887cb22a516ebdb690 Mon Sep 17 00:00:00 2001 From: huweihua Date: Fri, 27 Nov 2015 03:47:48 -0500 Subject: [PATCH 18/19] fix some bug found by cheng long --- xCAT-server/lib/xcat/plugins/getadapter.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index 6adbcf745..74b6607bc 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -229,8 +229,10 @@ sub scan_adapters{ my $node; foreach $node (@targetscannodes){ if ( -e "$inforootdir/$node.info"){ - rename("$inforootdir/$node.infoi", "$inforootdir/$node.info.bak"); + rename("$inforootdir/$node.info", "$inforootdir/$node.info.bak"); xCAT::MsgUtils->trace($VERBOSE,"d","getadapters: move $inforootdir/$node.info to $inforootdir/$node.info.bak"); + }else{ + open OUT,">$inforootdir/$node.first" } } @@ -394,8 +396,11 @@ sub get_info_from_local{ }elsif( ! -e "$inforootdir/$node.info" && -e "$inforootdir/$node.info.bak" ){ rename("$inforootdir/$node.info.bak","$inforootdir/$node.info"); push @{$rsp->{data}}, "[$node] Scan failed but old data exist, using the old data:"; - }elsif( -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" ){ + }elsif( -e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" && ! -e "$inforootdir/$node.first"){ push @{$rsp->{data}}, "[$node] with no need for scan due to old data exist, using the old data:"; + }elsif(-e "$inforootdir/$node.info" && ! -e "$inforootdir/$node.info.bak" && -e "$inforootdir/$node.first"){ + unlink "$inforootdir/$node.first"; + push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; }else{ unlink "$inforootdir/$node.info.bak"; push @{$rsp->{data}}, "[$node] scan successfully, below are the latest data:"; From bfc5a88ee2bfe40e4f224a6e8f39a736f775523d Mon Sep 17 00:00:00 2001 From: huweihua Date: Fri, 27 Nov 2015 04:40:48 -0500 Subject: [PATCH 19/19] modify sleep bug --- xCAT-server/lib/xcat/plugins/getadapter.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/getadapter.pm b/xCAT-server/lib/xcat/plugins/getadapter.pm index 74b6607bc..6d028405b 100644 --- a/xCAT-server/lib/xcat/plugins/getadapter.pm +++ b/xCAT-server/lib/xcat/plugins/getadapter.pm @@ -333,8 +333,8 @@ sub scan_adapters{ deletenode($request->{missnode}, "$pidreord{$cpid}"); } $forkcount--; - sleep 0.1; } + sleep 0.1; } }