From 2b76bf5ac8877b5bb82726126a7690873395f4fd Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 9 Mar 2012 17:00:51 -0500 Subject: [PATCH] add cert to list of valid commands --- sfa/clientbin/sfaadmin.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/sfa/clientbin/sfaadmin.py b/sfa/clientbin/sfaadmin.py index 276943b6..e722e6b6 100755 --- a/sfa/clientbin/sfaadmin.py +++ b/sfa/clientbin/sfaadmin.py @@ -238,24 +238,35 @@ class SliceManagerCommands(AggregateCommands): self.api= Generic.the_flavour().make_api(interface='slicemgr') -CATEGORIES = {'registry': RegistryCommands, +CATEGORIES = {'cert': CertificateCommands, + 'registry': RegistryCommands, 'aggregate': AggregateCommands, 'slicemgr': SliceManagerCommands} +def category_usage(): + print "Available categories:" + for k in CATEGORIES: + print "\t%s" % k def main(): argv = copy.deepcopy(sys.argv) script_name = argv.pop(0) + # ensure category is specified if len(argv) < 1: print script_name + " category action []" - print "Available categories:" - for k in CATEGORIES: - print "\t%s" % k + category_usage() sys.exit(2) + # ensure category is valid category = argv.pop(0) usage = "%%prog %s action [options]" % (category) parser = OptionParser(usage=usage) - command_class = CATEGORIES[category] + command_class = CATEGORIES.get(category, None) + if not command_class: + print "no such category %s " % category + category_usage() + sys.exit(2) + + # ensure command is valid command_instance = command_class() actions = command_instance._get_commands() if len(argv) < 1: @@ -272,6 +283,7 @@ def main(): action = argv.pop(0) command = getattr(command_instance, action) + # ensure options are valid options = getattr(command, 'options', []) usage = "%%prog %s %s [options]" % (category, action) parser = OptionParser(usage=usage) @@ -285,6 +297,7 @@ def main(): if v is None: del cmd_kwds[k] + # execute commadn try: command(*cmd_args, **cmd_kwds) sys.exit(0) -- 2.43.0