Re: List Minions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Reapplied patch for --list-minions after alikins most recent mods.
Patches attached & feedback welcome.

Cheers.

- -- 
Devan Goodwin <dgoodwin@xxxxxxxxxxxxxxxxxx>
  http://dgoodwin.dangerouslyinc.com
  GPG Key: F57D9B2E @ pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHArnoAyHWaPV9my4RAvusAKDT2qAsffK9AFo+83Ycg67VCIWkMACfXiQ6
D9PrQQSygQXpILJxRcA0m7g=
=xnDM
-----END PGP SIGNATURE-----
From 5e3e2903940d8e7693dda7c50f41f4f2ca5c5e5e Mon Sep 17 00:00:00 2001
From: Devan Goodwin <dgoodwin@xxxxxxxxxxxxxxxxxx>
Date: Sun, 30 Sep 2007 13:27:09 -0300
Subject: [PATCH] Added func --list-minions option.

---
 func/config.py      |    2 ++
 overlord/client.py  |   40 +++++++++++++++++++++++++++++-----------
 overlord/command.py |    5 +++++
 3 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/func/config.py b/func/config.py
index f174cd7..6dbdc61 100644
--- a/func/config.py
+++ b/func/config.py
@@ -26,6 +26,8 @@ from ConfigParser import NoSectionError, NoOptionError, ConfigParser
 from ConfigParser import ParsingError
 import exceptions
 
+CONFIG_FILE = "/etc/func/certmaster.conf"
+
 class ConfigError(exceptions.Exception):
     def __init__(self, value=None):
         exceptions.Exception.__init__(self)
diff --git a/overlord/client.py b/overlord/client.py
index 6ab75eb..04f7ed8 100755
--- a/overlord/client.py
+++ b/overlord/client.py
@@ -21,7 +21,7 @@ import glob
 import pprint
 
 from func.commonconfig import CMConfig
-from func.config import read_config
+from func.config import read_config, CONFIG_FILE
 import sslclient
 
 import command
@@ -31,7 +31,6 @@ import command
 # TO DO: some of this may want to come from config later
 
 DEFAULT_PORT = 51234
-CONFIG_FILE = "/etc/func/certmaster.conf"
 FUNC_USAGE = "Usage: %s [ --help ] [ --verbose ] target.example.org module method arg1 [...]"
 
 # ===================================
@@ -65,15 +64,19 @@ class CommandAutomagic(object):
 class Client(object):
 
     def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False,
-        verbose=False, noglobs=False):
+        verbose=False, noglobs=False, config=None):
         """
         Constructor.
         @server_spec -- something like "*.example.org" or "foosball"
         @port -- is the port where all funcd processes should be contacted
         @verbose -- whether to print unneccessary things
         @noglobs -- specifies server_spec is not a glob, and run should return single values
+        @config -- optional config object
         """
-        self.config      = read_config(CONFIG_FILE, CMConfig)
+        self.config  = config
+        if config is None:
+            self.config  = read_config(CONFIG_FILE, CMConfig)       
+
         self.server_spec = server_spec
         self.port        = port
         self.verbose     = verbose
@@ -223,8 +226,10 @@ class Call(command.Command):
     name = "call"
     useage = "call nodule method name arg1 arg2..."
     def addOptions(self):
-        self.parser.add_option("-v","--verbose",dest="verbose",action="store_true")
-        self.parser.add_option("-p","--port",dest="port",default=DEFAULT_PORT)
+        self.parser.add_option("-v", "--verbose", dest="verbose", 
+            action="store_true")
+        self.parser.add_option("-p", "--port", dest="port",
+            default=DEFAULT_PORT)
 
     def handleOptions(self, options):
         self.options = options
@@ -245,7 +250,7 @@ class Call(command.Command):
         self.method_args = args[3:]
 
         client = Client(self.server_spec,port=self.port,interactive=True,
-                        verbose=self.verbose)
+            verbose=self.verbose, config=self.config)
         results = client.run(self.module, self.method, self.method_args)
     
         # TO DO: add multiplexer support
@@ -253,7 +258,6 @@ class Call(command.Command):
 
         return client.cli_return(results)
 
-
 class FuncCommandLine(command.Command):
     name = "client"
     useage = "func is the commandline interface to a func minion"
@@ -269,14 +273,28 @@ class FuncCommandLine(command.Command):
     
     def addOptions(self):
         self.parser.add_option('', '--version', action="store_true",
-                               help="show version information")
+            help="show version information")
+        self.parser.add_option("--list-minions", dest="list_minions", 
+            action="store_true", help="list all available minions")
 
     def handleOptions(self, options):
         if options.version:
             #FIXME
             print "version is NOT IMPLEMENTED YET"
-
-
+        if options.list_minions:
+            self.list_minions()
+
+    # ----------------------------------------------- 
+
+    def list_minions(self):
+        print "Minions:"
+        gloob = "%s/%s.cert" % (self.config.certroot, "*")
+        certs = glob.glob(gloob)
+        for cert in certs:
+            host = cert.replace(self.config.certroot, "")[1:-5]
+            print "   %s" % host
+       
+# ===================================================================
 
 if __name__ == "__main__":
     # this is what /usr/bin/func will run
diff --git a/overlord/command.py b/overlord/command.py
index d2af494..54da1ec 100644
--- a/overlord/command.py
+++ b/overlord/command.py
@@ -14,6 +14,9 @@ Command class.
 import optparse
 import sys
 
+from func.config import read_config, CONFIG_FILE
+from func.commonconfig import CMConfig
+
 class CommandHelpFormatter(optparse.IndentedHelpFormatter):
     """
     I format the description as usual, but add an overview of commands
@@ -112,6 +115,8 @@ class Command:
         self.stderr = stderr
         self.parentCommand = parentCommand
 
+        self.config = read_config(CONFIG_FILE, CMConfig)
+
         # create subcommands if we have them
         self.subCommands = {}
         self.aliasedSubCommands = {}
-- 
1.5.2.4

From 8766472f6339d66df484300deac6a2ddb2628131 Mon Sep 17 00:00:00 2001
From: Devan Goodwin <dgoodwin@xxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Oct 2007 18:34:02 -0300
Subject: [PATCH] Exit program after listing minions.

---
 overlord/client.py |   17 +----------------
 1 files changed, 1 insertions(+), 16 deletions(-)

diff --git a/overlord/client.py b/overlord/client.py
index 04f7ed8..eb70767 100755
--- a/overlord/client.py
+++ b/overlord/client.py
@@ -283,8 +283,7 @@ class FuncCommandLine(command.Command):
             print "version is NOT IMPLEMENTED YET"
         if options.list_minions:
             self.list_minions()
-
-    # ----------------------------------------------- 
+            sys.exit(0) # stop execution
 
     def list_minions(self):
         print "Minions:"
@@ -294,17 +293,3 @@ class FuncCommandLine(command.Command):
             host = cert.replace(self.config.certroot, "")[1:-5]
             print "   %s" % host
        
-# ===================================================================
-
-if __name__ == "__main__":
-    # this is what /usr/bin/func will run
-    myname, argv = sys.argv[0], sys.argv[1:]
-    cli = FuncCommandLine()
-    rc = cli.do()
-    sys.exit(rc)
-#    cli = FuncCommandLine(myname,argv)
-
-#    rc = cli.run()
-    sys.exit(rc)
-
-
-- 
1.5.2.4


[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux