Gheek.net

January 27, 2008

bldsvr-namebldsvrs_exp

Filed under: blade servers, expect, HP — Tags: , , — lancevermilion @ 11:47 pm
#!/cygdrive/c//bin/expect --
#Purpose: Create a standard configuration on HP blade server chassises BL20s
#             and read in from file a list of names for each port.

# syntax: main.exp  
# returns: 1 bad file (chassis-server-blade-file)
#	   2 at least one device subdirectory can not be create (e.g. devname is a file, not a dir)

# Load global ATM variables and procedures
# source ./libglobal.exp

# Process command tail
set codepath [file dirname [info script]]
set path [lindex $argv 0]
set blade_file $path/Blade.csv.unix
send_user $blade_file
if [file exists $blade_file] {
	send_user "blade file exists, continuing\n"
} else {
	send_user "bad blade file name or bad path, exiting\n"
	exit 1 }
set debug_on [lindex $argv 1]

# Initialize misc fields and controls
#temporary working field, always init immediately before use
set temp_string ""
set timeout 60
exp_internal $debug_on
set target_sdir [file dirname $blade_file]
set run_log $target_sdir//run.log
set run_log_txt $target_sdir/run.log.txt

# Turn off screen logging, turn on file logging
log_user $debug_on
log_file -noappend -a $run_log

# Clear a few lines on the screen and announce process status
send_user "\n"
send_user "\n"
send_user "\n"
send_user "main.exp initialized and executing!\n"
set current_date_time [timestamp -format "Date:Time=%Y%m%d:%X"]
send_user $current_date_time\n

# Open chassis-server-blad-file
set handle [open $blade_file]
set end_of_file [eof $handle]


# Outer loop processes chassis row in chassis-server-blade-file
set chassis_row 0
gets $handle chassis_row
set chassis_list [split $chassis_row ,]

while {!$end_of_file == 1} {
	set element_idx 0
# note....lists are zero relative count
	set chassis_name [lindex $chassis_list 0]
	set server_num 0
	send_user "\n\n"

# Inner loop processes each server blade for server A
# note.....1st element is chassis name
	set element_idx 1
	set port 1
# note.....2nd thru 8th element are the blades
	while {$element_idx <= [llength $chassis_list]} {
		set chassis_blade [lindex $chassis_list $element_idx]
		set server_num [expr $server_num + 1]
		if ![string equal $chassis_blade ""] {
# Create Server A file
			set server_name $chassis_blade
			append server_name "A"
			send_user "\nThe following is the config for Chassis-Server $server_name\n"
			send_user   "_______________________________________________________\n"
#snmp syntax /c/snmp/cfg name|locn|cont|rcomm|wcomm|trap1|trap2|t1comm|t2comm|auth |lnkt  
			send_user "/c/snmp/cfg cont \"some contact info\"\n"
			send_user "/c/snmp/cfg rcomm snmpreadcommunity\n"
			send_user "/c/snmp/cfg wcomm snmpreadwritecommunity\n"
			send_user "/c/snmp/cfg trap1 snmp-trap-host-ip\n"
			send_user "/c/snmp/cfg t1comm snmpreadcommunity\n"
			send_user "/c/snmp/cfg auth disable\n"
			send_user "/c/port $port\n"
			set srv_prt s
			append srv_prt $server_num
			append srv_prt "p1"
			send_user "        name \"$server_name $srv_prt\"\n"
			send_user "/c/snmp/cfg lnkt $port ena\n"
			set port [expr $port +1]
			send_user "/c/port [expr $port]\n"
			set srv_prt "s"
			append srv_prt $server_num
			append srv_prt "p2"
			send_user "        name \"$server_name $srv_prt\"\n"
			send_user "/c/snmp/cfg lnkt $port ena\n"
			set port [expr $port +1]
# Create Server B file
			set server_name $chassis_blade
			append server_name "B"
			send_user "\nThe following is the config for Chassis-Server $server_name\n"
			send_user   "_______________________________________________________\n"
			send_user "/c/port $port\n"
			set srv_prt "s"
			append srv_prt $server_num
			append srv_prt "iOL"
			send_user "        name \"$server_name $srv_prt\"\n"
			send_user "/c/snmp/cfg lnkt $port ena\n"
			set port [expr $port + 1]
			send_user "/c/port [expr $port]\n"
			set srv_prt "s"
			append srv_prt $server_num
			append srv_prt "p3"
			send_user "        name \"$server_name $srv_prt\"\n"
			send_user "/c/snmp/cfg lnkt $port ena\n"
			set port [expr $port +1]



# end of inner loop, bump element idx
		} else {
			set port [expr $port +2]
		}
		set element_idx [expr $element_idx +1]
	}




# end of outer loop, so read next chassis-server-blade recordc
	gets $handle chassis_row
	set end_of_file [eof $handle]
	set chassis_list [split $chassis_row ,]
}





# ok....end of script, so cleanup and say goodbye
send_user "\n"
send_user "Script completed, exiting.\n"
set current_date_time [timestamp -format "Date:Time=%Y%m%d:%X"]
send_user $current_date_time\n
send_user \n
send_user \n
sleep 1
log_file

#oh, um, Create MS-DOS version of run_log now, as it breaks logging if log file open
catch {exec cp $run_log $run_log_txt}
catch {exec unix2dos.exe $run_log_txt}

# be polite and wish the engineer luck with the run
send_user "Bye.....hope the run went well for you!\n"
Advertisements

Create a free website or blog at WordPress.com.