You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by rg...@apache.org on 2010/07/17 11:05:47 UTC

svn commit: r965052 - /incubator/tashi/trunk/src/zoni/system/registration/register_node

Author: rgass
Date: Sat Jul 17 11:05:46 2010
New Revision: 965052

URL: http://svn.apache.org/viewvc?rev=965052&view=rev
Log:
Adding initial version of register_node.  This file is pulled by the
registation initrd,  captures system information, and submits it back to the
server to register the node to zoni.



Added:
    incubator/tashi/trunk/src/zoni/system/registration/register_node   (with props)

Added: incubator/tashi/trunk/src/zoni/system/registration/register_node
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/zoni/system/registration/register_node?rev=965052&view=auto
==============================================================================
--- incubator/tashi/trunk/src/zoni/system/registration/register_node (added)
+++ incubator/tashi/trunk/src/zoni/system/registration/register_node Sat Jul 17 11:05:46 2010
@@ -0,0 +1,229 @@
+#!/bin/sh
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.    
+
+#
+#  $Id$
+#
+
+DEBUG () {
+	if [ $VERBOSE ] && [ $VERBOSE -eq 1 ];then 
+		echo DEBUG: $*
+	fi
+}
+
+#  Capture vars passed via kernal args
+for x in $(cat /proc/cmdline); do
+    case $x in
+    imagename=*)
+        IMAGENAME=${x#imagename=}
+        ;;
+    pxeserver=*)
+        PXESERVER=${x#pxeserver=}
+        ;;
+    defaultimage=*)
+        DEFAULTIMAGE=${x#defaultimage=}
+        ;;
+    verbose=*)
+        VERBOSE=${x#verbose=}
+        ;;
+	esac
+done
+
+#  Scrape system for specs
+/sbin/getSystemId > /tmp/sysinfo
+cat /proc/cpuinfo >> /tmp/sysinfo
+cat /proc/meminfo >> /tmp/sysinfo
+ifconfig eth0 >> /tmp/sysinfo
+#fdisk >> /tmp/sysinfo
+
+DEBUG "pxeserver is ", ${PXESERVER}
+
+
+(echo -n "MAC:          "; ifconfig eth0 | grep "HWaddr" | awk '{print $5}') >> /tmp/sysinfo
+
+DEBUG $(cat /tmp/sysinfo)
+sleep 1
+MAC=$(cat /tmp/sysinfo | grep "HWaddr" | awk '{print $5}') 
+DEBUG MAC - $MAC
+MOD_MAC=`cat /tmp/sysinfo | grep "^MAC" | cut -c 15- | sed 's/:/-/g' | sed 'y/ABCDEF/abcdef/'`
+DEBUG MOD_MAC - $MOD_MAC
+SYS_MODEL=$(cat /tmp/sysinfo | grep "^Product Name:" | cut -c 15- | sed 's/ /+/g')
+DEBUG SYS_MODEL is $SYS_MODEL
+SERVICE_TAG=$(cat /tmp/sysinfo | grep "^Service Tag:" | cut -c 15- | sed 's/ /+/g')
+DEBUG SERVICE_TAG is $SERVICE_TAG
+EXPRESS_SERVICE_CODE=$(cat /tmp/sysinfo | grep "^Express Service Code:" | cut -c 15- | sed 's/ /+/g')
+DEBUG EXPRESS_SERVICE_CODE is $EXPRESS_SERVICE_CODE
+BIOS_REV=$(cat /tmp/sysinfo | grep "^BIOS Version:" | cut -c 15- | sed 's/ /+/g')
+DEBUG BIOS_REV - $BIOS_REV
+SYS_VENDOR=$(cat /tmp/sysinfo | grep "^Vendor:" | cut -c 15- | sed 's/ /+/g')
+#NUM_PROC=$(cat /proc/cpuinfo | grep processor | wc -l);
+
+PROC_VENDOR=$(cat /tmp/sysinfo | grep vendor_id | cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+PROC_MODEL=$(cat /tmp/sysinfo | grep "model name"| cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+CLOCK_SPEED=$(cat /tmp/sysinfo | grep "cpu MHz"| cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+PROC_CACHE=$(cat /tmp/sysinfo | grep "cache size"| cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+CPU_FLAGS=$(cat /tmp/sysinfo | grep "flags"| cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+NUM_PROCS=$(cat /tmp/sysinfo | grep "physical id" | sort | uniq | wc -l | sed 's/ /+/g');
+DA_PROCS=$(cat /tmp/sysinfo | grep "physical id" | sort | uniq | wc -l);
+#NUM_CORES=$(cat /tmp/sysinfo | grep "cpu cores"| cut -d ":" -f 2 | tail -n1 | sed 's/ /+/g');
+DA_CORES=$(cat /tmp/sysinfo | grep "cpu cores"| cut -d ":" -f 2 | tail -n1);
+NUM_CORES=$(echo $(($DA_PROCS * $DA_CORES)))
+MEM_TOTAL=$(cat /tmp/sysinfo | grep "MemTotal"| awk '{print $2}' | sed 's/ /+/g');
+SUBNET=$(cat /tmp/sysinfo | grep "inet addr"| awk '{print $2}' | cut -d ":" -f 2 | awk -F "." '{print $3}');
+
+#disk_size=$(cat /tmp/sysinfo | grep "Disk"| awk '{print $5}');
+
+#  Register sysinfo to DB
+DEUBG 'running cmd - wget -O- "http://${PXESERVER}/zoni-register.php?action=register_system&mac=$MAC&mod_mac=$MOD_MAC&sys_model=$SYS_MODEL&bios_rev=$BIOS_REV&service_tag=$SERVICE_TAG&express_service_code=$EXPRESS_SERVICE_CODE&sys_vendor=$SYS_VENDOR&proc_vendor=$PROC_VENDOR&proc_model=$PROC_MODEL&clock_speed=$CLOCK_SPEED&proc_cache=$PROC_CACHE&num_procs=$NUM_PROCS&num_cores=$NUM_CORES&mem_total=$MEM_TOTAL&cpu_flags=$CPU_FLAGS"'
+wget -O- "http://${PXESERVER}/zoni-register.php?action=register_system&mac=$MAC&mod_mac=$MOD_MAC&sys_model=$SYS_MODEL&bios_rev=$BIOS_REV&service_tag=$SERVICE_TAG&express_service_code=$EXPRESS_SERVICE_CODE&sys_vendor=$SYS_VENDOR&proc_vendor=$PROC_VENDOR&proc_model=$PROC_MODEL&clock_speed=$CLOCK_SPEED&proc_cache=$PROC_CACHE&num_procs=$NUM_PROCS&num_cores=$NUM_CORES&mem_total=$MEM_TOTAL&cpu_flags=$CPU_FLAGS"
+
+#  Get more info either from cheat file or from user entered info
+ec=1
+if [[ -e /register_automate ]]; then
+	switchinfo=`/register_automate $SERVICE_TAG switchinfo`
+	switchport=$(echo $switchinfo | cut -d ":" -f 2)
+	switch=$(echo $switchinfo | cut -d ":" -f 1)
+	pduinfo=`/register_automate $SERVICE_TAG pduinfo`
+	pduport=$(echo $pduinfo | cut -d ":" -f 2)
+	pdu_name=$(echo $pduinfo | cut -d ":" -f 1)
+	location=`/register_automate $SERVICE_TAG location`
+	hn=`/register_automate $SERVICE_TAG hostname`
+	ip_addr=`/register_automate $SERVICE_TAG ipaddr`
+	ec=$?
+	DEBUG "Register automate completed"
+	DEBUG "ec is $ec"
+fi
+
+#  If we have no information about this node in cheat file
+#  Ask user for the info
+#  rgass, leaving this out for now.  Haven't tested and not sure if we want a timer on this
+#echo "Hit any key (except enter) to begin interactive node entry (timeout in 10 seconds)"
+#stty -icanon min 0 time 100
+#answer=$(dd bs=1 count=1 2>/dev/null)
+#val=${#answer}
+#if [ $val -gt 0 ];then
+
+if [[ $ec -ne 0 ]]; then
+	ans=n;
+	while [ $ans == "n" ] || [ $ans == "N" ]; do
+		echo -n "Please enter the location for this node: "
+		read location
+		#echo -n "Please enter the hostname for this node: "
+		#read hn
+		echo -n "Please enter the IP address for this node: "
+		read ip_addr
+		echo -n "if you know what image you want, enter it here: "
+		read daimage
+		echo -n "Enter Switch name:port e.g. sw0-r3r2:8: "
+		read switchinfo
+		echo -n "Enter PDU name:port e.g. pdu0-r3r2:8: "
+		read pduinfo
+
+		##  Confirm summary
+		echo "--  Summary --"
+		echo "Location: $location"
+		#echo "Hostname: $hn"
+		echo "IP address: $ip_addr"
+		echo "Image name: $daimage"
+		echo "SwitchInfo: $switchinfo"
+		echo "Save Configuation? [y/n]"
+		read ans
+		##  Submit some stuff that was entered
+
+		switchport=$(echo $switchinfo | cut -d ":" -f 2)
+		switch=$(echo $switchinfo | cut -d ":" -f 1)
+
+		pduport=$(echo $pduinfo | cut -d ":" -f 2)
+		pdu_name=$(echo $pduinfo | cut -d ":" -f 1)
+
+	done
+	#  Update IP_ADDR
+	if [ $ip_addr ];then 
+		DEBUG "Update ip $ip_addr"
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=addip&mac=$MAC&ip_addr=$ip_addr"
+	fi
+	if [ $location ];then 
+		DEBUG "Set location"
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=addlocation&mac=$MAC&location=$location"
+	fi
+	#  If we set the imagename, register it
+	if [ $daimage ];then
+		DEBUG "setting image name"
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=assign_image&mac=$MAC&image_name=$daimage&location=$location"
+	#else
+		#wget -O- "http://${PXESERVER}/zoni-register.php?action=bootopt&machine_type=generic&mac=$MAC&image_name=$DEFAULTIMAGE"
+	fi
+#############################
+##  USE REGISTER_AUTOMATE  ##
+#############################
+else
+	# using register automate file info
+	DEBUG "Getting bootopt..."
+	bootopt=$(/register_automate $SERVICE_TAG bootopt)
+	ec=$?
+	if [[ $ec -eq 0 ]]; then
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=assign_image&mac=$MAC&image_name=$bootopt&location=$location"
+	fi 
+	DEBUG "about to update ip $ip_addr in automate"
+	if [ $ip_addr ];then 
+		echo wget -O- "http://${PXESERVER}/zoni-register.php?action=addip&mac=$MAC&ip_addr=$ip_addr"
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=addip&mac=$MAC&ip_addr=$ip_addr"
+	fi
+	if [ $location ];then 
+		wget -O- "http://${PXESERVER}/zoni-register.php?action=addlocation&mac=$MAC&location=$location"
+	fi
+fi
+if [ $switchport ];then 
+	wget -O- "http://${PXESERVER}/zoni-register.php?action=addswitchinfo&mac=$MAC&switch=${switch}&switchport=${switchport}"
+fi
+
+if [ $pduport ];then 
+	wget -O- "http://${PXESERVER}/zoni-register.php?action=addswitchinfo&mac=$MAC&switch=${pdu_name}&switchport=${pduport}"
+fi
+
+#  Add IPMI info 
+wget -O/outfile.txt "http://${PXESERVER}/zoni-register.php?action=add_ipmi&mac=$MAC&location=$location"
+IPMI_ADDR=$(cat /outfile.txt | grep IPMI_ADDR | awk '{print $2}')
+IPMI_PASSWORD=$(cat /outfile.txt | grep IPMI_ADDR | awk '{print $4}')
+
+echo $IPMI_ADDR and $IPMI_PASSWORD
+
+ipmitool lan set 1 ipaddr $IPMI_ADDR
+ipmitool lan set 1 vlan id 998 
+ipmitool lan set 1 defgw ipaddr 0.0.0.0
+ipmitool lan set 1 netmask 255.255.255.0
+ipmitool lan set 1 password $IPMI_PASSWORD
+ipmitool lan set 1 access on
+
+#  Make user 2 be root with random password
+ipmitool user set name 2 root
+ipmitool user set password 2 $IPMI_PASSWORD
+ipmitool channel setaccess 1 2 callin=on ipmi=on link=on privilege=4
+ipmitool user enable 2
+
+#  Add dns and dhcp
+wget -O- "http://${PXESERVER}/zoni-register.php?action=updatednsdhcp&mac=${MAC}&location=$location&ip_addr=$ip_addr&ipmi_addr=$IPMI_ADDR"
+
+
+#  If default image is set as kernel opt, override automate file
+DEBUG "def image is $DEFAULTIMAGE "
+if [ $DEFAULTIMAGE ] ; then 
+	wget -O- "http://${PXESERVER}/zoni-register.php?action=assign_image&mac=$MAC&image_name=$DEFAULTIMAGE&location=$location"
+fi
+#else
+	#echo "Interactive mode canceled due to no keyboard input"

Propchange: incubator/tashi/trunk/src/zoni/system/registration/register_node
------------------------------------------------------------------------------
    svn:executable = *