summaryrefslogtreecommitdiffstats
path: root/overlord
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@dangerouslyinc.com>2007-09-29 16:31:04 -0300
committerJames Bowes <jbowes@redhat.com>2007-09-29 16:54:45 -0400
commitc010a077418aeb511cca251f7b2fe0375d00990d (patch)
tree85a9dc8cd84eb5140832805d0d94b13ffc2b9abb /overlord
parente153b175bff255b9af212f6d969cb75503ab2f14 (diff)
downloadthird_party-func-c010a077418aeb511cca251f7b2fe0375d00990d.tar.gz
third_party-func-c010a077418aeb511cca251f7b2fe0375d00990d.tar.xz
third_party-func-c010a077418aeb511cca251f7b2fe0375d00990d.zip
Fix indentation error in overlord/client.py.
Also normalized indentation to 4-spaces per level, and wrapped a few 80+ character lines.
Diffstat (limited to 'overlord')
-rwxr-xr-xoverlord/client.py288
1 files changed, 148 insertions, 140 deletions
diff --git a/overlord/client.py b/overlord/client.py
index e0a0801..d6ccdc8 100755
--- a/overlord/client.py
+++ b/overlord/client.py
@@ -35,128 +35,134 @@ FUNC_USAGE = "Usage: %s [ --help ] [ --verbose ] target.example.org module metho
# ===================================
class CommandAutomagic():
- """
- This allows a client object to act as if it were one machine, when in
- reality it represents many.
- """
-
- def __init__(self, clientref, base):
- self.base = base
- self.clientref = clientref
-
- def __getattr__(self,name):
- base2 = self.base[:]
- base2.append(name)
- return CommandAutomagic(self.clientref, base2)
-
- def __call__(self, *args):
- if not self.base:
- raise AttributeError("something wrong here")
- if len(self.base) < 2:
- raise AttributeError("no method called: %s" % ".".join(self.base))
- module = self.base[0]
- method = ".".join(self.base[1:])
- return self.clientref.run(module,method,args)
+ """
+ This allows a client object to act as if it were one machine, when in
+ reality it represents many.
+ """
+
+ def __init__(self, clientref, base):
+ self.base = base
+ self.clientref = clientref
+
+ def __getattr__(self,name):
+ base2 = self.base[:]
+ base2.append(name)
+ return CommandAutomagic(self.clientref, base2)
+
+ def __call__(self, *args):
+ if not self.base:
+ raise AttributeError("something wrong here")
+ if len(self.base) < 2:
+ raise AttributeError("no method called: %s" % ".".join(self.base))
+ module = self.base[0]
+ method = ".".join(self.base[1:])
+ return self.clientref.run(module,method,args)
# ===================================
class Client():
- def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False, verbose=False, noglobs=False):
- """
- 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
- """
- self.config = read_config(CONFIG_FILE, CMConfig)
- self.server_spec = server_spec
- self.port = port
- self.verbose = verbose
- self.interactive = interactive
- self.noglobs = noglobs
- self.servers = self.expand_servers(self.server_spec)
+ def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False,
+ verbose=False, noglobs=False):
+ """
+ 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
+ """
+ self.config = read_config(CONFIG_FILE, CMConfig)
+ self.server_spec = server_spec
+ self.port = port
+ self.verbose = verbose
+ self.interactive = interactive
+ self.noglobs = noglobs
+ self.servers = self.expand_servers(self.server_spec)
- # default cert/ca/key is the same as the certmaster ca - need to be able to change that on the cli
- self.key = '%s/funcmaster.key' % self.config.cadir
- self.cert = '%s/funcmaster.crt' % self.config.cadir
- self.ca = '%s/funcmaster.crt' % self.config.cadir # yes, they're the same, that's the point
+ # default cert/ca/key is the same as the certmaster ca - need to
+ # be able to change that on the cli
+ self.key = '%s/funcmaster.key' % self.config.cadir
+ self.cert = '%s/funcmaster.crt' % self.config.cadir
+ # yes, they're the same, that's the point
+ self.ca = '%s/funcmaster.crt' % self.config.cadir
- # -----------------------------------------------
+ # -----------------------------------------------
- def expand_servers(self,spec):
- """
- Given a regex/blob of servers, expand to a list
- of server ids.
- """
-
- if self.noglobs:
- return [ "https://%s:%s" % (spec, self.port) ]
-
- all_hosts = []
- all_certs = []
- seperate_gloobs = spec.split(";")
- for each_gloob in seperate_gloobs:
- actual_gloob = "%s/%s.cert" % (self.config.certroot, each_gloob)
- certs = glob.glob(actual_gloob)
- for cert in certs:
- all_certs.append(cert)
- host = cert.replace(self.config.certroot,"")[1:-5]
- all_hosts.append(host)
-
- all_urls = []
- for x in all_hosts:
- all_urls.append("https://%s:%s" % (x, self.port))
-
- if self.verbose and len(all_urls) == 0:
- sys.stderr.write("no hosts matched\n")
-
- return all_urls
-
- # -----------------------------------------------
-
- def __getattr__(self, name):
- """
- This getattr allows manipulation of the object as if it were
- a XMLRPC handle to a single machine, when in reality it is a handle
- to an unspecified number of machines.
-
- So, it enables stuff like this:
+ def expand_servers(self,spec):
+ """
+ Given a regex/blob of servers, expand to a list
+ of server ids.
+ """
+
+ if self.noglobs:
+ return [ "https://%s:%s" % (spec, self.port) ]
+
+ all_hosts = []
+ all_certs = []
+ seperate_gloobs = spec.split(";")
+ for each_gloob in seperate_gloobs:
+ actual_gloob = "%s/%s.cert" % (self.config.certroot, each_gloob)
+ certs = glob.glob(actual_gloob)
+ for cert in certs:
+ all_certs.append(cert)
+ host = cert.replace(self.config.certroot,"")[1:-5]
+ all_hosts.append(host)
+
+ all_urls = []
+ for x in all_hosts:
+ all_urls.append("https://%s:%s" % (x, self.port))
+
+ if self.verbose and len(all_urls) == 0:
+ sys.stderr.write("no hosts matched\n")
+
+ return all_urls
+
+ # -----------------------------------------------
+
+ def __getattr__(self, name):
+ """
+ This getattr allows manipulation of the object as if it were
+ a XMLRPC handle to a single machine, when in reality it is a handle
+ to an unspecified number of machines.
+
+ So, it enables stuff like this:
- Client("*.example.org").yum.install("foo")
+ Client("*.example.org").yum.install("foo")
- # WARNING: any missing values in Client's source will yield
- # strange errors with this engaged. Be aware of that.
- """
+ # WARNING: any missing values in Client's source will yield
+ # strange errors with this engaged. Be aware of that.
+ """
- return CommandAutomagic(self, [name])
+ return CommandAutomagic(self, [name])
- # -----------------------------------------------
+ # -----------------------------------------------
- def run(self, module, method, args):
- """
- Invoke a remote method on one or more servers.
- Run returns a hash, the keys are server names, the values are the returns.
- The returns may include exception objects.
- If Client() was constructed with noglobs=True, the return is instead just
- a single value, not a hash.
- """
+ def run(self, module, method, args):
+ """
+ Invoke a remote method on one or more servers.
+ Run returns a hash, the keys are server names, the values are the
+ returns.
+
+ The returns may include exception objects.
+ If Client() was constructed with noglobs=True, the return is instead
+ just a single value, not a hash.
+ """
- results = {}
+ results = {}
- for server in self.servers:
+ for server in self.servers:
- conn = sslclient.FuncServer(server, self.key, self.cert, self.ca )
- # conn = xmlrpclib.ServerProxy(server)
+ conn = sslclient.FuncServer(server, self.key, self.cert, self.ca )
+ # conn = xmlrpclib.ServerProxy(server)
- if self.interactive:
- sys.stderr.write("on %s running %s %s (%s)\n" % (server, module, method, ",".join(args)))
+ if self.interactive:
+ sys.stderr.write("on %s running %s %s (%s)\n" % (server,
+ module, method, ",".join(args)))
- # FIXME: support userland command subclassing only if a module
- # is present, otherwise run as follows. -- MPD
+ # FIXME: support userland command subclassing only if a module
+ # is present, otherwise run as follows. -- MPD
- try:
+ try:
# thats some pretty code right there aint it? -akl
# we can't call "call" on s, since thats a rpc, so
# we call gettatr around it.
@@ -164,49 +170,50 @@ class Client():
retval = getattr(conn, meth)(*args[:])
if self.interactive:
pprint.pprint(retval)
- except Exception, e:
+ except Exception, e:
retval = e
if self.interactive:
- sys.stderr.write("remote exception on %s: %s\n" % (server, str(e)))
+ sys.stderr.write("remote exception on %s: %s\n" %
+ (server, str(e)))
- if self.noglobs:
- return retval
- else:
- left = server.rfind("/")+1
- right = server.rfind(":")
- server_name = server[left:right]
- results[server_name] = retval
+ if self.noglobs:
+ return retval
+ else:
+ left = server.rfind("/")+1
+ right = server.rfind(":")
+ server_name = server[left:right]
+ results[server_name] = retval
- return results
+ return results
# -----------------------------------------------
- def cli_return(self,results):
- """
- As the return code list could return strings and exceptions
- and all sorts of crazy stuff, reduce it down to a simple
- integer return. It may not be useful but we need one.
- """
- numbers = []
- for x in results.keys():
- # faults are the most important
- if type(x) == Exception:
- return -911
- # then pay attention to numbers
- if type(x) == int:
- numbers.append(x)
-
- # if there were no numbers, assume 0
- if len(numbers) == 0:
- return 0
-
- # if there were numbers, return the highest
- # (presumably the worst error code
- max = -9999
- for x in numbers:
- if x > max:
- max = x
- return max
+ def cli_return(self,results):
+ """
+ As the return code list could return strings and exceptions
+ and all sorts of crazy stuff, reduce it down to a simple
+ integer return. It may not be useful but we need one.
+ """
+ numbers = []
+ for x in results.keys():
+ # faults are the most important
+ if type(x) == Exception:
+ return -911
+ # then pay attention to numbers
+ if type(x) == int:
+ numbers.append(x)
+
+ # if there were no numbers, assume 0
+ if len(numbers) == 0:
+ return 0
+
+ # if there were numbers, return the highest
+ # (presumably the worst error code
+ max = -9999
+ for x in numbers:
+ if x > max:
+ max = x
+ return max
# ===================================================================
@@ -288,7 +295,8 @@ class FuncCommandLine():
"""
Runs the actual command.
"""
- client = Client(self.server_spec,port=self.port,interactive=True,verbose=self.verbose)
+ client = Client(self.server_spec,port=self.port,interactive=True,
+ verbose=self.verbose)
results = client.run(self.module, self.method, self.method_args)
# TO DO: add multiplexer support