2013-01-15 20:00:44 +00:00
|
|
|
#!/bin/bash
|
2012-12-07 15:59:34 +00:00
|
|
|
minixcatd.awk &
|
|
|
|
PUBKEY=`openssl rsa -in /etc/xcat/privkey.pem -pubout 2> /dev/null|grep -v "PUBLIC KEY"`
|
|
|
|
PUBKEY=`echo $PUBKEY|sed -e 's/ //g'`
|
|
|
|
export PUBKEY
|
|
|
|
|
|
|
|
echo "Beginning node discovery process"
|
2013-08-13 17:28:34 +00:00
|
|
|
for nic in `ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep -v ,LOWER_UP|awk -F: '{print $2}'`; do
|
|
|
|
ip link set $nic up
|
|
|
|
done
|
2012-12-07 15:59:34 +00:00
|
|
|
waitforlink=100
|
|
|
|
while [ ! -z "$NICSTOBRINGUP" -a $waitforlink -gt 0 ]; do
|
|
|
|
NICSTOBRINGUP=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep -v ,LOWER_UP|awk -F: '{print $2}'`
|
|
|
|
waitforlink=$((waitforlink - 1))
|
|
|
|
sleep 0.1
|
|
|
|
if [ $waitforlink = 1 ]; then
|
|
|
|
echo "No link detected on $NICSTOBRINGUP"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
NICSGETTINGADDR=`ip link|grep mtu|grep -v LOOPBACK|grep -v usb|grep ,LOWER_UP|awk -F: '{print $2}'`
|
|
|
|
timewaiting=0
|
|
|
|
echo "Waiting for nics to get addresses"
|
|
|
|
while [ ! -z "$NICSGETTINGADDR" -a $timewaiting != 700 ]; do
|
|
|
|
NEWNICSGETTINGADDR=""
|
|
|
|
for nic in $NICSGETTINGADDR; do
|
|
|
|
if ! ip addr show dev $nic |grep -v inet6|grep inet >/dev/null; then
|
|
|
|
NEWNICSGETTINGADDR="$NEWNICSGETTINGADDR $nic"
|
|
|
|
else
|
|
|
|
echo -n "$nic|"
|
|
|
|
ip addr show dev $nic |grep -v inet6|grep inet|sed -e s/\\/.*//|awk '{print $2}'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
sleep 0.1
|
|
|
|
timewaiting=$((timewaiting+1))
|
|
|
|
if [ $timewaiting = 699 ]; then
|
|
|
|
echo "No DHCP answer for $nic, ignoring interface"
|
|
|
|
fi
|
|
|
|
NICSGETTINGADDR=$NEWNICSGETTINGADDR
|
|
|
|
done
|
|
|
|
if [ $timewaiting != 700 -a $timewaiting -gt 450 ]; then
|
|
|
|
echo "Got an address, but it took inordinately long, you may want to check spanning tree configuration"
|
|
|
|
fi
|
|
|
|
echo "Network configuration complete, commencing transmit of discovery packets"
|
|
|
|
XCATPORT=3001
|
|
|
|
export XCATPORT
|
|
|
|
for parm in `cat /proc/cmdline`; do
|
|
|
|
key=`echo $parm|awk -F= '{print $1}'`
|
|
|
|
if [ "$key" = "xcatd" ]; then
|
|
|
|
XCATMASTER=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $1}'`
|
|
|
|
XCATPORT=`echo $parm|awk -F= '{print $2}'|awk -F: '{print $2}'`
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
#time to make our packet...
|
2013-07-15 14:09:19 +00:00
|
|
|
while [ ! -r /restart ]; do
|
2012-12-07 15:59:34 +00:00
|
|
|
MTM=unknown
|
|
|
|
SERIAL=unknown
|
|
|
|
ARCH=unknown
|
|
|
|
ARCH=`uname -m` #32-bit only is old news
|
2014-09-10 08:51:06 +00:00
|
|
|
PLATFORM=unknown
|
2012-12-07 15:59:34 +00:00
|
|
|
if [ -r /sys/devices/virtual/dmi/id/product_name ]; then #x86
|
|
|
|
PRODNAME=`cat /sys/devices/virtual/dmi/id/product_name`
|
|
|
|
IAMAVM=0
|
|
|
|
if [ "$PRODNAME" = "KVM" ]; then
|
|
|
|
IAMAVM=1
|
|
|
|
MTM=KVM
|
|
|
|
elif [ "$PRODNAME" = "VMware Virtual Platform" ]; then
|
|
|
|
IAMAVM=1
|
|
|
|
MTM=VMware
|
|
|
|
else
|
|
|
|
MTM=`cat /sys/devices/virtual/dmi/id/product_name|awk -F'[' '{print $2}'|awk -F']' '{print $1}'`
|
|
|
|
SERIAL=`cat /sys/devices/virtual/dmi/id/product_serial`
|
|
|
|
fi
|
2014-09-05 09:10:54 +00:00
|
|
|
CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l`
|
|
|
|
grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing
|
|
|
|
echo $line > /tmp/cpumod
|
|
|
|
done
|
|
|
|
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
|
|
|
|
UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /sys/devices/virtual/dmi/id/product_uuid`
|
|
|
|
|
2012-12-07 15:59:34 +00:00
|
|
|
elif [ -r /proc/device-tree/model ]; then #POWER
|
2014-09-05 09:10:54 +00:00
|
|
|
#MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'`
|
|
|
|
MTM=`cat /proc/device-tree/model | sed -e 's/\^.*,//'`
|
|
|
|
CPUCOUNT=`cat /proc/cpuinfo |grep -e "^cpu\s*:"|wc -l`
|
2014-09-10 08:51:06 +00:00
|
|
|
PLATFORM=`cat /proc/cpuinfo | grep -e "^platform\s*:" | awk '{print \$3}'`
|
2014-09-05 09:10:54 +00:00
|
|
|
grep -e "^cpu\s*:" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing
|
|
|
|
echo $line > /tmp/cpumod
|
|
|
|
done
|
|
|
|
CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
|
|
|
|
SERIAL=`cat /proc/device-tree/system-id`
|
|
|
|
UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /proc/sys/kernel/random/uuid`
|
|
|
|
|
2012-12-07 15:59:34 +00:00
|
|
|
fi
|
2014-09-05 09:10:54 +00:00
|
|
|
#CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l`
|
2013-12-19 13:25:41 +00:00
|
|
|
|
|
|
|
# The MEMORY will look like this: 32868920
|
|
|
|
MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{printf "%.0fMB\n", $2/1024}'`
|
|
|
|
# The MEMORY will look like this: 32GiB
|
|
|
|
#MEMORY=`lshw -C memory -short |grep "System Memory"|awk -F' ' '{print $3}'`
|
|
|
|
|
|
|
|
# The DISKSIZE will look like this: /dev/sda:250GB,/dev/sdb:250GB
|
|
|
|
#DISKSIZE=`lshw -C disk -short |grep disk |awk -F' ' '{print $2":"$4}'|sed 'N;s/\n/,/'`
|
|
|
|
# The DISKSIZE will look like this: sdb:250GB,sda:250GB
|
|
|
|
DISKSIZE=`cat /proc/partitions |grep -e "sd.\>" |awk -F' ' '{printf "%s:%.0fGB\n", $4, $3*0.000001024}' |sed 'N;s/\n/,/'`
|
|
|
|
|
2014-09-05 09:10:54 +00:00
|
|
|
#UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /sys/devices/virtual/dmi/id/product_uuid`
|
|
|
|
#grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing
|
|
|
|
# echo $line > /tmp/cpumod
|
|
|
|
#done
|
|
|
|
#CPUTYPE=`cat /tmp/cpumod|awk -F':' '{print $2}'|sed -e 's/^ //'`
|
2012-12-07 15:59:34 +00:00
|
|
|
echo '<xcatrequest>' > /tmp/discopacket
|
|
|
|
echo "<command>findme</command>" >> /tmp/discopacket
|
|
|
|
echo "<arch>$ARCH</arch>" >> /tmp/discopacket
|
|
|
|
if [ "$IAMAVM" = 1 ]; then
|
|
|
|
echo "<nodetype>virtual</nodetype>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
echo "<cpucount>$CPUCOUNT</cpucount>" >> /tmp/discopacket
|
|
|
|
echo "<cputype>$CPUTYPE</cputype>" >> /tmp/discopacket
|
|
|
|
echo "<memory>$MEMORY</memory>" >> /tmp/discopacket
|
2013-12-19 13:25:41 +00:00
|
|
|
echo "<disksize>$DISKSIZE</disksize>" >> /tmp/discopacket
|
2014-09-05 09:10:54 +00:00
|
|
|
if [ "$UUID" != "unknown" ]; then
|
|
|
|
echo "<uuid>$UUID</uuid>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
|
2012-12-07 15:59:34 +00:00
|
|
|
if [ "$MTM" != "unknown" ]; then
|
|
|
|
echo "<mtm>$MTM</mtm>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
if [ "$SERIAL" != "unknown" ]; then
|
|
|
|
echo "<serial>$SERIAL</serial>" >> /tmp/discopacket
|
|
|
|
fi
|
2014-09-10 08:51:06 +00:00
|
|
|
if [ "$PLATFORM" != "unknown" ]; then
|
|
|
|
echo "<platform>$PLATFORM</platform>" >> /tmp/discopacket
|
|
|
|
fi
|
2013-01-15 20:00:44 +00:00
|
|
|
#so we have some cases where DMI table explictly records every function number, and some where only first function is enumerated
|
|
|
|
#so for each onboard device, we record it. If it is also the first function, we'll seek out other function numbers and append
|
|
|
|
#if that other function number does not show up in its own dmi type 41 record
|
|
|
|
for onboard in `dmidecode -t 41|egrep '(Type:|Bus Address)'|grep -A1 Ethernet|grep -v Ethernet|sed -e 's/.*Address: //'`; do
|
|
|
|
obdevs=("${obdevs[@]}" $onboard)
|
|
|
|
if [ ${onboard#*.}=0 ]; then
|
|
|
|
truncslot=${onboard%.*}
|
|
|
|
for obslot in `grep $truncslot /sys/class/net/*/device/uevent|sed -e s/.*=//`; do
|
|
|
|
if ! dmidecode -t 41|grep $obslot > /dev/null; then
|
|
|
|
obdevs=("${obdevs[@]}" $obslot)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
#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=""
|
|
|
|
ONBOARDINDEX=""
|
2012-12-07 15:59:34 +00:00
|
|
|
DRIVER=`grep DRIVER /sys/class/net/$dev/device/uevent|awk -F= '{print $2}'`
|
2013-01-15 20:00:44 +00:00
|
|
|
PCI_SLOT=`grep PCI_SLOT_NAME /sys/class/net/$dev/device/uevent|awk -F= '{print $2}'`
|
2012-12-07 15:59:34 +00:00
|
|
|
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/`
|
2013-01-15 20:00:44 +00:00
|
|
|
if [ ! -z "$PCI_SLOT" ]; 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
|
|
|
|
index=1
|
|
|
|
for s in ${obdevs[@]}; do
|
|
|
|
if [ "$s" = "$PCI_SLOT" ]; then
|
|
|
|
ONBOARDINDEX=$index
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
index=$((index+1))
|
|
|
|
done
|
|
|
|
if [ ! -z "$ONBOARDINDEX" ]; then
|
|
|
|
FIRMDESC=`dmidecode -t 41|egrep '(Designation|Address)' |grep -B 1 $PCI_SLOT|grep Designation|sed -e 's/.*: //'`
|
|
|
|
if [ -z "$FIRMDESC" ]; then
|
|
|
|
SHORTPCISLOT=${PCI_SLOT%.*}
|
|
|
|
FIRMDESC=`dmidecode -t 41|egrep '(Designation|Address)' |grep -B 1 $SHORTPCISLOT|grep Designation|sed -e 's/.*: //'`
|
|
|
|
fi
|
|
|
|
SLOTNAME="Onboard Ethernet $ONBOARDINDEX"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2013-01-22 21:19:11 +00:00
|
|
|
echo "<mac>$DRIVER|$dev|$MAC|$ADDRESS</mac>" >> /tmp/discopacket
|
2013-01-25 14:37:17 +00:00
|
|
|
echo "<nic>" >> /tmp/discopacket
|
|
|
|
echo " <devname>$dev</devname>" >> /tmp/discopacket
|
|
|
|
echo " <driver>$DRIVER</driver>" >> /tmp/discopacket
|
|
|
|
if [ ! -z "$ADDRESS" ]; then
|
|
|
|
echo " <ip4address>$ADDRESS</ip4address>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
echo " <hwaddr>$MAC</hwaddr>" >> /tmp/discopacket
|
|
|
|
if [ ! -z "$PCI_SLOT" ]; then
|
|
|
|
echo " <pcidev>$PCI_SLOT</pcidev>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
if [ ! -z "$SLOTNAME" ]; then
|
|
|
|
echo " <location>$SLOTNAME</location>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
if [ ! -z "$ONBOARDINDEX" ]; then
|
|
|
|
echo " <onboardeth>$ONBOARDINDEX</onboardeth>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
if [ ! -z "$FIRMDESC" ]; then
|
|
|
|
echo " <firmdesc>$FIRMDESC</firmdesc>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
myswitch=`lldptool -n -i $dev -t -V sysName|grep -v 'System Name TLV'|sed -e 's/^ *//'`
|
|
|
|
if [ ! -z "$myswitch" -a "$myswitch" != "Agent instance for device not found" ]; then
|
|
|
|
echo " <switchname>$myswitch</switchname>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
for switchaddr in `lldptool -i $dev -n -t -V mngAddr|grep IP|sed -e 's/.*:.//'`; do
|
|
|
|
if [ "$switchaddr" = "Agent instance for device not found" ]; then break; fi
|
|
|
|
echo " <switchaddr>$switchaddr</switchaddr>" >> /tmp/discopacket
|
|
|
|
done
|
|
|
|
myswitchdesc=`lldptool -n -i $dev -t -V sysDesc|grep -v 'System Description TLV'|sed -e 's/^ *//'`
|
|
|
|
if [ ! -z "$myswitchdesc" -a "$myswitchdesc" != "Agent instance for device not found" ]; then
|
|
|
|
echo " <switchdesc>$myswitchdesc</switchdesc>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
myport=`lldptool -n -i $dev -t -V portDesc|grep -v 'Port Description TLV'|sed -e 's/^ *//'`
|
|
|
|
if [ ! -z "$myport" -a "$myswitchdesc" != "Agent instance for device not found" ]; then
|
|
|
|
echo " <switchport>$myport</switchport>" >> /tmp/discopacket
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "</nic>" >> /tmp/discopacket
|
2012-12-07 15:59:34 +00:00
|
|
|
done
|
|
|
|
echo "<xcatpubkey>$PUBKEY</xcatpubkey>" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security
|
|
|
|
echo "<sha512sig>" >> /tmp/discopacket
|
|
|
|
echo "</sha512sig>" >> /tmp/discopacket
|
|
|
|
echo "</xcatrequest>" >> /tmp/discopacket
|
|
|
|
openssl dgst -sha512 -out /tmp/discopacket.sha512 -sign /etc/xcat/privkey.pem /tmp/discopacket
|
|
|
|
openssl enc -e -a -in /tmp/discopacket.sha512 > /tmp/discopacket.b64sig
|
|
|
|
cat /tmp/discopacket |while read line; do
|
|
|
|
if [ "$line" = "</sha512sig>" ]; then
|
|
|
|
cat /tmp/discopacket.b64sig >> /tmp/discopacket.new
|
|
|
|
fi
|
|
|
|
echo $line >> /tmp/discopacket.new
|
|
|
|
done
|
|
|
|
mv /tmp/discopacket.new /tmp/discopacket
|
|
|
|
|
2013-01-25 14:37:17 +00:00
|
|
|
rm -f /tmp/discopacket.gz
|
|
|
|
gzip -9 /tmp/discopacket
|
2012-12-07 15:59:34 +00:00
|
|
|
if [ ! -z "$XCATMASTER" ]; then
|
2013-01-25 14:37:17 +00:00
|
|
|
(cat /tmp/discopacket.gz | udpcat.awk $XCATMASTER $XCATPORT ) &
|
2012-12-07 15:59:34 +00:00
|
|
|
fi
|
|
|
|
for dhcps in `grep dhcp-server /var/lib/dhclient/dhclient.leases|awk '{print $4}'|sed -s 's/;//'`; do
|
2013-01-25 14:37:17 +00:00
|
|
|
(cat /tmp/discopacket.gz | udpcat.awk $dhcps $XCATPORT ) &
|
2012-12-07 15:59:34 +00:00
|
|
|
done
|
|
|
|
#cat /tmp/discopacket
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
/bin/restart
|