#!/usr/bin/python

import optparse
import sys

def remoteCommand(command, options):
	print "Doing command %s options %s" % (command, options)
	return 0

def setHostState(args):
	parser = optparse.OptionParser()
	parser.set_usage("%s setHostState [options]" % sys.argv[0])
	parser.add_option("--host", help="Set the state of this host", action="store", type="string", dest="hostname")
	parser.add_option("--state", help="Change state to this value", action="store", type="string", dest="state")
	(options, arguments) = parser.parse_args(args)
	print options
	print arguments
	if options.hostname is None or options.state is None:
		print "A mandatory option is missing\n"
		parser.print_help()
		sys.exit(-1)

	remoteCommand("shs", options)
	return 0

def setHostNotes(args):
	parser = optparse.OptionParser()
	parser.set_usage("%s setHostNotes [options]" % sys.argv[0])
	parser.add_option("--host", help="Annotate this host with the note (mandatory)", action="store", type="string", dest="hostname")
	parser.add_option("--notes", help="Annotate the host with this note (mandatory)", action="store", type="string", dest="notes")
	(options, arguments) = parser.parse_args(args)
	print options
	print arguments
	if options.hostname is None or options.notes is None:
		print "A mandatory option is missing\n"
		parser.print_help()
		sys.exit(-1)

	remoteCommand("shn", options)
	return 0

cmdsdesc = (
("setHostState", "Sets host state"),
("setHostNotes", "Annotates a host"),
)

cmds = {
'setHostState': setHostState,
'setHostNotes': setHostNotes,
}

def main():
	if len(sys.argv) < 2:
		print "too few args"
		sys.exit(-1)

	scriptname = sys.argv[0]
	cmd = sys.argv[1]
	args = sys.argv[2:]

	print "scriptname: %s" % (scriptname)
	print "cmd: %s" % (cmd)

	# allow use of lower case for commands
	lccmddict = dict((foo.lower(), foo) for foo in cmds.keys())

	if cmd.lower() not in lccmddict:
		print "not a valid command"
		sys.exit(-1)

	handler = cmds[lccmddict[cmd]]

	rv = handler(args)
	return rv


if __name__ == "__main__":
	rv = main()
	sys.exit(rv)

@@ -695,32 +695,37 @@
 %09sys.exit(-1)%0A%0A%09
+rv = 
 remoteCommand(%22s
@@ -1342,16 +1342,21 @@
 t(-1)%0A%0A%09
+rv = 
 remoteCo
@@ -1388,16 +1388,619 @@
 turn 0%0A%0A
+def help(args):%0A%09print %22Available commands:%22%0A%09for (command, desc) in cmdsdesc:%0A%09%09print %22%25s%5Ct%5Ct%25s%22 %25 (command, desc)%0A%09print %22See %25s %3Ccommand%3E -h for help on these commands.%22 %25 sys.argv%5B0%5D %0A%09return 0%0A%0A%22%22%22 Possible functions:%0Adescription = (%0A('addHost', 'Adds a new host to Tashi'),%0A('delHost', 'Removes a host from Tashi'),%0A('addUser', 'Adds a user to Tashi'),%0A('delUser', 'Removes a user from Tashi'),%0A('addNet', 'Adds a network to Tashi'),%0A('delNet', 'Removes a network from Tashi'),%0A('setHostState', 'Set the state of a host, eg. Normal or Drained'),%0A('setHostNotes', 'Annotate a host record'),%0A)%0A%22%22%22%0A%0A
 cmdsdesc
@@ -2079,16 +2079,60 @@
 host%22),%0A
+(%22help%22, %22Get list of available commands%22),%0A
 )%0A%0Acmds 
@@ -2195,16 +2195,30 @@
 tNotes,%0A
+'help': help,%0A
 %7D%0A%0Adef m
@@ -2224,16 +2224,43 @@
 main():%0A
+%09scriptname = sys.argv%5B0%5D%0A%0A
 %09if len(
@@ -2287,63 +2287,71 @@
 nt %22
-too few args%22%0A%09%09sys.exit(-1)%0A%0A%09scriptname = sys.argv%5B0%5D
+Syntax: %25s %3Ccommand%3E%22 %25 scriptname%0A%09%09help(None)%0A%09%09sys.exit(-1)%0A
 %0A%09cm
@@ -2460,26 +2460,15 @@
 %0A%09# 
-allow use of lower
+flatten
  cas

build out admin client