diff options
author | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-26 15:18:46 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-26 15:18:46 -0400 |
commit | c7a55aabe8d99ac6ddc8e4884d8b7a404b0ac291 (patch) | |
tree | 9eac3255071532f3abdfcdedd36527ff38e5db10 /overlord/client.py | |
parent | 411b3213fd42ea8c7cc13bda6923393a18130295 (diff) | |
download | third_party-func-c7a55aabe8d99ac6ddc8e4884d8b7a404b0ac291.tar.gz third_party-func-c7a55aabe8d99ac6ddc8e4884d8b7a404b0ac291.tar.xz third_party-func-c7a55aabe8d99ac6ddc8e4884d8b7a404b0ac291.zip |
Adding a noglobs=True/False parameter to the client. When set to True, the return codes assume
the server specification is NOT a glob and return a single value instead of a hash. This minimizes
code when needing to address only one system at a time. The command line will always assume globs are
possible and will not use this shortcut.
Diffstat (limited to 'overlord/client.py')
-rwxr-xr-x | overlord/client.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/overlord/client.py b/overlord/client.py index 87b665a..42285c2 100755 --- a/overlord/client.py +++ b/overlord/client.py @@ -61,17 +61,21 @@ class CommandAutomagic(): class Client(): - def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False): + def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False, noglobs=False): """ Constructor. - server_spec is something like "*.example.org" or "foosball" - everything else optional and mostly self explanatory. + @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 + @silent -- whether to print anything + @noglobs -- specifies server_spec is not a glob, and run should return single values """ self.server_spec = server_spec self.port = port self.verbose = verbose self.silent = silent + self.noglobs = noglobs self.servers = self.expand_servers(self.server_spec) # ----------------------------------------------- @@ -82,6 +86,9 @@ class Client(): of server ids. """ + if self.noglobs: + return [ "http://%s:%s" % (spec, self.port) ] + all_hosts = [] all_certs = [] seperate_gloobs = spec.split(";") @@ -112,23 +119,28 @@ class Client(): 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") - """ + # WARNING: any missing values in Client's source will yield + # strange errors with this engaged. Be aware of that. + """ + 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. """ - count = len(self.servers) results = {} for server in self.servers: @@ -156,7 +168,13 @@ class Client(): if not self.silent: sys.stderr.write("remote exception on %s: %s\n" % (server, str(e))) - results[server] = retval + if self.noglobs: + return retval + else: + left = server.rfind("/") + right = server.rfind(":") + server_name = server[left:right] + results[server_name] = retval return results |