Commit b97d7d21 authored by Christopher Alfeld's avatar Christopher Alfeld

Initial scans of all.

parent e5e0ef4b
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.
General usage:
To configure a node N:
osset N ...
osdb2node N
ossane N
\ No newline at end of file
######################################################################
# oslib.tcl
#
# os <command> <args>
#
# init
# end
# querydb <node> - Returns a node_state (see below)
# querynode <node> - Returns a node_state (see below)
# listbases
# listsdeltas <base> - Returns list of deltas
# querybase <base> - Returns {os, ver, extra, desc}
# querydelta <delta> - Returns {name, desc, path}
#
# 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
querybase querydelta
}
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} {
# XXX - This is non-trivial. Might use the roatan library.
}
##################################################
# 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 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
}
}
#!/usr/local/bin/tclsh
source [file dirname [info script]]/oslib.tcl
namespace import TB_OS::os
if {[llength $argv] == 0 || [llength $argv] > 2} {
puts stderr "Syntax: $arg0 \[-v\[v\]\] <node>"
exit 1
}
os init
set verbose 0
if {[llength $argv] == 2} {
switch -- [lindex $argv 0] {
"-v" {set verbose 1}
"-vv" {set verbose 2}
default {
puts stderr "Unrecognized option: [lindex $argv 0]"
exit 1
}
}
set node [lindex $argv 1]
} else {
set node [lindex $argv 0]
}
set state [os querydb $node]
set bstate [os querybase [lindex $state 0]]
puts "base: [lindex $bstate 3]"
if {$verbose > 0} {
puts "os: [lindex $bstate 0]"
puts "ver: [lindex $bstate 1]"
puts "extras: [lindex $bstate 2]"
puts ""
}
puts "deltas: [lindex $state 1]"
if {$verbose > 0} {
foreach delta [lindex $state 1] {
set info [os querydelta $delta]
puts ""
puts "delta: $delta"
puts "name: [lindex $info 0]"
puts "desc: [lindex $info 1]"
if {$verbose > 1} {
puts "rpms: [lindex $info 2]"
}
}
}
os end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment