Commit 62551b28 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Move a bunch of old scripts and stuff to the attic.

parent 9d4b17d7
osstatus <node> - Returns current base and deltas of node.
osstatus -v <node> - Returns current base and deltas of node
with descriptions of deltas.
osstatus -vv <node> - Returns above + actual RPMs in deltas.
osnodestatus <node> - Like os status except that it asks the
node rather than the DB.
ossane <node> - Checks to see if the DB agrees with the OS.
osnode2db <node> - Sets the DB status to match the node status.
osdb2node <node> - Sets the node up to match the DB.
osset <node> <base> <deltas> - Sets the state of a node. <base> can
be "" to indicate no change. <deltas> is zero or more entries
that can be prefixed with + or - to indicate addition or
deletion. This only sets the DB.
oslist <what> - Lists from the DB. <what> can be "" which indicates
to list base images or it can be an image id which will
mean it should list the deltas available for that image.
oslist -v <what> - Like above but with file info.
General usage:
To configure a node N:
osset N ...
osdb2node N
ossane N
\ No newline at end of file
#!/usr/local/bin/tclsh
set sdir [file dirname [info script]]
if {[file dirname [info script]] == "."} {
load ../lib/sql.so
} else {
load [file dirname [file dirname [info script]]]/lib/sql.so
}
if {[llength $argv] != 1} {
puts stderr "Syntax: $argv0 <node#>"
exit 1
}
set node [lindex $argv 0]
set DB [sql connect]
sql selectdb $DB tbdb
if {[catch "exec ssh -n -l root 155.99.214.1$node cat /etc/ssh/ssh_host_key | $sdir/key7" hostkey]} {
puts stderr "ERROR: Could not get hostkey ($hostkey)"
exit 1
}
sql query $DB "select * from ssh_host_keys where node_id=\"tbpc$node\""
if {[sql fetchrow $DB] == ""} {
sql exec $DB "insert into ssh_host_keys values (\"tbpc$node\", '$hostkey')"
} else {
sql exec $DB "update ssh_host_keys set ssh_key='$hostkey' where node_id=\"tbpc$node\""
}
#!/usr/local/bin/tclsh
set sdir [file dirname [info script]]
if {[file dirname [info script]] == "."} {
load ../lib/sql.so
} else {
load [file dirname [file dirname [info script]]]/lib/sql.so
}
if {[llength $argv] != 1} {
puts stderr "Syntax: $argv0 <node#>"
exit 1
}
set node [lindex $argv 0]
set DB [sql connect]
sql selectdb $DB tbdb
sql query $DB "select * from ssh_host_keys where node_id=\"tbpc$node\""
set key [sql fetchrow $DB]
if {$key != ""} {
puts [exec echo [lindex $key 1] | $sdir/key8]
}
#!/usr/local/bin/expect
# Takes a number of parameters and installs and boots a disk
# image. Will install the new redhat image and boot it. Use "" for the
# partition to install an entire disk image. It can be run from any
# host.
# Example:
# instimage tbpc17 rh62_080100.ndz s2 linux
set RLT "\r\n"
set NetDisk "155.99.214.74:/q/testbed/images/netdisk"
set ImagePrefix "155.99.214.74:/q/testbed/images"
set TO 90
if {[llength $argv] != 4} {
puts stderr "Syntax: instimage <node> <image> <partition> <bootafter>"
exit 1
}
set node [lindex $argv 0]
set image [lindex $argv 1]
set partition [lindex $argv 2]
set bootafter [lindex $argv 3]
spawn ssh -t -a -x plastic tip $node
set timeout 15
expect {
"connected" {
set state "UNKNOWN"
}
timeout {
puts "Could not connect - Exiting"
exit 1
}
}
set timeout $TO
expect_after {
timeout {
if {[lindex [split $state _] 0] == "RECOVER"} {
puts "TIMEOUT on state $state - Exiting"
exit 2
} else {
puts "TIMEOUT on state $state - Recovering"
set state "RECOVER_$state"
set exitcode 1
}
}
}
proc doflush {} {
global spawn_id
expect -re {.*}
}
set exitcode 0
set goodcopy 0
while {$state != "EXIT"} {
puts ""
puts "\[STATE: $state\]"
switch $state {
"UNKNOWN" {
send "$RLT"
expect {
"login:" {
set state "LOGIN"
}
-re {# $} {
set state "SHELL"
}
"boot:" {
set state "LILO"
}
"NetBoot>" {
set state "NETBOOT"
}
"NetDisk>" {
set state "NETDISK"
}
}
}
"RECOVER_UNKNOWN" {
puts "Can not recover from state UNKNOWN - Exiting"
exit 2
}
"LOGIN" {
doflush
send "root$RLT"
expect {
"Password:" {
set state "PASSWORD"
}
}
}
"RECOVER_LOGIN" {
doflush
send "$RLT"
set state EXIT
}
"PASSWORD" {
send_user "Please enter Password: "
stty -echo
expect_user -re "(.*)\n"
stty echo
doflush
send "$expect_out(1,string)$RLT"
expect {
-re {login: $} {
puts "Login failed"
set state "LOGIN"
}
-re {# $} {
set state "SHELL"
}
}
}
"RECOVER_PASSWORD" {set state EXIT}
"SHELL" {
doflush
send "reboot$RLT"
expect {
"going down" {
set state "REBOOTING"
}
-re {# $} {
puts "Reboot failed - Exiting"
send "exit$RLT"
exit 1
}
}
}
"RECOVER_SHELL" {
send "exit$RLT"
set state EXIT
}
"REBOOTING" {
expect {
"boot:" {
set state "LILO"
}
"login:" {
puts "Missed LILO SHELL - Exiting"
exit 1
}
}
}
"RECOVER_REBOOTING" {set state EXIT}
"LILO" {
doflush
send "netboot$RLT"
expect {
"boot:" {
puts "Unable to netboot - Recovering"
set exitcode 1
set state "RECOVER_LILO"
}
"NetBoot>" {
set state "NETBOOT"
}
}
}
"NETBOOT" {
doflush
send "$NetDisk$RLT"
expect {
"NetDisk>" {
set state "NETDISK"
}
"NetBoot>" {
puts "Unable to boot NetDisk - Recovering"
set exitcode 1
set state "RECOVER_NETBOOT"
}
}
}
"NETDISK" {
doflush
send "$RLT"
set tries 0
set bootptries 0
set ok 0
expect {
"No bootp server found for any interfaces" {
if {$bootptries < 5} {
send "y$RLT"
incr bootptries
exp_continue
} else {
puts "Couldn't find bootp server."
set exitcode 1
send "n$RLT"
set state "RECOVER_NETDISK"
}
}
"Bad command line" {
puts "NetDisk didn't like our command line - $ImagePrefix/$image $partition - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
"Can't get the disk image" {
puts "Couldn't find disk image - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
"netdisk: Partition range:" {
puts "Copying - This will take a while."
set timeout 900
set ok 1
exp_continue
}
"netdisk: Success!" {
puts "Copy finished"
set timeout $TO
set state "RECOVER_NETBOOT"
set goodcopy 1
}
"NetDisk>" {
# XXX - dirty hack Need to fix
if {$tries <= 5} {
incr tries
doflush
send "$ImagePrefix/$image wd0 $partition$RLT"
exp_continue
} else {
puts "Unknown error - Recovering"
set exitcode 1
set state "RECOVER_NETDISK"
}
}
}
}
"RECOVER_NETDISK" {
doflush
send "$RLT"
set tries 0
expect {
"NetBoot>" {
set state "RECOVER_NETBOOT"
}
-re {NetDisk> $} {
if {$tries == 0} {
incr tries
doflush
send "exit$RLT"
exp_continue
} else {
puts "Exit didn't work - Exiting - Machine in strange state"
exit 2
}
}
}
}
"RECOVER_NETBOOT" {
doflush
send "$RLT"
set tries 0
expect {
"boot:" {
set state "RECOVER_LILO"
}
"NetBoot>" {
if {$tries == 0} {
incr tries
doflush
send "exit$RLT"
exp_continue
} else {
puts "Exit didn't work - Exiting - Machine in strange state"
exit 2
}
}
}
}
"RECOVER_LILO" {
puts "Booting $bootafter"
send "$bootafter$RLT"
set state "EXIT"
}
}
}
puts ""
if {$goodcopy == 1} {
puts "COPY: SUCCESS"
} else {
puts "COPY: FAIL"
}
if {$exitcode != 2} {
puts "RECOVERY: PROBABLE SUCCESS"
} else {
puts "RECOVERY: FAIL - Machine in unknown state."
}
exit $exitcode
\ No newline at end of file
#include <stdio.h>
int main()
{
char buf[1024*32];
int size;
int i;
size = fread(buf,1,1024*32,stdin);
for (i=0;i<size;++i) {
printf("%02x",buf[i]);
}
fflush(stdout);
return 0;
}
#include <stdio.h>
#define TONUM(x) (x >= '0' && x <= '9' ? x - '0' : 10 + (x - 'a'))
int main()
{
char buf[1024*32];
int size;
int i;
size = fread(buf,1,1024*32,stdin);
for (i=0;i<size;i+=2) {
printf("%c",TONUM(buf[i])*16+TONUM(buf[i+1]));
}
fflush(stdout);
return 0;
}
######################################################################
# oslib.tcl
#
# os <command> <args>
#
# init
# end
# querydb <node> - Returns a node_state (see below)
# querynode <node> - Returns a node_state (see below)
# listbases
# listdeltas <base> - Returns list of deltas
# querybase <base> - Returns {os, ver, extra, desc, path}
# querydelta <delta> - Returns {name, desc, path}
# db - Returns sql connection.
#
# node_state = {base {deltas}}
######################################################################
if {[file dirname [info script]] == "."} {
load ../lib/sql.so
} else {
load [file dirname [file dirname [info script]]]/lib/sql.so
}
namespace eval TB_OS {
namespace export os;
variable commands {
init end
querydb querynode
listbases listdeltas
querybase querydelta
db
}
variable DB {}
##################################################
# os <command> <args>
# Main interface into this library. See header for list of
# commands and args.
##################################################
proc os {command args} {
variable commands
variable DB
if {[lsearch $commands $command] == -1} {
error "$command not a valid os command."
}
if {$DB == {} && $command != "init"} {
error "Need to run 'os init' first."
}
return [eval "[namespace current]::$command $args"]
}
##################################################
# init
# This initalizes a connection to the database.
##################################################
proc init {} {
variable DB
set DB [sql connect]
sql selectdb $DB tbdb
}
##################################################
# end
# This disconnects from the database.
##################################################
proc end {} {
variable DB
sql disconnect $DB
set DB {}
}
##################################################
# querydb <node>
# Returns the base and deltas for <node>
##################################################
proc querydb {node} {
variable DB
sql query $DB "select image_id from SW_table where node_id=\"$node\""
set base [sql fetchrow $DB]
if {$base == {}} {return {}}
sql endquery $DB
sql query $DB "select fix_id from fixed_list where node_id=\"$node\""
set fix_ids {}
while {[set row [sql fetchrow $DB]] != {}} {
lappend fix_ids $row
}
sql endquery $DB
return [list $base $fix_ids]
}
##################################################
# querynode <node>
# Queries the node about the it's state and creates a node_state.
##################################################
proc querynode {node} {
variable DB
# calculate OS type
if {[catch "exec ssh -n -x $node uname -a" uname]} {
error "$uname"
}
sql query $DB "select image_id, magic from disk_images"
set os {}
while {[set row [sql fetchrow $DB]] != {}} {
set id [lindex $row 0]
set magic [lindex $row 1]
if {$magic != {}} {
if {[string first $magic $uname] != -1} {
set os $id
break
}
}
}
sql endquery $DB
# calculate deltas
if {[catch "exec ssh -n -x $node rpm -qa" result]} {
error "$result"
}
foreach pkg $result {
sql query $DB "select fix_id from fixes_table where fix_path like \"$pkg\""
while {[set row [sql fetchrow $DB]] != {}} {
lappend potential($row) $pkg
}
sql endquery $DB
}
set deltas {}
foreach delta [array names potential] {
sql query $DB "select fix_path from fixes table where fix_id = \"$delta\""
set pkgs [split [sql fetchrow $DB] ,]
if {[lsort $pkgs] == [lsort $potential($delta)]} {
lappend deltas $delta
}
}
return [list $os $deltas]
}
##################################################
# listbases
# Lists all the bases in the DB.
##################################################
proc listbases {} {
variable DB
sql query $DB "select image_id from disk_images"
set ret {}
while {[set row [sql fetchrow $DB]] != {}} {
lappend ret $row
}
sql endquery $DB
return $ret
}
##################################################
# listdeltas <base>
# Returns a list of all the deltas for a given base.
##################################################
proc listdeltas {base} {
variable DB
sql query $DB "select fix_id from fix_compat where image_id=\"$base\""
set ret {}
while {[set row [sql fetchrow $DB]] != {}} {
lappend ret $row
}
sql endquery $DB
return $ret
}
##################################################
# querybase <base>
# Returns {os, ver, extra, desc} for base.
##################################################
proc querybase {base} {
variable DB
sql query $DB "select OS, ver, extras, img_desc, img_path from disk_images where image_id=\"$base\""
set ret [sql fetchrow $DB]
sql endquery $DB
return $ret
}
##################################################
# querydelta <delta>
# Returns {name, desc, path}
##################################################
proc querydelta {delta} {
variable DB
sql query $DB "select fix_name, fix_desc, fix_path from fixes_table where fix_id=\"$delta\""
set ret [sql fetchrow $DB]
sql endquery $DB
return $ret
}
##################################################
# db
# Plain accesor function to the DB variable.
##################################################
proc db {} {
variable DB
return $DB
}
}
#!/usr/local/bin/tclsh
source [file dirname [info script]]/oslib.tcl
namespace import TB_OS::os
if {[llength $argv] > 2} {
puts stderr "Syntax: $argv0 [-v] \[<base>\]"
exit 1
}
set verbose 0
if {[lindex $argv 0] == "-v"} {
set verbose 1
set argv [lrange $argv 1 end]
}