2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-23 12:12:05 +00:00
chenglch c6e663d1fd Use fifo pipe to enhance getadapter
Currently the getadapter implementation store the nics information
in multiple files. This implementaion will store the records in the
database and add the following changes:

1. Add taskstate table to record the getadapter request.
2. Add route_request hook in xcatd to avoid of too much process.
3. Add adapterinfo column to keep the adapter information.
4. Use fifo pipe to send/recv the adapter message and wake up the waiting process.
5. Use alarm signal to handle the timeout event.
2016-01-25 01:53:54 -05:00

116 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
#set -x
XCATPORT=3001
export XCATPORT
#XCATMASTER="10.3.5.21"
ADAPTERFILE="/tmp/adapterinfo"
SCANNICLOG="/tmp/adapterscan.log"
rm -f "$SCANNICLOG" >/dev/null 2>&1
if [ -f "$ADAPTERFILE" ]; then
echo "rm -f $ADAPTERFILE" > "$SCANNICLOG"
rm -f "$ADAPTERFILE" >> "$SCANNICLOG" 2>&1
fi
echo "<xcatrequest>
<command>getadapter</command>
<clienttype>cli</clienttype>
<noderange>$HOSTNAME</noderange>
<action>update</action>" >> "$ADAPTERFILE"
#scan adapters have recognized by operating system
for n in /sys/class/net/*; do
nic=${n##/sys/class/net/}
if [ "$nic" == "lo" ]; then
continue
else
echo '<nic>' >> "$ADAPTERFILE"
tmp=`udevadm info /sys/class/net/"$nic" | grep " INTERFACE" | awk -F '=' '{print $2}'`
if [ -n "$tmp" ]; then
echo "<interface>$tmp</interface>" >> "$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 [ -n "$tmp" ]; then
echo "<predictablename>$tmp</predictablename>" >> "$ADAPTERFILE"
fi
tmp=`udevadm info /sys/class/net/"$nic" | grep DEVPATH | awk -F 'devices' '{print $2}'`
if [ -n "$tmp" ]; then
echo "<pcilocation>${tmp%/net*}</pcilocation>" >> "$ADAPTERFILE"
fi
echo "<mac>`cat /sys/class/net/$nic/address`</mac>" >> "$ADAPTERFILE"
tmp=`udevadm info /sys/class/net/"$nic" | grep ID_VENDOR_FROM_DATABASE | awk -F '=' '{print $2}' | tr -s "\n" "/" | sed "s/\/$//g"`
if [ -n "$tmp" ]; then
echo "<vendor>$tmp</vendor>" >> "$ADAPTERFILE"
fi
tmp=`udevadm info /sys/class/net/"$nic" | grep ID_MODEL_FROM_DATABASE | awk -F '=' '{print $2}'`
if [ -n "$tmp" ]; then
echo "<model>$tmp</model>" >> "$ADAPTERFILE"
fi
tmp=`ip link show $nic`
if [ -n "$tmp" ]; then
tmp=${tmp#*state }
echo "<linkstate>${tmp% mode*}</linkstate>" >> "$ADAPTERFILE"
fi
echo '</nic>' >> "$ADAPTERFILE"
fi
done
for pci in `lspci |awk '/Ethernet/ {print $1}' `; do
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
tmp=`lspci |grep "$pci"`
echo '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*:}</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
done
for pci in `lspci |awk '/Network/ {print $1}' `; do
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
tmp=`lspci |grep "$pci"`
echo '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*: }</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
done
for pci in `lspci |awk '/Mellanox/ {print $1}' `; do
if ! grep -q "$pci" "$ADAPTERFILE" 2>/dev/null; then
tmp=`lspci |grep "$pci"`
echo '<nic>' >> "$ADAPTERFILE"
echo "<pcilocation>$pci</pcilocation>" >> "$ADAPTERFILE"
echo "<model>${tmp##*: }</model>" >> "$ADAPTERFILE"
echo '</nic>' >> "$ADAPTERFILE"
fi
done
echo "</xcatrequest>" >> "$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
echo "using /etc/xcat/certkey.pem and /etc/xcat/cert.pem to transmit scan result to $XCATMASTER" >> "$SCANNICLOG"
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"
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"
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"
openssl s_client -connect $dhcps:$XCATPORT <"$ADAPTERFILE" >>"$SCANNICLOG" 2>&1
fi
fi
fi