From 8257a97b8f163b5fa4fc93859ede6baf71196320 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Mon, 11 Jul 2011 18:52:03 +0000 Subject: [PATCH] Continue work on nbroot2 git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10049 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-nbroot2/dodiscovery | 89 +++++++++++++++++++++++++++++++++--- xCAT-nbroot2/udpcat.awk | 12 +++++ xCAT-nbroot2/xcat-cmdline.sh | 1 + 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100755 xCAT-nbroot2/udpcat.awk diff --git a/xCAT-nbroot2/dodiscovery b/xCAT-nbroot2/dodiscovery index f5b2ddcd6..5531bc4b6 100755 --- a/xCAT-nbroot2/dodiscovery +++ b/xCAT-nbroot2/dodiscovery @@ -10,7 +10,7 @@ done 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)) + waitforlink=$((waitforlink - 1)) sleep 0.1 if [ $waitforlink = 1 ]; then echo "No link detected on $NICSTOBRINGUP" @@ -40,10 +40,87 @@ while [ ! -z "$NICSGETTINGADDR" -a $timewaiting != 700 ]; do NICSGETTINGADDR=$NEWNICSGETTINGADDR done echo "Stopped waiting on nics to get addresses" - - - -while [ ! -r /restart ]; do - sleep 1 +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... +MTM=unknown +SERIAL=unknown +ARCH=unknown +ARCH=`uname -m` #32-bit only is old news +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}'` + fi +elif [ -r /proc/device-tree/model ]; then #POWER + MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'` +fi +CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l` +MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{print $2}'` +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/^ //'` +echo '' > /tmp/discopacket +echo "findme" >> /tmp/discopacket +echo "$ARCH" >> /tmp/discopacket +if [ ! -z "$IAMAVM" ]; then + echo "virtual" >> /tmp/discopacket +fi +echo "$CPUCOUNT" >> /tmp/discopacket +echo "$CPUTYPE" >> /tmp/discopacket +echo "$MEMORY" >> /tmp/discopacket +if [ "$MTM" != "unknown" ]; then + echo "$MTM" >> /tmp/discopacket +fi +if [ "$SERIAL" != "unknown" ]; then + echo "$SERIAL" +fi +for dev in `ip link|grep -B1 ether|grep UP|awk '{print $2}'|sed -e s/://`; do + DRIVER=`grep DRIVER /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}'` + echo "$DRIVER|$MAC|$ADDRESS" >> /tmp/discopacket +done +echo "$PUBKEY" >> /tmp/discopacket #this is not secure to use by itself, switch sourced pubkey for security +echo "" >> /tmp/discopacket +echo "" >> /tmp/discopacket +echo "" >> /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" = "" ]; then + cat /tmp/discopacket.b64sig >> /tmp/discopacket.new + fi + echo $line >> /tmp/discopacket.new +done +mv /tmp/discopacket.new /tmp/discopacket + + +while [ ! -r /restart ]; do + if [ ! -z "$XCATMASTER" ]; then + (ping -c 1 $XCATMASTER cat /tmp/discopacket | udpcat.awk $XCATMASTER $XCATPORT ) & + fi + for dhcps in `grep dhcp-server /var/lib/dhclient/dhclient.leases|awk '{print $4}'|sed -s 's/;//'`; do + (ping -c 1 $XCATMASTER cat /tmp/discopacket | udpcat.awk $dhcps $XCATPORT ) & + done + cat /tmp/discopacket + sleep 5 done diff --git a/xCAT-nbroot2/udpcat.awk b/xCAT-nbroot2/udpcat.awk new file mode 100755 index 000000000..6a3c2c166 --- /dev/null +++ b/xCAT-nbroot2/udpcat.awk @@ -0,0 +1,12 @@ +#!/usr/bin/awk -f +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +BEGIN { + xcatdport = ARGV[2] + xcatdhost = ARGV[1] + delete ARGV[1] + delete ARGV[2] + RS="" +} +END { + print $0 |& "/inet/udp/301/"xcatdhost"/"xcatdport +} diff --git a/xCAT-nbroot2/xcat-cmdline.sh b/xCAT-nbroot2/xcat-cmdline.sh index 23eedaa68..0ff3b9e78 100755 --- a/xCAT-nbroot2/xcat-cmdline.sh +++ b/xCAT-nbroot2/xcat-cmdline.sh @@ -52,6 +52,7 @@ mkdir -p /etc/xcat openssl genrsa -out /etc/xcat/privkey.pem 1024 PUBKEY=`openssl rsa -in /etc/xcat/privkey.pem -pubout|grep -v "PUBLIC KEY"` PUBKEY=`echo $PUBKEY|sed -e 's/ //g'` +export PUBKEY mkdir -p /var/lib/lldpad echo 'lldp :' >> /var/lib/lldpad/lldpad.conf echo '{' >> /var/lib/lldpad/lldpad.conf