List Minions

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

 



Greetings, I did up a quick --list-minions option to func this
weekend. (patch attached) As mentioned on Friday I first set out to do
this as a func listminions command but saw that the only
infrastructure now is for running commands on minions, so I went with
--list-minions for first draft.

Talking to jbowes about adding a registry of local commands to the
FuncCommandLine to intercept anything that's a local command and run
it, but delegate anything unknown to the Client as we do now. Local
usage would be 'func localcommand [arg0] ... [argN]' as opposed to the
'func glob module method' remote syntax. Only small problem here is
the dual meaning of the first argument, if you had a hostname somehow
named the same as a local command you couldn't run against it. (rare
but hey, it could happen) I suppose I could also do 'func glob
listminons' where glob would almost always be * but you could also
wildcard and limit the output.

Thoughts?

1. func --list-minions
2. func listminions
3. func * listminions

Cheers,

D

-- 
Devan Goodwin <dgoodwin@xxxxxxxxxxxxxxxxxx>
http://dgoodwin.dangerouslyinc.com
From c86b5577008757bf49bddc47361c7188b7da3172 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.

---
 overlord/client.py |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/overlord/client.py b/overlord/client.py
index d6ccdc8..df2bfdd 100755
--- a/overlord/client.py
+++ b/overlord/client.py
@@ -63,15 +63,20 @@ class CommandAutomagic():
 class Client():
 
     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)
+        if config is None:
+            self.config  = read_config(CONFIG_FILE, CMConfig)       
+        else:
+            self.config  = config
+
         self.server_spec = server_spec
         self.port        = port
         self.verbose     = verbose
@@ -228,6 +233,7 @@ class FuncCommandLine():
         self.verbose      = 0
         self.server_spec  = None
         self.port         = DEFAULT_PORT
+        self.config       = read_config(CONFIG_FILE, CMConfig)
 
     # ----------------------------------------------- 
 
@@ -259,8 +265,10 @@ class FuncCommandLine():
 
         # parse options
         p = optparse.OptionParser()
-        p.add_option("-v","--verbose",dest="verbose",action="store_true")
-        p.add_option("-p","--port",dest="port",default=DEFAULT_PORT)
+        p.add_option("-v", "--verbose", dest="verbose", action="store_true")
+        p.add_option("-p", "--port", dest="port", default=DEFAULT_PORT)
+        p.add_option("--list-minions", dest="list_minions", 
+            action="store_true")
         (options, args) = p.parse_args(self.args)
 
         self.args    = args
@@ -278,6 +286,11 @@ class FuncCommandLine():
         # a good Klingon program does not have parameters
         # it has arguments, and it always wins them.
 
+                
+        if options.list_minions:
+            self.list_minions()
+
+
         if len(args) < 3:
             print self.usage()
             return -411
@@ -296,7 +309,7 @@ class FuncCommandLine():
         Runs the actual command.
         """
         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
@@ -304,10 +317,18 @@ class FuncCommandLine():
  
         return client.cli_return(results)
 
+    # ----------------------------------------------- 
+
+    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
     myname, argv = sys.argv[0], sys.argv[1:]
-- 
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