[Et-mgmt-commits-list] [SCM] virt-factory branch, master now at v0.0.3-287-gd19eb9d

Adrian Likins alikins at redhat.com
Thu Aug 30 22:56:45 UTC 2007


Hello,

This is an automated email from the git hooks/update script, it was
generated because a ref change was pushed to the repository.

Updating branch, master,
       via  d19eb9df77f948a39b726a54a7ccb845a470d239 (commit)
      from  35f006460e04196a717d80859dfbb452b75c6cdd (commit)

- Log -----------------------------------------------------------------
commit d19eb9df77f948a39b726a54a7ccb845a470d239
Author: Adrian Likins <alikins at grimlock.devel.redhat.com>
Date:   Thu Aug 30 18:47:41 2007 -0400

    change command_modules to "register" themselves and the mode they correspond to
    
    add help strings for each more
    
    change global --help and/or help mode to show all the help strings
-----------------------------------------------------------------------

Diffstat:
 ampm/client/ampm_cli.py            |   64 +++++++++++++++++++++++------------
 ampm/command_modules/add.py        |   16 ++++++---
 ampm/command_modules/create.py     |   14 ++++++--
 ampm/command_modules/delete.py     |   15 +++++++--
 ampm/command_modules/guest_cmds.py |    2 +-
 ampm/command_modules/list.py       |    8 +++--
 ampm/command_modules/pause.py      |    3 ++
 ampm/command_modules/query.py      |   15 ++++++---
 ampm/command_modules/shutdown.py   |    4 +-
 ampm/command_modules/start.py      |    5 +--
 ampm/command_modules/unpause.py    |    5 +--
 11 files changed, 99 insertions(+), 52 deletions(-)

diff --git a/ampm/client/ampm_cli.py b/ampm/client/ampm_cli.py
index 2ed8b9e..b22a764 100644
--- a/ampm/client/ampm_cli.py
+++ b/ampm/client/ampm_cli.py
@@ -44,7 +44,7 @@ from command_modules import start
 from command_modules import shutdown
 
 
-def print_help(valid_modes):
+def print_help(mode_dict):
     print "global options"
     print "\t --help, -h"
     print "\t --verbose, -v"
@@ -52,7 +52,11 @@ def print_help(valid_modes):
     print "\t --username <username>"
     print "\t --passowrd <password>"
     print "valid modes include:"
-    print "\t %s" % (string.join(valid_modes, ', '))
+    print "\t %s" % (string.join(mode_dict.keys(), ', '))
+
+    for mode in mode_dict.keys():
+        print "%s:" % mode
+        mode_dict[mode](["--help"], api=None)
 
     
 def main():
@@ -61,6 +65,16 @@ def main():
                    "create", "delete", "add",
                    "pause", "unpause", "start",
                    "shutdown"]
+
+    mode_modules = [list, query, create,
+                    delete, add, pause,
+                    unpause, start, shutdown]
+
+    mode_dict = {}
+    for mode in mode_modules:
+        mode.register(mode_dict)
+
+    
     username = cfg.get("user", "username")
     password = cfg.get("user", "password")
     server = cfg.get("server", "url")
@@ -81,7 +95,7 @@ def main():
 
     for (opt, val) in opts:
         if opt in ["-h", "--help"]:
-            print_help(valid_modes)
+            print_help(mode_dict)
             sys.exit()
         if opt in ["-v", "--verbose"]:
             verbose = 1
@@ -100,9 +114,12 @@ def main():
         print_help()
         sys.exit()
 
+    if mode == "help":
+        print_help( mode_dict)
+        sys.exit()
 
     if mode not in valid_modes:
-        print_help(valid_modes)
+        print_help(mode_dict)
         sys.exit()
 
     modeargs = args[args.index(mode)+1:]
@@ -112,33 +129,36 @@ def main():
                       username=username,
                       password=password)
 
+    # invoke the mode class 
+    mode_dict[mode](modeargs, api=api)
+
     
-    if mode == "list":
-        list.run(modeargs, api=api)
+  #  if mode == "list":
+  #      list.run(modeargs, api=api)
 
-    if mode == "query":
-        query.run(modeargs, api=api)
+#    if mode == "query":
+#        query.run(modeargs, api=api)
 
-    if mode == "create":
-        create.run(modeargs, api=api)
+#    if mode == "create":
+#        create.run(modeargs, api=api)
 
-    if mode == "delete":
-        delete.run(modeargs, api=api)
+#    if mode == "delete":
+#        delete.run(modeargs, api=api)
 
-    if mode == "add":
-        add.run(modeargs, api=api)
+#    if mode == "add":
+#        add.run(modeargs, api=api)
 
-    if mode == "pause":
-        pause.run(modeargs, api=api)
+#    if mode == "pause":
+#        pause.run(modeargs, api=api)
 
-    if mode == "unpause":
-        unpause.run(modeargs, api=api)
+#    if mode == "unpause":
+#        unpause.run(modeargs, api=api)
 
-    if mode == "start":
-        start.run(modeargs, api=api)
+#    if mode == "start":
+#        start.run(modeargs, api=api)
 
-    if mode == "shutdown":
-        shutdown.run(modeargs, api=api)
+#    if mode == "shutdown":
+#        shutdown.run(modeargs, api=api)
         
 if __name__ == "__main__":
     main()
diff --git a/ampm/command_modules/add.py b/ampm/command_modules/add.py
index 053cd6f..0554a37 100644
--- a/ampm/command_modules/add.py
+++ b/ampm/command_modules/add.py
@@ -12,15 +12,19 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Add(args,api)
-
+def register(mode_dict):
+    mode_dict[Add.mode_string] = Add
 
 class Add(command_class.Command):
+    mode_string = "add"
     def print_help(self):
-        print "--username <username> --password <password> --first <first_name"
-        print "     --middle <middle_name> --last <last_name> --email <email address>"
-        print "     --description <desription>"
+        print "\t --username <username>"
+        print "\t --password <password>"
+        print "\t --first <first_name"
+        print "\t --middle <middle_name>"
+        print "\t --last <last_name>"
+        print "\t --email <email address>"
+        print "\t --description <desription>"
 
     def _parse_args(self, args):
 
diff --git a/ampm/command_modules/create.py b/ampm/command_modules/create.py
index 5f563cb..d341a4b 100644
--- a/ampm/command_modules/create.py
+++ b/ampm/command_modules/create.py
@@ -11,11 +11,17 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Create(args, api)
-
+def register(mode_dict):
+    mode_dict[Create.mode_string] = Create
 
 class Create(command_class.Command):
+    mode_string = "create"
+    def print_help(self):
+        print "\t--help, -h"
+        print "\t--verbose, -v"
+        print "\t--host <hostname>           the  host to run the guest on"
+        print "\t--profile <profilename>     the profile to create the guest with"
+    
     def _parse_args(self, args):
 
         hostname = None
@@ -35,7 +41,7 @@ class Create(command_class.Command):
 
         for (opt, val) in opts:
             if opt in ["-h", "--help"]:
-                print_help()
+                self.print_help()
             if opt in ["-v", "--verbose"]:
                 self.verbose = self.verbose + 1
             if opt in ["--host"]:
diff --git a/ampm/command_modules/delete.py b/ampm/command_modules/delete.py
index b94edc6..6aa9e72 100644
--- a/ampm/command_modules/delete.py
+++ b/ampm/command_modules/delete.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import command_class
+import guest_cmds
 
 import getopt
 import os
@@ -10,11 +11,19 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Delete(args, api)
+def register(mode_dict):
+    mode_dict[Delete.mode_string] = Delete
 
 
 class Delete(command_class.Command):
+    mode_string = "delete"
+    def print_help(self):
+        print "\t --help, -h"
+        print "\t --verbose, -v"
+        print "\t --task_id <task_id>            delete a task from the task queue"
+#        print "\t --profile <profile>            delete a profile"
+        print "\t --user_id <user_id>            delete a user"
+    
     def _parse_args(self, args):
 
         task_id = None
@@ -35,7 +44,7 @@ class Delete(command_class.Command):
 
         for (opt, val) in opts:
             if opt in ["-h", "--help"]:
-                print_help()
+                self.print_help()
             if opt in ["-v", "--verbose"]:
                 self.verbose = self.verbose + 1
             if opt in ["--task_id"]:
diff --git a/ampm/command_modules/guest_cmds.py b/ampm/command_modules/guest_cmds.py
index e2d6ae3..2a805a8 100644
--- a/ampm/command_modules/guest_cmds.py
+++ b/ampm/command_modules/guest_cmds.py
@@ -13,7 +13,7 @@ from client import ampmlib
 
 class GuestCommand(command_class.Command):
     def print_help(self):
-        print "ampm %s guest_name [--guest_id] <guest_id>" % self.mode_string
+        print "\tampm %s guest_name [--guest_id] <guest_id>" % self.mode_string
 
     def check_missing_args(self):
         if self.guests == [] and self.guests_ids == []:
diff --git a/ampm/command_modules/list.py b/ampm/command_modules/list.py
index 413e49e..cb8a9e1 100644
--- a/ampm/command_modules/list.py
+++ b/ampm/command_modules/list.py
@@ -12,14 +12,16 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = List(args,api)
 
+def register(mode_dict):
+    mode_dict[List.mode_string] = List
+    
 
 
 class List(command_class.Command):
+    mode_string = "list"
     def print_help(self):
-        print "valid modes are hosts, guests, status, profiles, tasks, users"
+        print "\tvalid sub modes are hosts, guests, status, profiles, tasks, users"
 
     def _parse_args(self, args):
 
diff --git a/ampm/command_modules/pause.py b/ampm/command_modules/pause.py
index b5e3542..23c6151 100644
--- a/ampm/command_modules/pause.py
+++ b/ampm/command_modules/pause.py
@@ -18,6 +18,9 @@ def run(args, api):
     command = Pause(args,api)
 
 
+def register(modes_dict):
+    modes_dict[Pause.mode_string] = Pause
+
 class Pause(guest_cmds.GuestCommand):
     mode_string = "pause"
     def _parse_args(self, args):
diff --git a/ampm/command_modules/query.py b/ampm/command_modules/query.py
index 76be54f..413a4f1 100644
--- a/ampm/command_modules/query.py
+++ b/ampm/command_modules/query.py
@@ -11,11 +11,17 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Query(args, api)
-
+def register(mode_dict):
+    mode_dict[Query.mode_string] = Query
 
 class Query(command_class.Command):
+    mode_string = "query"
+    def print_help(self):
+        print "\t--help, -h"
+        print "\t--verbose, -v"
+        print "\t--containter <container>     which container a deployment is running on"
+        print "\t--profile <profile>          which profile a deployement is running on"
+    
     def _parse_args(self, args):
 
         try:
@@ -32,7 +38,7 @@ class Query(command_class.Command):
 
         for (opt, val) in opts:
             if opt in ["-h", "--help"]:
-                print_help()
+                self.print_help()
             if opt in ["-v", "--verbose"]:
                 self.verbose = self.verbose + 1
             if opt in ["--container"]:
@@ -47,7 +53,6 @@ class Query(command_class.Command):
 
 
     def query_container(self, deployment=None):
-        print "bloop"
         if deployment is None:
             # we could try to figure out the local deployment name and use
             # that here FIXME
diff --git a/ampm/command_modules/shutdown.py b/ampm/command_modules/shutdown.py
index bab43a0..230da5b 100644
--- a/ampm/command_modules/shutdown.py
+++ b/ampm/command_modules/shutdown.py
@@ -14,8 +14,8 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Shutdown(args,api)
+def register(mode_dict):
+    mode_dict[Shutdown.mode_string] = Shutdown
 
 
 class Shutdown(guest_cmds.GuestCommand):
diff --git a/ampm/command_modules/start.py b/ampm/command_modules/start.py
index 82a99d6..e776c7e 100644
--- a/ampm/command_modules/start.py
+++ b/ampm/command_modules/start.py
@@ -14,9 +14,8 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Start(args,api)
-
+def register(mode_dict):
+    mode_dict[Start.mode_string] = Start
 
 class Start(guest_cmds.GuestCommand):
     mode_string = "start"
diff --git a/ampm/command_modules/unpause.py b/ampm/command_modules/unpause.py
index 0776803..cbd4ab8 100644
--- a/ampm/command_modules/unpause.py
+++ b/ampm/command_modules/unpause.py
@@ -14,9 +14,8 @@ from rhpl.translate import _, N_, textdomain, utf8
 
 from client import ampmlib
 
-def run(args, api):
-    command = Unpause(args,api)
-
+def register(mode_dict):
+    mode_dict[Unpause.mode_string] = Unpause
 
 class Unpause(guest_cmds.GuestCommand):
     mode_string = "unpause"

hooks/update
---
Git Source Code Management System
hooks/update refs/heads/master \
  35f006460e04196a717d80859dfbb452b75c6cdd \
  d19eb9df77f948a39b726a54a7ccb845a470d239




More information about the Et-mgmt-commits-list mailing list