3 commits - func/minion func/overlord scripts/func-command scripts/func-down-hosts

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

 



 func/minion/modules/users.py |   20 +++++++++++---
 func/overlord/scripts.py     |   10 +++++--
 scripts/func-command         |   58 +++++++++++++++++++++++--------------------
 scripts/func-down-hosts      |   45 +++++++++++++++++----------------
 4 files changed, 77 insertions(+), 56 deletions(-)

New commits:
commit 271ea0a75157fe814efdc2636ad0ef338e345c9b
Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx>
Date:   Fri Oct 22 16:38:34 2010 -0400

    fix users for python 2.4  and un-obsfuscate this code

diff --git a/func/minion/modules/users.py b/func/minion/modules/users.py
index 4dc1bf1..bad39ff 100644
--- a/func/minion/modules/users.py
+++ b/func/minion/modules/users.py
@@ -67,9 +67,17 @@ class UsersModule(func_module.FuncModule):
             if elem == '':
                 pass
             else:
-                cmd = cmd + " '" + str(elem.replace("'","") if (type(elem) == str) else elem) + "'"
-#    print "\nCmd: [%s]"%cmd
-        return False if system(cmd+" 2>/dev/null 1>/dev/null") else True
+                if type(elem) == str:
+                    ret = str(elem.replace("'", ""))
+                else:
+                    ret = str(elem)
+                cmd = cmd + " '" + ret + "'"
+
+        if system(cmd+" 2>/dev/null 1>/dev/null"):
+            return False
+        else:
+            return True
+            
 
     def __plural(self,f):
         return (lambda xs: map(f,xs))
@@ -380,7 +388,8 @@ class UsersModule(func_module.FuncModule):
         """Lists all UIDs on the target system(s)."""
         uids = []
         for user in pwd.getpwall():
-            uids.append(user[2] if user[2] < 4294967294 else True)
+            if user[2] < 4294967294:
+                uids.append(user[2])
         return uids
 
     def uids_list(self):
@@ -402,7 +411,8 @@ class UsersModule(func_module.FuncModule):
         """Lists all GIDs on the target system(s)."""
         gids = []
         for group in grp.getgrall():
-            gids.append(group[2] if group[2] < 4294967294 else True)
+            if group[2] < 4294967294:
+                gids.append(group[2])
         return gids
 
     def gids_list(self):


commit 41786d392d25d0e64d1b1df8601f98d02a214e75
Merge: 4648e78... 786c5c9...
Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx>
Date:   Fri Oct 22 12:09:01 2010 -0400

    Merge branch 'master' of ssh://git.fedorahosted.org/git/func
    fix merge
    
    * 'master' of ssh://git.fedorahosted.org/git/func:
      modify distutils file for new commands
      Huge whitespace cleanup which includes;
    
    Conflicts:
    	func/overlord/scripts.py

diff --cc func/overlord/scripts.py
index 27ade78,7f2e0f2..4c84dd2
--- a/func/overlord/scripts.py
+++ b/func/overlord/scripts.py
@@@ -39,11 -39,6 +39,10 @@@ def handle_base_func_options(parser, op
              if hn.startswith('#'):
                  continue
              hn = hn.replace('\n', '')
-             opts.host.append(hn)    
+             opts.host.append(hn)
  
      return opts
 +
++
 +def errorprint(msg)
 +    print >> sys.stderr, msg
-     
-     


commit 4648e78eb85a889ee9965b52c45efdc6674be02b
Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx>
Date:   Fri Oct 22 12:05:59 2010 -0400

    convert func-command func-down-hosts to using the common parser

diff --git a/func/overlord/scripts.py b/func/overlord/scripts.py
index 57a6255..27ade78 100644
--- a/func/overlord/scripts.py
+++ b/func/overlord/scripts.py
@@ -9,7 +9,7 @@ from optparse import OptionParser
 import sys
 
 
-def base_func_parser(opthosts=True, outputpath=True):
+def base_func_parser(opthosts=True, outputpath=True, forkdef=40, timeoutdef=300):
     parser = OptionParser()
     if opthosts:
         parser.add_option('--host', default=[], action='append',
@@ -17,9 +17,9 @@ def base_func_parser(opthosts=True, outputpath=True):
         parser.add_option('--hosts-from-file', default=None, dest="hostfile",
                    help="read list of hosts from this file, if '-' read from stdin")
 
-    parser.add_option('--timeout', default=300, type='int',
+    parser.add_option('--timeout', default=timeoutdef, type='int',
                help='set the wait timeout for func commands')
-    parser.add_option('--forks', default=40, type='int',
+    parser.add_option('--forks', default=forkdef, type='int',
                help='set the number of forks to start up')
     if outputpath:
         parser.add_option('--outputpath', default='/var/lib/func/data/', dest="outputpath",
@@ -43,3 +43,7 @@ def handle_base_func_options(parser, opts):
 
     return opts
 
+def errorprint(msg)
+    print >> sys.stderr, msg
+    
+    
diff --git a/scripts/func-command b/scripts/func-command
index e6b88f9..5e0f43d 100755
--- a/scripts/func-command
+++ b/scripts/func-command
@@ -5,39 +5,45 @@
 
 import sys
 import func.overlord.client
-from func.overlord.scripts import base_func_parser, handle_base_func_options
+from func.overlord.scripts import base_func_parser, handle_base_func_options, errorprint
 from func.utils import is_error
 
-parser = base_func_parser(outputpath=False)
-opts, args, parser = parse_args(sys.argv[1:])
-opts = handle_base_func_options(parser, opts)
 
-if len(args) < 1:
-    print parser.format_help()
-    sys.exit(1)
+def main(args):
+    parser = base_func_parser(outputpath=False)
+    opts, args, parser = parse_args(args)
+    opts = handle_base_func_options(parser, opts)
 
-mycmd = ' '.join(args)
+    if len(args) < 1:
+        errorprint(parser.format_help())
+        return 1
 
-hosts ='*'
-if opts.host:
-    hosts = ';'.join(opts.host)
+    mycmd = ' '.join(args)
 
-fc = func.overlord.client.Client(hosts, timeout=opts.timeout, nforks=opts.forks)
+    hosts ='*'
+    if opts.host:
+        hosts = ';'.join(opts.host)
 
-print mycmd
-results = fc.command.run(mycmd)
-for (hn, output) in results.items():
-    if is_error(output):
-        msg = 'Error: %s: ' % hn
-        for item in output[1:3]:
-            if type(item) == type(''):
-                msg += ' %s' % item
-        print >> sys.stderr, msg 
-        continue
+    fc = func.overlord.client.Client(hosts, timeout=opts.timeout, nforks=opts.forks)
 
-    # FIXME - maybe for commands don't do it one line with hostname first
+    print mycmd
+    results = fc.command.run(mycmd)
+    for (hn, output) in results.items():
+        if is_error(output):
+            msg = 'Error: %s: ' % hn
+            for item in output[1:3]:
+                if type(item) == type(''):
+                    msg += ' %s' % item
+            errorprint(msg)
+            continue
 
-    print '%s' % hn
-    print output[1]
-    print ''
+        # FIXME - maybe for commands don't do it one line with hostname first
+
+        print '%s' % hn
+        print output[1]
+        print ''
+    
+    return 0
     
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
diff --git a/scripts/func-down-hosts b/scripts/func-down-hosts
index 5d556f0..8ee08a9 100755
--- a/scripts/func-down-hosts
+++ b/scripts/func-down-hosts
@@ -4,32 +4,33 @@
 
 import sys
 import func.overlord.client
-from optparse import OptionParser
+from func.overlord.scripts import base_func_parser, handle_base_func_options, errorprint
+from func.utils import is_error
 
-def parse_args(args):
-    parser = OptionParser(version = "1.0")
-    parser.add_option('--host', default=[], action='append',
-               help="hosts to act on, defaults to ALL")
-    parser.add_option('--timeout', default=10, type='int',
-               help='set the wait timeout for func commands')
-    parser.add_option('--forks', default=40, type='int',
-               help='set the number of forks to start up')
-    (opts, args) = parser.parse_args(args)
 
-    return opts, args, parser
+def main(args):
+    parser = base_func_parser(outputpath=False, timeoutdef=10)
+    opts, args, parser = parse_args(args)
+    opts = handle_base_func_options(parser, opts)
 
 
-opts, args, parser = parse_args(sys.argv[1:])
-hosts ='*'
-if opts.host:
-    hosts = ';'.join(opts.host)
+    hosts ='*'
+    if opts.host:
+        hosts = ';'.join(opts.host)
 
-fc = func.overlord.client.Client(hosts, timeout=opts.timeout, nforks=opts.forks)
+    fc = func.overlord.client.Client(hosts, timeout=opts.timeout, nforks=opts.forks)
+
+    results = fc.test.ping()
+    offline = []
+    for (hn, out) in results.items():
+        if out != 1:
+            offline.append(hn)
+
+    print '\n'.join(sorted(offline))
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
 
-results = fc.test.ping()
-offline = []
-for (hn, out) in results.items():
-    if out != 1:
-        offline.append(hn)
 
-print '\n'.join(sorted(offline))


_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


[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